/* Five in a Row — bright Baithak theme (unified with the /apps/games/ hub) */
:root {
  --bg0: #fff8e7;
  --bg1: #d9ecff;
  --table: #fffdf8;
  --table-dark: #eadfc8;
  --gold: #ffb020;
  --gold-light: #ffd166;
  --gold-deep: #c77e00;
  --chipblue: #2f6fd6;
  --cream: #3a2c1c;
  --cream-dim: #8a755c;
  --ink: #2a1a00;
  --red-suit: #d1342c;
  --chip-B: #2f7bff;
  --chip-G: #2fe05a;
  --chip-R: #f72323;
  --text: #3a2c1c;
  --text-dim: #8a755c;
  --danger: #d23c28;
  --radius: 18px;
  --display: 'Baloo 2', 'Noto Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* viewport lock: pages never scroll; game UI sits on the background */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--text);
  background: linear-gradient(165deg, #fff8e7 0%, #ffefd9 32%, #ffe3ec 64%, #d9ecff 100%);
  background-attachment: fixed;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
}
/* faint giant suits — the deck is always around */
body::before {
  content: "♠  ♥  ♦  ♣";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  font-size: 120px; line-height: 2.2; letter-spacing: 30px; text-align: center;
  color: rgba(140,100,40,.06); transform: rotate(-8deg) scale(1.3);
  white-space: pre-wrap; overflow: hidden;
}
#app, #topbar { position: relative; z-index: 1; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 2px solid #eadfc8;
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,253,248,.92); backdrop-filter: blur(6px);
  flex: 0 0 auto;
}
.brand { font-family: var(--display); font-size: 22px; font-weight: 800; letter-spacing: .5px; color: var(--text); }
.brand span { color: var(--gold-deep); }
.brand-main { color: var(--cream); font-style: italic; }
.brand-accent { color: var(--gold-deep); font-weight: 800; }
.lang-toggle { display: flex; border: 2px solid #eadfc8; border-radius: 999px; overflow: hidden; }
.lang-toggle button {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 8px 14px; font-size: 14px; cursor: pointer; min-height: 40px; font-weight: 700;
}
.lang-toggle button.active { background: var(--gold); color: var(--ink); font-weight: 800; }

/* ---------- layout ---------- */
#app {
  max-width: 560px; margin: 0 auto; padding: 16px 12px 96px;
  flex: 1 1 auto; min-height: 0; width: 100%;
  overflow-y: auto; overscroll-behavior: contain;
}
.screen.hidden, .hidden { display: none !important; }
.card {
  background: #fffdf8;
  border: 2px solid #eadfc8;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(120,80,20,.10);
}
.card h2, .hero-title {
  font-family: var(--display); color: #3a2c1c; margin: 0 0 10px; font-size: 22px; font-weight: 800;
}
.hero { text-align: center; overflow: hidden; }
.hero-title {
  font-size: 42px; font-weight: 800; line-height: 1.02; margin: 4px 0 8px;
  color: var(--text);
  text-shadow: 0 2px 0 rgba(255,255,255,.85);
}
.hero-title .five {
  background: linear-gradient(180deg, #ffd166, #f5a300);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--text); margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.story { color: var(--text-dim); font-style: italic; margin: 10px 0 0; font-size: 14px; line-height: 1.5; }

/* chip divider — a row of poker chips */
.chip-row {
  height: 20px; margin: 2px 8px 10px; border-radius: 999px;
  background-image:
    radial-gradient(circle, #2f7bff 5px, transparent 6.5px),
    radial-gradient(circle, #2fe05a 5px, transparent 6.5px),
    radial-gradient(circle, #f72323 5px, transparent 6.5px),
    radial-gradient(circle, #ffb020 5px, transparent 6.5px);
  background-size: 88px 20px, 88px 20px, 88px 20px, 88px 20px;
  background-position: 11px center, 33px center, 55px center, 77px center;
  background-repeat: repeat-x;
  filter: drop-shadow(0 2px 3px rgba(120,80,20,.3)); opacity: .95;
}

/* hero board — a real mini Sequence board with a winning run */
.hero-board {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px;
  margin: 14px auto 4px; max-width: 400px; padding: 10px; border-radius: 14px;
  background: linear-gradient(160deg, #fffefb, #f3eee1);
  border: 2px solid #eadfc8;
  box-shadow: 0 8px 24px rgba(120,80,20,.12), 0 0 26px rgba(255,176,32,.22);
}
.hcell {
  position: relative; aspect-ratio: 1; border-radius: 4px;
  background: #fffdf7; border: 1px solid #e3dcc9;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 700; color: #3a3a3e; line-height: 1;
}
.hcell.corner { background: #b02a38; color: #ffe9c9; font-size: 11px; }
.hcell.red { color: var(--red-suit); }
.hchip {
  position: absolute; width: 80%; height: 80%; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55); box-shadow: 0 1px 4px rgba(0,0,0,.55);
}
.hchip.W { background: radial-gradient(circle at 35% 30%, #ffc9ce, #b02a38); animation: winpulse 1.8s ease-in-out infinite; z-index: 2; }
.hchip.B { background: radial-gradient(circle at 35% 30%, #7fb0ff, var(--chip-B)); }
.hchip.G { background: radial-gradient(circle at 35% 30%, #8ff5a8, var(--chip-G)); }
.hchip.R { background: radial-gradient(circle at 35% 30%, #ff8a7a, var(--chip-R)); }
@keyframes winpulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 6px rgba(255,176,32,.5); }
  50% { transform: scale(1.14); box-shadow: 0 0 14px rgba(255,176,32,.95); }
}

/* ---------- forms & buttons ---------- */
.field-label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.text-input {
  width: 100%; padding: 12px 14px; font-size: 16px; border-radius: 12px;
  border: 2px solid #eadfc8; background: #fff; color: var(--text);
  min-height: 48px;
}
.text-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,176,32,.25); }
.text-input.mono { font-family: ui-monospace, monospace; font-size: 13px; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; font-size: 16px; font-weight: 800;
  cursor: pointer; min-height: 48px; font-family: var(--display);
}
.btn-gold {
  background: linear-gradient(180deg, var(--gold-light), var(--gold)); color: var(--ink);
  box-shadow: 0 4px 0 var(--gold-deep), 0 8px 20px rgba(255,176,32,.4);
}
.btn-gold:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-deep); }
.btn-ghost { background: #fff; color: #3a2c1c; border: 2px solid #eadfc8; box-shadow: 0 2px 6px rgba(120,80,20,.08); }
.btn-ghost:active { transform: translateY(2px); }
.btn-small { padding: 8px 16px; font-size: 14px; min-height: 44px; box-shadow: 0 3px 0 #e3d5b8; }
.btn-small.btn-gold { box-shadow: 0 3px 0 var(--gold-deep), 0 6px 14px rgba(255,176,32,.35); }
.btn-big { width: 100%; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.has-new { outline: 3px solid var(--gold-light); outline-offset: 2px; }
.form-error { color: var(--danger); font-size: 14px; margin: 8px 0 0; font-weight: 700; }
.hint { color: var(--text-dim); font-size: 14px; text-align: center; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.seg button {
  flex: 1 1 0; border: 2px solid #eadfc8; background: #fff;
  color: var(--text); border-radius: 12px; padding: 10px 6px; font-size: 15px; min-height: 48px; cursor: pointer;
  font-family: var(--display); font-weight: 700;
}
.seg button.active { background: var(--gold); color: var(--ink); font-weight: 800; border-color: var(--gold); box-shadow: 0 3px 0 var(--gold-deep); }

/* ---------- seats ---------- */
.seat-list { list-style: none; margin: 0; padding: 0; }
.seat-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 4px;
  border-bottom: 1px solid #f0e7d2; font-size: 16px;
}
.seat-list li:last-child { border-bottom: 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: #d8cbb2; flex: none; }
.dot.on { background: var(--chip-G); box-shadow: 0 0 8px var(--chip-G); }
.badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 800;
  border: 2px solid var(--gold); color: var(--gold-deep); border-radius: 999px; padding: 2px 8px;
}
.badge.you { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.badge.off { border-color: #c9bda3; color: var(--text-dim); }
.badge.bot { border-color: var(--chipblue); color: var(--chipblue); }
.seat-remove {
  margin-left: auto; background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 4px 8px; line-height: 1;
}
.seat-remove:hover { color: var(--danger); }
.chipdot { width: 18px; height: 18px; border-radius: 50%; flex: none; border: 2px solid rgba(255,255,255,.4); }
.chipdot.B { background: var(--chip-B); } .chipdot.G { background: var(--chip-G); } .chipdot.R { background: var(--chip-R); }

.share-block .link-row { display: flex; gap: 8px; }
.share-block .link-row .text-input { flex: 1; min-width: 0; }

/* ---------- game ---------- */
.turn-banner {
  text-align: center; font-family: var(--display); font-weight: 800; font-size: 20px;
  padding: 10px; margin-bottom: 10px; border-radius: 14px;
  background: #eef4ff; border: 2px solid #bcd2f5; color: #2f5ba8;
}
.turn-banner.mine {
  background: linear-gradient(100deg, rgba(255,176,32,.4), rgba(255,176,32,.16));
  border-color: var(--gold); color: #3a2c1c;
  box-shadow: 0 0 18px rgba(255,176,32,.4);
  animation: bannerpop .5s ease-out;
}
@keyframes bannerpop { from { transform: scale(.94); } }
.card-tight { padding: 10px 12px; margin-bottom: 10px; background: #fffdf8; border: 2px solid #eadfc8; border-radius: 14px; }
.scoreboard { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; font-size: 15px; font-weight: 700; }
.score-side { display: flex; align-items: center; gap: 6px; color: var(--cream-dim); }
.meta-row { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.meta-chip {
  font-size: 13px; color: var(--text-dim); border: 1px solid #d9cdae;
  border-radius: 999px; padding: 4px 12px; font-weight: 700;
}
.meta-chip.urgent { color: var(--danger); border-color: var(--danger); animation: pulse 1s infinite; }

/* board */
#board-wrap { display: flex; justify-content: center; margin-bottom: 12px; }
.board {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px;
  container-type: inline-size;
  width: 100%; max-width: 480px; padding: 10px; border-radius: 16px;
  background: linear-gradient(160deg, #fffefb, #f3eee1);
  border: 3px solid var(--gold);
  box-shadow: 0 14px 44px rgba(120,80,20,.16), 0 0 34px rgba(255,176,32,.28);
}
.cell {
  position: relative; aspect-ratio: 1; border-radius: 5px;
  background: #fffdf7;
  border: 1px solid #e3dcc9;
  display: flex; align-items: center; justify-content: center;
  cursor: default; user-select: none;
}
.cell .cardlabel { font-size: 10px; font-size: 3.2cqi; line-height: 1.05; text-align: center; color: #1d1d20; font-weight: 700; }
.cell .cardlabel .suit { display: block; font-size: 11px; font-size: 3.7cqi; }
.cell .cardlabel.red { color: var(--red-suit); }
.cell.corner { background: #b02a38; border-color: #8c1f2c; }
.cell.corner .cardlabel { color: #ffe9c9; font-size: 15px; font-size: 4.6cqi; }
.cell.occupied .cardlabel { opacity: .22; }
.cell .chip {
  position: absolute; width: 100%; height: 100%; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.65);
  box-shadow: 0 2px 6px rgba(0,0,0,.4), inset 0 0 0 1px rgba(0,0,0,.12);
}
.cell .chip.B { background: radial-gradient(circle at 35% 30%, rgba(127,176,255,.65), rgba(47,123,255,.65)); }
.cell .chip.G { background: radial-gradient(circle at 35% 30%, rgba(143,245,168,.65), rgba(47,224,90,.65)); }
.cell .chip.R { background: radial-gradient(circle at 35% 30%, rgba(255,138,122,.65), rgba(247,35,35,.65)); }
.cell .chip.locked { outline: 2px solid var(--gold); outline-offset: 1px; }
.cell.legal { cursor: pointer; }
.cell.legal::after {
  content: ""; position: absolute; inset: 12%; border-radius: 50%;
  border: 3px dashed var(--gold); animation: pulse 1.2s infinite;
}
.cell.legal-target::after { border-style: solid; border-color: var(--chip-R); }
@keyframes pulse { 50% { opacity: .45; } }

/* hand */
#hand-label { margin-top: 4px; }
.hand {
  display: flex; gap: 10px; overflow-x: auto; padding: 6px 2px 12px;
  -webkit-overflow-scrolling: touch;
}
.pcard {
  flex: none; width: 68px; height: 96px; border-radius: 12px;
  background: linear-gradient(165deg, #fffdf6, #efe6cf);
  color: #241c12; border: 3px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; cursor: pointer; position: relative;
  box-shadow: 0 4px 12px rgba(0,0,0,.45);
  font-family: var(--display);
}
.pcard .rank { font-size: 22px; line-height: 1; }
.pcard .suit { font-size: 24px; line-height: 1.1; }
.pcard.red { color: var(--red-suit); }
.pcard.selected { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,176,32,.6), 0 4px 12px rgba(0,0,0,.45); transform: translateY(-4px); }
.pcard.dead { opacity: .75; }
.pcard .swap-tag {
  position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: var(--ink); font-size: 10px; font-weight: 800;
  border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.pcard .jack-tag {
  position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 800; letter-spacing: .04em;
  border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.pcard .jack-tag.wild { background: var(--gold); color: var(--ink); }
.pcard .jack-tag.remove { background: #23232a; color: #ffd9d9; border: 1px solid var(--gold); }
.action-bar { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

/* leaderboard */
.board-list { display: flex; flex-direction: column; gap: 6px; }
.board-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 10px;
  background: #fff; border: 1px solid #eadfc8;
  font-size: 14px; color: #3a2c1c;
}
.board-row .rank {
  font-family: var(--display); font-weight: 800; color: var(--gold-deep);
  min-width: 22px; text-align: center;
}
.board-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .wins { font-weight: 800; color: #3a2c1c; }
.board-row .wins small { font-weight: 400; color: var(--cream-dim); margin-left: 4px; }
.board-empty { color: var(--cream-dim); font-size: 13px; }
.mini-board { margin: 12px 0 4px; }
.mini-board h3 { font-size: 15px; margin: 0 0 8px; color: var(--gold-deep); font-family: var(--display); }
.board-card h2 { margin-top: 0; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.board-head h2, .board-head h3 { margin: 0; }
.board-reset {
  background: none; border: 0; color: var(--text-dim); font-size: 13px;
  text-decoration: underline; cursor: pointer; padding: 4px 2px; font-family: inherit;
}
.board-reset:hover { color: var(--danger); }

/* ---------- tutorial ---------- */
#screen-tutorial { display: flex; flex-direction: column; gap: 10px; }
.tut-main { display: flex; justify-content: center; }
#tut-board-wrap { display: flex; justify-content: center; width: 100%; }
#tut-board { width: min(92vw, 420px, calc(100dvh - 400px)); }
.tut-side { display: flex; flex-direction: column; gap: 10px; }
.tut-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.tut-head h2 { margin: 0 0 6px; }
.tut-dots { display: flex; gap: 6px; }
.tut-dots span { width: 8px; height: 8px; border-radius: 50%; background: rgba(120,80,20,.18); }
.tut-dots span.on { background: var(--gold); }
.tut-bubble {
  background: #fffdf8; border: 1px solid #eadfc8;
  border-radius: 14px; padding: 12px 16px;
  font-size: 15px; line-height: 1.5; color: #3a2c1c;
  box-shadow: 0 4px 18px rgba(120,80,20,.10);
}
.tut-bubble.shake { animation: tutshake .35s; }
@keyframes tutshake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
.pcard.tut-glow { animation: tutpulse 1.2s infinite; border-color: var(--gold); }
@keyframes tutpulse { 50% { box-shadow: 0 0 0 4px rgba(212,175,55,.45); transform: translateY(-3px); } }
#tut-hand { flex-wrap: wrap; overflow-x: visible; row-gap: 10px; }
#tut-done { margin-top: 6px; justify-content: center; }
@media (min-width: 1024px) {
  #screen-tutorial {
    flex: 1; min-height: 0;
    display: grid; gap: 18px; align-items: stretch;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  }
  .tut-main { min-height: 0; min-width: 0; align-items: center; }
  .tut-side { min-height: 0; overflow-y: auto; justify-content: center; }
}

/* ---------- chat ---------- */
.chat-drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: #fffdf8; border-top: 3px solid var(--gold);
  border-radius: 20px 20px 0 0; max-height: 60vh; display: flex; flex-direction: column;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(120,80,20,.12);
}
.chat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chat-head strong { font-family: var(--display); color: #3a2c1c; font-size: 19px; font-weight: 800; }
.chat-messages { overflow-y: auto; flex: 1; min-height: 120px; margin-bottom: 10px; }
.chat-messages .msg { margin-bottom: 8px; font-size: 15px; color: #3a2c1c; }
.chat-messages .msg .who { color: var(--chipblue); font-weight: 700; margin-right: 6px; }
.chat-input-row { display: flex; gap: 8px; }

/* ---------- toasts / modal / conn ---------- */
#toasts { position: fixed; top: 64px; left: 12px; right: 12px; z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #fffdf8; border: 2px solid var(--gold); color: #3a2c1c;
  border-radius: 999px; padding: 10px 20px; font-size: 15px; font-weight: 700; max-width: 100%;
  box-shadow: 0 4px 16px rgba(120,80,20,.18); animation: toastin .25s ease-out;
}
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } }
.modal {
  position: fixed; inset: 0; z-index: 70; background: rgba(58,44,28,.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card { background: #fffdf8; border: 2px solid #eadfc8; border-radius: 20px; padding: 24px; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 12px 40px rgba(120,80,20,.18); }
.modal-card h3 { margin: 0 0 8px; font-size: 21px; font-family: var(--display); color: #3a2c1c; }
.modal-card h2 { margin: 0 0 8px; font-size: 24px; font-family: var(--display); color: #3a2c1c; }
.modal-card p { font-size: 15px; line-height: 1.5; margin: 0 0 20px; color: var(--cream-dim); }
.modal-btns { display: flex; gap: 10px; }
.modal-btns .btn { flex: 1; padding: 12px 8px; font-size: 15px; }
.btn-danger { background: linear-gradient(180deg, #e05260, #c23344); color: #fff; border: none; border-radius: 12px; font-weight: 800; cursor: pointer; box-shadow: 0 4px 14px rgba(210,60,75,.4); }
.btn-danger:active { transform: translateY(1px); }
.conn-bar {
  text-align: center; font-size: 14px; font-weight: 700; color: var(--gold-deep);
  background: rgba(255,176,32,.14); border: 2px solid rgba(255,176,32,.5);
  border-radius: 12px; padding: 8px; margin-bottom: 12px;
}

.over-card { text-align: center; }
.over-card h2 { font-size: 28px; }
.over-card .scoreboard { margin: 12px 0; }
.over-card .btn-row { justify-content: center; }

/* how-to steps as poker-chip numbers */
.howto ul { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.howto li {
  counter-increment: step;
  position: relative; margin-bottom: 10px; padding-left: 44px;
  font-size: 15px; line-height: 1.5; color: var(--cream-dim); min-height: 34px;
  display: flex; align-items: center;
}
.howto li::before {
  content: counter(step);
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffc9ce, var(--gold) 70%);
  border: 2px dashed #fff8;
  color: var(--ink); font-family: var(--display); font-weight: 800; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}

/* home: full-width stacked CTAs, cleanly aligned */
#screen-home .btn-row .btn { width: 100%; }
#rejoin-wrap { margin-top: 10px; }
#rejoin-wrap .btn { width: 100%; }
/* wrapper is layout-neutral on small screens; becomes a grid column on desktop */
.home-side { display: contents; }

/* ---------- game screen: no-scroll dashboard ---------- */
#room-game { display: block; }
/* tighter chrome so phones fit more on one screen */
#app { padding-bottom: 32px; }
.turn-banner { margin-bottom: 8px; }
.scorebar { margin-bottom: 8px !important; }
#board-wrap { margin-bottom: 8px; }

/* ---------- wide screens: app width for the home/game dashboards ---------- */
@media (min-width: 1024px) {
  #app { max-width: 1040px; }
}

/* ---------- wide screens: board + side panel, everything visible ---------- */
@media (min-width: 1024px) {
  #screen-room { height: 100%; }
  #room-game {
    display: flex; gap: 20px; align-items: stretch; justify-content: center;
    height: 100%; min-height: 500px;
  }
  .game-main { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
  #board-wrap { margin-bottom: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
  .board { width: auto; max-width: none; } /* exact size set by fitBoard() */
  .game-side {
    flex: 0 0 300px; max-height: none; overflow-y: auto; padding-right: 2px;
  }
  .game-side .hand { flex-wrap: wrap; overflow-x: visible; }
  .game-side .hand-label { margin-top: 0; }
  .game-side .action-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .game-side .action-bar .btn-small { min-height: 44px; }
  body.chat-open #app { max-width: 980px; }
}

/* ---------- small screens ---------- */
@media (max-width: 400px) {
  .pcard { width: 62px; height: 90px; }
  .hero-title { font-size: 34px; }
  .hcell { font-size: 7px; }
}

/* ---------- wide screens: chat becomes a right sidebar ---------- */
@media (min-width: 1024px) {
  body.chat-open { padding-right: 340px; }
  body.chat-open .chat-drawer {
    top: 0; bottom: 0; left: auto; right: 0; width: 340px;
    border-radius: 0; border-top: none; border-left: 3px solid var(--gold);
    max-height: none;
  }
  body.chat-open #toasts { right: 352px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .pcard.selected { transform: none; }
}

/* ---------- desktop: every screen fits one viewport, no page scroll ---------- */
@media (min-width: 1024px) {
  body { overflow: hidden; }
  #app {
    height: calc(100vh - 70px); height: calc(100dvh - 70px);
    padding: 14px 20px;
    display: flex; flex-direction: column;
  }
  .screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }

  /* HOME: hero | create+join, how-to as a slim bottom strip.
     Scrolls internally if the side column outgrows the viewport. */
  #screen-home {
    display: grid; gap: 14px; min-height: 0; overflow-y: auto;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "hero side" "howto howto";
  }
  #screen-home .hero {
    grid-area: hero; margin: 0; min-height: 0; overflow: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    grid-template-areas:
      "chips chips"
      "text board";
    column-gap: 20px; align-items: center; text-align: left;
    padding: 18px 24px;
  }
  #screen-home .chip-row { grid-area: chips; }
  #screen-home .hero-text { grid-area: text; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
  #screen-home .hero-title { margin: 0; font-size: 30px; white-space: nowrap; }
  #screen-home .tagline { margin: 0; font-size: 15px; }
  #screen-home .story { margin: 0; font-size: 13px; }
  #screen-home .hero-board { grid-area: board; max-width: 260px; width: 100%; margin: 0; }
  .home-side {
    grid-area: side; display: flex; flex-direction: column;
    gap: 14px; min-height: 0; overflow-y: auto;
  }
  .home-side > :first-child { margin-top: auto; }
  .home-side > :last-child { margin-bottom: auto; }
  .home-side .card { margin: 0; flex: none; }
  #screen-home .howto { grid-area: howto; margin: 0; padding: 12px 18px; }
  #screen-home .howto h2 { font-size: 17px; margin: 0 0 8px; }
  #screen-home .howto ul { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  #screen-home .howto li { margin: 0; min-height: 0; font-size: 13px; padding-left: 40px; }
  #screen-home .howto li::before { width: 28px; height: 28px; font-size: 14px; }

  /* LOBBY: the three cards sit side by side */
  #room-lobby {
    flex: 1; min-height: 0; display: flex; gap: 14px;
    align-items: stretch; flex-wrap: wrap; align-content: center;
  }
  #room-lobby .card { flex: 1 1 0; margin: 0; min-width: 0; overflow: auto; }
  #lobby-wait { flex: 1 1 100%; margin: 0; }
  #join-gate { margin: auto; width: min(480px, 100%); }

  /* GAME: board + side already a row — just remove page scroll and cap the board */
  #room-game { flex: 1; min-height: 0; }
  .game-side { max-height: none; overflow: visible; }
  .board { width: min(100%, 600px, calc(100vh - 210px), calc(100dvh - 210px)); }

  /* GAME OVER: single card, centered */
  #room-over { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
  #room-over .card { margin: 0; width: min(520px, 100%); }
}
