/*
 * King Teen Patti — application styles.
 *
 * Colour, shape and elevation all come from the Material 3 tokens in
 * theme.css, so the light/dark toggle is one attribute on <html> and nothing
 * here needs a second set of rules.
 */

:root {
  /* Legacy aliases, mapped onto the M3 roles so older rules keep working. */
  --bg: var(--md-surface);
  --felt: var(--md-primary-container);
  --felt-2: var(--md-surface-2);
  --gold: var(--md-secondary);
  --ink: var(--md-on-surface);
  --muted: var(--md-on-surface-variant);
  --danger: var(--md-error);
  --ok: var(--md-primary);
  --panel: var(--md-surface-1);
  --radius: var(--md-shape-l);
}

* { box-sizing: border-box; }

/* An author `display` beats the user-agent [hidden] rule, so panels that set
   display: flex would stay visible when hidden. Make [hidden] win. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--md-surface);
  color: var(--md-on-surface);
  font: 15px/1.45 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--md-motion-medium) var(--md-easing),
              color var(--md-motion-medium) var(--md-easing);
}

/*
 * One frame for the whole app.
 *
 * Every screen occupies the same box, so signing in does not make the window
 * jump taller. On a short screen (a phone in landscape) the frame simply uses
 * whatever height there is.
 */
:root { --app-height: min(520px, 100dvh); --app-width: 880px; }

.screen {
  width: 100%;
  max-width: var(--app-width);
  /* A flex item will not shrink below its content unless told to, and the
     lobby's rail is very wide — without this the frame stretches to fit it. */
  min-width: 0;
  margin: 0 auto;
  padding: 16px;
}

/* The sign-in screen uses the same frame as the rest, with its card centred. */
#login {
  display: flex;
  align-items: center;
  height: var(--app-height);
  overflow: hidden;
}
#login .panel {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
}

h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -0.5px; }
h1 span { color: var(--gold); }
h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 20px 0 8px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 14px; }
.error { color: var(--danger); font-size: 14px; margin-top: 12px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

.fieldlabel { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

.row { display: flex; gap: 8px; align-items: center; }
.row input { text-transform: uppercase; }
.row .btn { width: auto; margin: 0; white-space: nowrap; }

.who { display: flex; align-items: center; gap: 8px; }
.tablemeta { font-size: 13px; color: var(--muted); }
.tablemeta strong { color: var(--gold); letter-spacing: 0.1em; }

.potbox { text-align: center; margin-bottom: 14px; }
.potlabel { font-size: 11px; letter-spacing: 0.2em; color: rgba(255,255,255,0.5); }
.potvalue { font-size: 30px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.stake { font-size: 12px; color: rgba(255,255,255,0.55); }

/*
 * Players sit in a ring around the table rather than in a row.
 *
 * The five places are fixed points on an ellipse, computed once and written out
 * as classes: seat 0 at the bottom, then clockwise. Absolute positioning keeps
 * the arrangement stable no matter how many seats are occupied, so a player
 * does not appear to move when someone else leaves.
 */
.seats {
  position: relative;
  flex: 1 1 auto;
  /* The ring needs real room; without a floor the seats spill off the felt. */
  min-height: 168px;
  width: 100%;
  margin: 0 auto;
  max-width: 640px;
}

.seats .seat {
  position: absolute;
  width: 116px;
  transform: translate(-50%, -50%);
}

/*
 * Three bands — top, middle, bottom — rather than a true circle. A seat is
 * centred on its point, so the bands are inset far enough that no seat box
 * hangs off the felt on a short screen.
 */
.seat--0 { left: 50%; top: 80%; }
.seat--1 { left: 13%; top: 52%; }
.seat--2 { left: 28%; top: 24%; }
.seat--3 { left: 72%; top: 24%; }
.seat--4 { left: 87%; top: 52%; }

/* The felt's centre, where the pot sits inside the ring. */
.tablecentre {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.seat.empty { opacity: 0.32; }
.seat.packed { opacity: 0.4; }
.seat.offline { border-style: dashed; }
.seat .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .ch { color: var(--gold); font-variant-numeric: tabular-nums; }
/* Blind table: the stack was never sent, so it is shown as withheld. */
.seat .ch.hidden { color: var(--muted); letter-spacing: 2px; }
.seat .st { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.seat .dealer { font-size: 10px; background: #fff; color: #000; border-radius: 99px; padding: 0 5px; font-weight: 800; }
.seat .mini { display: flex; gap: 2px; justify-content: center; margin-top: 4px; }
.seat .mini i { width: 13px; height: 19px; border-radius: 2px; background: linear-gradient(135deg, #8e2f2f, #571818); display: block; }

.status { text-align: center; margin-top: 14px; min-height: 22px; color: var(--gold); font-weight: 600; }

/* Own hand */
.myhand { padding: 18px 4px 8px; }
.handwrap { position: relative; }
.cards { display: flex; gap: 10px; justify-content: center; min-height: 96px; }

/* "See Cards" overlays the face-down hand rather than sitting in the action row. */
.seeoverlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 13px 26px;
  border: 2px solid var(--gold);
  border-radius: 12px;
  background: rgba(232, 196, 106, 0.94);
  color: #1c1403;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
}
.seeoverlay:hover { background: var(--gold); }
.seeoverlay:active { transform: translate(-50%, -50%) scale(0.97); }

.card {
  width: 66px; height: 94px;
  border-radius: 9px;
  background: #fff;
  color: #111;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-weight: 800;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}
.card.red { color: #c62828; }
.card .r { font-size: 26px; line-height: 1; }
.card .s { font-size: 20px; line-height: 1.1; }
.card.back { background: repeating-linear-gradient(45deg, #8e2f2f 0 7px, #6f2222 7px 14px); }

.timerbar { height: 5px; background: rgba(255,255,255,0.1); border-radius: 99px; margin: 14px 0 12px; overflow: hidden; }
#timerFill { height: 100%; width: 0; background: var(--gold); transition: width 0.1s linear; }
#timerFill.low { background: var(--danger); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.actions .btn { width: auto; flex: 1 1 92px; margin: 0; }

/* Bet control: [ Chaal 400 ][ − ][ + ] — Chaal sits on the left and is the
   only thing that places a bet; the steppers beside it only pick the amount. */
.actions .btn.bet {
  flex: 2 1 150px;
  flex-direction: column;
  gap: 1px;
  padding: 8px 12px;
  line-height: 1.15;
}
.actions .btn.bet .lbl { font-size: 11px; letter-spacing: 0.1em; opacity: 0.8; }
.actions .btn.bet .amt { font-size: 18px; font-variant-numeric: tabular-nums; }
.actions .btn.tonal { background: var(--md-tertiary-container); color: var(--md-on-tertiary-container); }


.log {
  margin-top: 16px; padding: 10px 12px;
  background: rgba(0,0,0,0.28); border-radius: 10px;
  font-size: 12.5px; color: var(--muted);
  max-height: 132px; overflow-y: auto;
}
.log div { padding: 1px 0; }
.log .hl { color: var(--gold); }

/* Room chat */
.chatfab {
  position: fixed;
  right: 18px; bottom: 18px;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.16);
  background: var(--panel);
  color: var(--ink);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  z-index: 20;
}
.chatfab .badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 21px; height: 21px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 12px; font-weight: 800;
  line-height: 21px;
  padding: 0 5px;
}

.chatpanel {
  position: fixed;
  right: 12px; bottom: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  box-shadow: 0 12px 34px rgba(0,0,0,0.55);
  z-index: 21;
  overflow: hidden;
}
.chatpanel header {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
}
.chatpanel header .meta { color: var(--muted); font-size: 11.5px; flex: 1; }

.chatmessages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 140px;
}
.chatmessages .msg { font-size: 14px; line-height: 1.35; word-break: break-word; }
.chatmessages .msg .author { color: var(--gold); font-weight: 700; margin-right: 5px; }
.chatmessages .msg.mine .author { color: var(--ok); }
.chatmessages .msg.system { color: var(--muted); font-style: italic; font-size: 12.5px; }
.chatmessages .empty { color: var(--muted); font-size: 13px; text-align: center; margin: auto 0; }

.chatform { display: flex; gap: 7px; padding: 10px; border-top: 1px solid rgba(255,255,255,0.09); }
.chatform input { flex: 1; padding: 9px 11px; font-size: 14px; }
.chatform .btn { width: auto; margin: 0; }
.chatpanel .error { margin: 0 12px 10px; }

/* ---- Rewards, avatars and stats (lobby) ---- */
.ok { color: var(--ok); font-size: 14px; margin-top: 10px; }

.reward {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  background: var(--md-surface-3); margin-bottom: 8px;
}
.reward strong { display: block; font-size: 14.5px; }
.reward .meta { color: var(--muted); font-size: 12.5px; }
.reward .btn { flex: 0 0 auto; }
.reward.ready { border: 1px solid var(--gold); background: rgba(232,196,106,0.10); }

.avatar { border-radius: var(--md-shape-m); background: var(--md-surface-3); object-fit: cover; }
.avatar.lg { width: 72px; height: 72px; }
.avatarrow { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatarrow .meta { color: var(--muted); font-size: 13px; }

.avatargrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 8px; margin-bottom: 12px;
}
.avatargrid button {
  padding: 0; border: 2px solid transparent; border-radius: 12px;
  background: none; cursor: pointer; line-height: 0;
}
.avatargrid button.on { border-color: var(--gold); }
.avatargrid img { width: 100%; aspect-ratio: 1; border-radius: 10px; display: block; }
.avatargrid button:disabled { opacity: 0.4; cursor: not-allowed; }

.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.statgrid div {
  background: var(--md-surface-3); border-radius: var(--md-shape-m); padding: 10px; text-align: center;
}
.statgrid .v { font-size: 19px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.statgrid .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Showdown (requirement 14) ---- */
.showdown {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 10px;
  border-radius: var(--md-shape-xl);
  overflow: hidden;
  z-index: 5;
}
.showdownhands { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.showdownhand { text-align: center; }
.showdownhand .who { font-size: 13px; font-weight: 700; margin-bottom: 5px; color: var(--ink); }
.showdownhand.winner .who { color: var(--ok); }
.showdownhand .cards { display: flex; gap: 4px; min-height: 0; }
#table .showdownhand .card { width: 40px; height: 57px; box-shadow: none; }
#table .showdownhand .card .r { font-size: 17px; }
#table .showdownhand .card .s { font-size: 13px; }
.showdownhand .rank { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.showdownresult {
  font-size: 19px; font-weight: 800; color: var(--gold); text-align: center; line-height: 1.35;
}
.showdownresult .amt { display: block; font-size: 25px; }

/* The seat avatar. */
.seat .pic { width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 3px; display: block; }

/* ============================ Material 3 components ====================== */

/* Cards (M3 filled card): the panels the app is built from. */
.panel {
  background: var(--md-surface-2);
  border: none;
  border-radius: var(--md-shape-l);
  box-shadow: var(--md-elev-1);
  padding: 20px;
  margin-bottom: 14px;
}

/* Buttons. The base is an M3 filled-tonal button; `.primary` is filled. */
.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 22px;
  margin-bottom: 9px;
  border: none;
  border-radius: var(--md-shape-full);
  background: var(--md-surface-variant);
  color: var(--md-on-surface-variant);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  overflow: hidden;
  transition: box-shadow var(--md-motion-short) var(--md-easing),
              background-color var(--md-motion-short) var(--md-easing);
}

/* The M3 state layer: a tinted overlay rather than a colour swap. */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-motion-short) var(--md-easing);
  pointer-events: none;
}
.btn:hover:not(:disabled)::after { opacity: var(--md-state-hover); }
.btn:focus-visible::after { opacity: var(--md-state-focus); }
.btn:active:not(:disabled)::after { opacity: var(--md-state-press); }
.btn:focus-visible { outline: 3px solid var(--md-primary); outline-offset: 2px; }

.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn:disabled::after { opacity: 0; }

.btn.primary {
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-elev-1);
}
.btn.primary:hover:not(:disabled) { box-shadow: var(--md-elev-2); }

.btn.danger { background: var(--md-error-container); color: var(--md-on-error-container); }

/* M3 text button. */
.btn.ghost {
  background: transparent;
  color: var(--md-primary);
  box-shadow: none;
}

.btn.small { width: auto; padding: 9px 16px; font-size: 13px; margin: 0; }

/* Icons sit inline with button labels. */
.icon { font-size: 17px; line-height: 1; }

/* Text fields (M3 filled). */
input, select {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--md-outline);
  border-radius: var(--md-shape-xs) var(--md-shape-xs) 0 0;
  background: var(--md-surface-3);
  color: var(--md-on-surface);
  font-family: inherit;
  font-size: 15px;
  transition: border-color var(--md-motion-short) var(--md-easing);
}
input:focus, select:focus {
  outline: none;
  border-bottom: 2px solid var(--md-primary);
  padding-bottom: 13px;
}

/* Segmented button (M3). */
.segmented {
  display: flex;
  gap: 0;
  margin-bottom: 4px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-full);
  overflow: hidden;
}
.segmented button {
  flex: 1;
  padding: 11px 10px;
  border: none;
  border-right: 1px solid var(--md-outline);
  border-radius: 0;
  background: transparent;
  color: var(--md-on-surface-variant);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.25;
  transition: background-color var(--md-motion-short) var(--md-easing);
}
.segmented button:last-child { border-right: none; }
.segmented button small { display: block; font-size: 10.5px; font-weight: 400; opacity: 0.8; margin-top: 2px; }
.segmented button:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.segmented button.on {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

/* Chips / assist chip. */
.tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  padding: 3px 10px;
  border-radius: var(--md-shape-s);
}
.chips { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--md-secondary); }

/* Top app bar. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px 16px;
}

/* Theme toggle (M3 icon button). */
.iconbtn {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--md-shape-full);
  background: transparent;
  color: var(--md-on-surface-variant);
  font-size: 21px;
  cursor: pointer;
  overflow: hidden;
  transition: background-color var(--md-motion-short) var(--md-easing);
}
.iconbtn:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.iconbtn:focus-visible { outline: 3px solid var(--md-primary); outline-offset: 2px; }

/*
 * The table screen fills the viewport and never scrolls: the felt takes what is
 * left after the header and the controls, and the ring of players sizes itself
 * to the felt.
 */
#table {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  overflow: hidden;
}
#table .topbar { flex: 0 0 auto; }
#table .myhand { flex: 0 0 auto; }

.felt {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--md-primary-container);
  border: none;
  border-radius: var(--md-shape-xl);
  box-shadow: var(--md-elev-2);
  padding: 14px 16px 8px;
}
.potvalue { color: var(--md-on-primary-container); }
.potlabel, .stake { color: color-mix(in srgb, var(--md-on-primary-container) 75%, transparent); }

.seat {
  background: var(--md-surface-2);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-m);
  padding: 9px;
  text-align: center;
  font-size: 13px;
  transition: border-color var(--md-motion-short) var(--md-easing),
              box-shadow var(--md-motion-short) var(--md-easing);
}
/*
 * Whose turn it is, at a glance: the seat pulses until they act. The animation
 * is disabled for anyone who has asked for reduced motion, who gets a steady
 * ring instead.
 */
.seat.turn {
  border-color: var(--md-secondary);
  animation: seat-turn 1.1s ease-in-out infinite;
  z-index: 2;
}

@keyframes seat-turn {
  0%, 100% {
    box-shadow: 0 0 0 2px var(--md-secondary);
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--md-secondary) 45%, transparent);
    transform: translate(-50%, -50%) scale(1.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .seat.turn { animation: none; box-shadow: 0 0 0 3px var(--md-secondary); }
}
.seat.won { border-color: var(--md-primary); box-shadow: 0 0 0 2px var(--md-primary); }
.seat .nm { color: var(--md-on-surface); }
.seat .ch { color: var(--md-secondary); }
.seat .st { color: var(--md-on-surface-variant); }

.status { color: var(--md-secondary); }

/* Chat surfaces. */
.chatpanel { background: var(--md-surface-3); border: none; box-shadow: var(--md-elev-3); }
.chatfab {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border: none;
  box-shadow: var(--md-elev-3);
}
.chatmessages .msg .author { color: var(--md-secondary); }
.chatmessages .msg.mine .author { color: var(--md-primary); }

.log { background: var(--md-surface-1); color: var(--md-on-surface-variant); border-radius: var(--md-shape-m); }
.log .hl { color: var(--md-secondary); }

.statgrid div { background: var(--md-surface-3); border-radius: var(--md-shape-m); }
.statgrid .v { color: var(--md-secondary); }
.statgrid .k { color: var(--md-on-surface-variant); }

.reward { background: var(--md-surface-3); border-radius: var(--md-shape-m); }
.reward.ready { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.reward.ready .meta { color: var(--md-on-secondary-container); opacity: 0.85; }

.showdown { background: var(--md-scrim); border-radius: var(--md-shape-xl); }
.showdownresult { color: var(--md-secondary); }

.seeoverlay {
  background: var(--md-secondary);
  color: var(--md-on-secondary);
  border: none;
  border-radius: var(--md-shape-full);
  box-shadow: var(--md-elev-3);
  font-family: inherit;
}

.error { color: var(--md-error); }
.ok { color: var(--md-primary); }

/* The − and + beside the Chaal button: round M3 icon buttons. */
.stepper { display: flex; gap: 6px; flex: 0 0 auto; }
.stepper .btn.step {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  margin: 0;
  padding: 0;
  font-size: 22px;
  font-weight: 800;
  background: var(--md-surface-variant);
  color: var(--md-on-surface-variant);
  border-radius: var(--md-shape-full);
}
.stepper .btn.step:disabled { opacity: 0.38; }

/* ================================ landscape ============================== */

/*
 * Requirement 23: the game is played in landscape on phones. The table screen
 * lays the felt and the controls side by side so nothing needs scrolling, and
 * a portrait phone is asked to turn.
 */
@media (orientation: landscape) and (max-height: 560px) {
  .screen { max-width: none; padding: 8px 12px; }

  #table .felt { min-height: 0; padding: 12px; }
  #table .potvalue { font-size: 22px; }
  /* Everything on the table screen tightens up so a phone in landscape fits
     the ring, the hand and the controls without scrolling. */
  #table .felt { padding: 8px 10px 4px; }
  #table .seats { max-width: 560px; min-height: 172px; }
  #table .seats .seat { width: 86px; padding: 3px; font-size: 9.5px; line-height: 1.25; }
  #table .seats .seat .st { font-size: 9px; }
  #table .seats .seat .mini { margin-top: 2px; }
  #table .seats .seat .mini i { width: 9px; height: 13px; }
  #table .seats .seat .pic { width: 20px; height: 20px; }
  #table .potvalue { font-size: 20px; }
  #table .potlabel, #table .stake { font-size: 10px; }

  #table .myhand { padding: 4px 0 2px; }
  #table .card { width: 44px; height: 62px; }
  #table .card .r { font-size: 17px; }
  #table .card .s { font-size: 13px; }
  #table .cards { min-height: 62px; gap: 5px; }
  #table .timerbar { margin: 6px 0 6px; }
  #table .actions .btn { padding: 8px 14px; font-size: 13px; }
  #table .actions .btn.bet .amt { font-size: 16px; }
  #table .stepper .btn.step { width: 40px; height: 40px; flex: 0 0 40px; font-size: 19px; }
  #table .seeoverlay { padding: 9px 18px; font-size: 14px; }
  #table .showdownhand .card { width: 32px; height: 46px; }
  #table .showdownhand .card .r { font-size: 14px; }
  #table .showdownhand .card .s { font-size: 11px; }
  #table .showdownhand .who { font-size: 11px; }
  #table .showdownhand .rank { font-size: 10px; }
  #table .showdownresult { font-size: 14px; }
  #table .showdownresult .amt { font-size: 19px; }
  #table .showdownhands { gap: 10px; }
  #table .card { width: 48px; height: 68px; }
  #table .card .r { font-size: 19px; }
  #table .card .s { font-size: 15px; }
  #table .cards { min-height: 70px; gap: 6px; }
  #table .myhand { padding: 8px 0 4px; }
  #table .log { max-height: 62px; }
  .topbar { padding: 4px 2px 8px; }
}

/* A phone held upright is asked to rotate rather than shown a cramped table. */
#rotateHint {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
  background: var(--md-surface);
  color: var(--md-on-surface);
}
#rotateHint .glyph { font-size: 56px; animation: tilt 1.8s ease-in-out infinite; }
#rotateHint p { margin: 0; color: var(--md-on-surface-variant); }

@keyframes tilt {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (max-width: 820px) and (pointer: coarse) {
  body.at-table #rotateHint { display: flex; }
}

/* =========================== horizontal card rail ======================== */

/*
 * The lobby is a rail of cards rather than a tall column: the screen fills the
 * viewport, the rail takes whatever height is left, and only the rail scrolls —
 * sideways. A phone therefore never scrolls down in the lobby.
 */
#lobby {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  overflow: hidden;
  padding-bottom: 8px;
}
#lobby .topbar { flex: 0 0 auto; }
#lobby .error { flex: 0 0 auto; margin: 0 4px; }

.hscroll {
  flex: 1 1 auto;
  /* Without this a flex child refuses to shrink below its content. */
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
}

.hscroll > * {
  scroll-snap-align: start;
  flex: 0 0 auto;
  height: 100%;
}

.panel.railcard {
  width: min(290px, 80vw);
  height: 100%;
  margin-bottom: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* A card that genuinely cannot fit scrolls inside itself rather than
     pushing the page taller. */
  overflow-y: auto;
}
.panel.railcard h2 { margin: 0; font-size: 17px; flex: 0 0 auto; }
.panel.railcard .meta { color: var(--md-on-surface-variant); font-size: 12.5px; margin: 0; }
.panel.railcard .btn { margin-bottom: 0; flex: 0 0 auto; }

/* The tables on offer, all on one row of the rail. */
.cardgroup { display: flex; gap: 12px; height: 100%; }

/*
 * One table on offer. The whole card is the button — a bigger touch target
 * than a link inside it, which matters on a phone.
 */
.tablecard {
  width: min(168px, 46vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-l);
  background: var(--md-surface-2);
  color: var(--md-on-surface);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--md-elev-1);
  transition: box-shadow var(--md-motion-short) var(--md-easing),
              background-color var(--md-motion-short) var(--md-easing);
}
.tablecard:hover { box-shadow: var(--md-elev-2); background: var(--md-surface-3); }
.tablecard:focus-visible { outline: 3px solid var(--md-primary); outline-offset: 2px; }

.tablecard .cat {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-on-secondary-container);
  background: var(--md-secondary-container);
  padding: 3px 9px;
  border-radius: var(--md-shape-s);
}
.tablecard .amount {
  font-size: 26px;
  font-weight: 800;
  color: var(--md-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.tablecard .desc { font-size: 11.5px; color: var(--md-on-surface-variant); line-height: 1.3; }
/* Pushed to the bottom so every card reads the same way. */
.tablecard .cta { font-size: 11.5px; color: var(--md-primary); margin-top: auto; font-weight: 600; }

/* Blind tables get the tertiary accent so the two kinds read apart at a glance. */
.tablecard.blind .cat {
  background: var(--md-tertiary-container);
  color: var(--md-on-tertiary-container);
}

/* Compact enough that the picture card fits without scrolling. */
.panel.railcard .avatargrid { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 0; }
.panel.railcard .avatarrow { margin-bottom: 0; }
.panel.railcard .avatar.lg { width: 52px; height: 52px; }
.panel.railcard .statgrid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
.panel.railcard .statgrid .v { font-size: 16px; }

@media (orientation: landscape) and (max-height: 560px) {
  .panel.railcard { width: min(250px, 44vw); padding: 12px; gap: 8px; }
  .panel.railcard h2 { font-size: 15px; }
  .tablecard { width: min(140px, 30vw); padding: 10px; }
  .tablecard .amount { font-size: 21px; }
  #lobby .topbar { padding: 4px 2px 6px; }

  #login .panel { padding: 14px 16px; }
  #login h1 { font-size: 22px; }
  #login .sub { margin-bottom: 10px; font-size: 13px; }
  #login .field { margin-bottom: 8px; }
  #login .btn { padding: 9px 18px; margin-bottom: 6px; font-size: 13.5px; }
  #login .hint { margin-top: 8px; font-size: 11.5px; }
}

/* ===================== corner rewards (requirements 26, 27) ============== */

/*
 * The two rewards sit in opposite corners so they are always reachable without
 * hunting through the lobby: the 4-hour bonus top-left beside the theme
 * switch, the milestone bottom-right.
 */
.cornerreward {
  position: fixed;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px 8px 10px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-full);
  background: var(--md-surface-3);
  color: var(--md-on-surface);
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--md-elev-2);
  transition: box-shadow var(--md-motion-short) var(--md-easing),
              background-color var(--md-motion-short) var(--md-easing),
              transform var(--md-motion-short) var(--md-easing);
}
.cornerreward.top-left { top: 12px; left: 12px; }
.cornerreward.bottom-right { bottom: 12px; right: 12px; }

/* The top-left reward floats over the lobby header, so the header steps aside
   rather than being covered by it. */
body.at-lobby #lobby .topbar { padding-left: 168px; }

.cornerreward .icon { font-size: 19px; line-height: 1; }
.cornerreward .body { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.cornerreward .label {
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
}
.cornerreward .value { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Ready to collect: the button lights up and lifts. */
.cornerreward.ready {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-color: var(--md-secondary);
  box-shadow: var(--md-elev-3);
  animation: reward-ready 1.6s ease-in-out infinite;
}
.cornerreward.ready .label { color: var(--md-on-secondary-container); opacity: 0.8; }
.cornerreward:not(.ready) { cursor: default; }

@keyframes reward-ready {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Confirmation of a collected reward, shown briefly under the top bar. */
.rewardtoast {
  position: fixed;
  z-index: 45;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 18px;
  border-radius: var(--md-shape-full);
  background: var(--md-inverse-surface);
  color: var(--md-inverse-on-surface);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--md-elev-3);
}

/* ======================= dialog (requirement 25) ========================= */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--md-scrim);
}

.dialog {
  width: min(360px, 92vw);
  padding: 22px;
  border-radius: var(--md-shape-xl);
  background: var(--md-surface-3);
  color: var(--md-on-surface);
  box-shadow: var(--md-elev-3);
}
.dialog h2 { margin: 0 0 10px; font-size: 19px; }
.dialog p { margin: 0 0 20px; color: var(--md-on-surface-variant); font-size: 14px; }
.dialogactions { display: flex; gap: 8px; justify-content: flex-end; }
.dialogactions .btn { width: auto; margin: 0; padding: 10px 20px; }

/* ================= square table cards (requirement 28) =================== */

/*
 * Boot tables are square, with a sheen that travels top-left to bottom-right
 * on a loop. The sweep is a pseudo-element behind the content so it never
 * interferes with the text or the tap target.
 */
.tablecard {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  width: auto;
  height: 100%;
  max-height: min(230px, 100%);
  justify-content: space-between;
}

.tablecard::before {
  content: '';
  position: absolute;
  /* Oversized so the band is still off-screen at both ends of its travel. */
  inset: -60%;
  background: linear-gradient(
    135deg,
    transparent 42%,
    color-mix(in srgb, var(--md-primary) 26%, transparent) 50%,
    transparent 58%
  );
  transform: translate3d(-55%, -55%, 0);
  animation: card-sheen 3.6s var(--md-easing) infinite;
  pointer-events: none;
}

/* The content sits above the sweep. */
.tablecard > * { position: relative; z-index: 1; }

@keyframes card-sheen {
  0%   { transform: translate3d(-55%, -55%, 0); }
  /* A pause at the end so the sweep reads as a highlight, not a strobe. */
  60%  { transform: translate3d(55%, 55%, 0); }
  100% { transform: translate3d(55%, 55%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .tablecard::before { animation: none; opacity: 0.35; }
  .cornerreward.ready { animation: none; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .cornerreward { padding: 6px 12px 6px 9px; gap: 7px; }
  .cornerreward .icon { font-size: 16px; }
  .cornerreward .value { font-size: 12px; }
  .tablecard { max-height: min(180px, 100%); }
}
