:root {
  --felt: #0f6e4f;
  --felt-dark: #0a5740;
  --tile-face: #fbf7ee;
  --tile-edge: #cdc1a4;
  --tile-side: #d6c8a4;
  --tile-side-dark: #b6a77f;
  --wood: #5b3d23;
  --tile-back: #1d6fb8;
  --tile-back2: #155a96;
  /* tile-face palette (themeable) — Jade defaults match the original look */
  --tf-green: #1f7a37; --tf-red: #c01722; --tf-blue: #15539e; --tf-ink: #1c1c1c;
  --tf-gold: #b8860b; --tf-num: #1a3a8f;
  --tf-green-d: #0e4a20; --tf-red-d: #7d0f15; --tf-blue-d: #0c3566;
  --ink: #222;
  --char: #1a1a1a;   /* characters (m) */
  --bamboo: #1f8a3b;  /* bamboo (s) */
  --dots: #1c6fd6;    /* dots (p) */
  --red: #c8202a;
  --gold: #e9c46a;
  --panel: rgba(0, 0, 0, 0.22);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

/* Jade theme values stated explicitly so theme previews are self-contained
   (a Jade swatch shown while the app is in Ink mode still renders Jade). */
[data-theme="jade"] {
  --tf-green: #1f7a37; --tf-red: #c01722; --tf-blue: #15539e; --tf-ink: #1c1c1c;
  --tf-gold: #b8860b; --tf-num: #1a3a8f;
  --tf-green-d: #0e4a20; --tf-red-d: #7d0f15; --tf-blue-d: #0c3566;
  --tile-side: #d6c8a4; --tile-side-dark: #b6a77f; --tile-edge: #cdc1a4;
}

/* Slate theme (free): cool light-grey tiles */
[data-theme="slate"] {
  --tf-green: #1f7a37; --tf-red: #c01722; --tf-blue: #15539e; --tf-ink: #1c1c1c;
  --tf-gold: #8a6d1f; --tf-num: #1a3a8f;
  --tf-green-d: #0e4a20; --tf-red-d: #7d0f15; --tf-blue-d: #0c3566;
  --tile-side: #b6c0ca; --tile-side-dark: #96a2ae; --tile-edge: #aab4bf;
}
[data-theme="slate"] .tile { background: linear-gradient(157deg, #f6f9fc 0%, #e4ebf1 55%, #d3dce4 100%); }
[data-theme="slate"] .tile.back { background: linear-gradient(157deg, #5f7183, #435463); border-color: #2c3743; }

/* Royal theme (premium): midnight blue tiles, gold numerals */
[data-theme="royal"] {
  --tf-green: #5bd6a0; --tf-red: #ff8090; --tf-blue: #93b8ff; --tf-ink: #f0e9d0;
  --tf-gold: #f0d97a; --tf-num: #ffd66b;
  --tf-green-d: #2f9c74; --tf-red-d: #c04d5a; --tf-blue-d: #4a6fb0;
  --tile-side: #171f3c; --tile-side-dark: #0d1430; --tile-edge: #0b1026;
}
[data-theme="royal"] .tile { background: linear-gradient(157deg, #2a3568 0%, #1c2450 55%, #131a3c 100%); }
[data-theme="royal"] .tile-face { filter: drop-shadow(0 0.5px 0.5px rgba(0,0,0,.7)); }
[data-theme="royal"] .tile.back { background: linear-gradient(157deg, #2c3770, #1a2146); border-color: #0e1332; }

/* ---- Ink tile theme (premium): dark charcoal tiles, bright engraving ---- */
[data-theme="ink"] {
  --tf-green: #4ade80; --tf-red: #fb7185; --tf-blue: #60a5fa; --tf-ink: #e8e8ea;
  --tf-gold: #e8d49a; --tf-num: #8fbcff;
  --tf-green-d: #1c8a4e; --tf-red-d: #c04d5a; --tf-blue-d: #3b6fb0;
  --tile-side: #2a2e33; --tile-side-dark: #16181c; --tile-edge: #14171b;
}
[data-theme="ink"] .tile {
  background: linear-gradient(157deg, #3d434b 0%, #2c3037 55%, #1f2227 100%);
  box-shadow:
    inset 0 1.5px 0.5px rgba(255,255,255,.14),
    inset -1.5px -2px 2.5px rgba(0,0,0,.5),
    0 2px 2px rgba(0,0,0,.4);
}
[data-theme="ink"] .your-hand .tile {
  box-shadow:
    inset 0 2px 0.5px rgba(255,255,255,.14), inset -2px -3px 4px rgba(0,0,0,.5),
    0 4px 0 var(--tile-side), 0 5px 0 var(--tile-side-dark), 0 8px 11px rgba(0,0,0,.55);
}
[data-theme="ink"] .tile-face { filter: drop-shadow(0 0.5px 0.5px rgba(0,0,0,.7)); }
[data-theme="ink"] .tile.back {
  background: linear-gradient(157deg, #333a42 0%, #262b31 55%, #1a1d22 100%);
  border-color: #12151a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(ellipse 70% 55% at 50% 22%, rgba(60,110,90,.35), transparent 70%),
    radial-gradient(ellipse at 50% 30%, #1b3a30 0%, #0c1f19 65%, #060f0c 100%);
  color: #f3f3f3;
  overflow: hidden;
  overscroll-behavior: none;          /* no iOS rubber-band bounce */
  touch-action: manipulation;         /* kill the 300ms tap delay / double-tap zoom */
  -webkit-user-select: none;          /* feels native — no accidental text selection */
  user-select: none;
  -webkit-touch-callout: none;        /* no long-press callout on tiles/buttons */
}
/* re-enable selection where it's actually useful (editable name field) */
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
/* honour the notch / home-indicator safe areas on iPhone (PWA + native) */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
           calc(4px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); }

/* ---- top bar ---- */
#topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.brand span { color: var(--gold); }
.scores { display: flex; gap: 8px; order: 3; width: 100%; flex-wrap: wrap; }
.score-chip {
  background: var(--panel); padding: 4px 10px; border-radius: 8px; font-size: 13px;
  border: 1px solid rgba(255,255,255,.08); min-width: 92px;
}
.score-chip.turn { outline: 2px solid var(--gold); }
.score-chip .nm { font-weight: 600; }
.score-chip .pts { float: right; font-variant-numeric: tabular-nums; }
.score-chip .pts.neg { color: #ff9d9d; }
.score-chip .pts.pos { color: #aef0c0; }
.score-chip .ai-style { font-size: 10px; opacity: .6; margin-top: 2px; }
.modal .sect-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; opacity: .65; margin: 12px 0 4px; }
.controls { display: flex; gap: 10px; align-items: center; font-size: 13px; margin-left: auto; }
.controls select { background: #0c3a2e; color: #fff; border: 1px solid #2c6b58; border-radius: 6px; padding: 3px 6px; }
.controls button, .btn {
  background: var(--gold); color: #1a1a1a; border: 0; padding: 7px 14px; border-radius: 8px;
  font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}
.controls button:hover, .btn:hover { filter: brightness(1.07); }
.btn.secondary { background: #2c6b58; color: #fff; }

/* ---- floating game HUD ---- */
#hud {
  /* top-right corner, below the score chips — the side seats' tile rivers live
     at mid-height, so the corner is the one spot that never collides */
  position: fixed; right: calc(8px + env(safe-area-inset-right));
  top: calc(116px + env(safe-area-inset-top)); z-index: 930;
  display: flex; flex-direction: column; gap: 10px;
}
.hud-btn {
  width: 46px; height: 46px; border-radius: 50%; font-size: 21px; line-height: 1;
  background: rgba(8, 34, 27, .82); border: 2px solid #2c6b58; color: #fff;
  cursor: pointer; box-shadow: 0 3px 10px rgba(0, 0, 0, .4);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.hud-btn:hover { filter: brightness(1.2); }
.hud-btn.on { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 14px rgba(230, 195, 92, .55); }
/* desktop: coach panel docks on the right — slide the HUD out of its way */
@media (min-width: 1000px) {
  body.coach-open #hud { right: 322px; }
}
/* mobile: coach is a top sheet — tuck the HUD into a row just beneath it */
@media (max-width: 999px) {
  body.coach-open #hud { top: calc(48vh + 10px); transform: none; flex-direction: row; }
}
/* the HUD belongs to the game table — hide it under the home/landing screen */
body.home-open #hud { display: none; }

/* ---- pause-style settings popup (⚙️) ---- */
#drawerBackdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 940;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
#drawer {
  position: fixed; top: 50%; left: 50%; z-index: 950;
  width: min(340px, 92vw); max-height: min(560px, 86vh); overflow-y: auto;
  background: #0b2b22; border: 1px solid var(--gold); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  padding: 20px;
  transform: translate(-50%, -50%) scale(.92); opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
body.drawer-open #drawer { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
body.drawer-open #drawerBackdrop { opacity: 1; pointer-events: auto; }
#drawer .controls {
  flex-direction: column; align-items: stretch; gap: 12px; margin-left: 0; font-size: 14px;
}
#drawer .controls label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#drawer .controls select { padding: 6px 8px; }
#drawer .controls button { padding: 12px; font-size: 14px; text-align: center; }

/* ---- table ---- */
/* The board is a spatial diagram (seats fixed at N/E/S/W), not prose — keep it
 * LTR even when the document is RTL (Arabic); only text panels should mirror. */
#table, #actionbar, #trainbar, #drawer .controls { direction: ltr; }
#table {
  flex: 1; display: grid;
  grid-template-columns: minmax(120px, 1fr) 2.4fr minmax(120px, 1fr);
  grid-template-rows: minmax(78px, 0.8fr) 2.8fr minmax(150px, auto);
  gap: 6px; min-height: 0;
}
.seat-top { grid-column: 2; grid-row: 1; }
.seat-left { grid-column: 1; grid-row: 2; }
.seat-right { grid-column: 3; grid-row: 2; }
#center { grid-column: 2; grid-row: 2; }
.seat-bottom { grid-column: 2; grid-row: 3; }

.seat { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; min-height: 0; }
.seat-left, .seat-right { justify-content: center; }
.seat-name { font-size: 12px; opacity: .85; }
.seat-name.active { color: var(--gold); font-weight: 700; opacity: 1; }

/* opponent concealed hand (backs) */
.hand-backs { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; max-width: 100%; }
.melds-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.meld { display: flex; gap: 1px; }
.meld-kong { outline: 2px solid rgba(233,196,106,.5); outline-offset: 1px; border-radius: 3px; }
.bonus-row { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; }

/* discard rivers */
.river { display: flex; flex-wrap: wrap; gap: 2px; max-width: 320px; justify-content: center; align-content: flex-start; }
.seat-left .river, .seat-right .river { max-width: 110px; }

/* center info */
#center {
  background:
    radial-gradient(ellipse 82% 74% at 50% 40%, #1c9a6c 0%, #116449 60%, #0a4d37 100%);
  border-radius: 18px;
  border: 5px solid var(--wood);
  box-shadow:
    inset 0 0 80px rgba(0,0,0,.5),
    inset 0 3px 10px rgba(0,0,0,.35),
    inset 0 -2px 6px rgba(255,255,255,.06),
    0 0 0 1px rgba(0,0,0,.4),
    0 10px 28px rgba(0,0,0,.45);
  display: flex; flex-direction: column; position: relative;
  align-items: center; justify-content: center; gap: 8px; padding: 12px; min-height: 0;
}
/* fine felt grain */
#center::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  opacity: .4; mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.center-info { text-align: center; font-size: 12px; line-height: 1.45; }
.center-info .big { font-size: 22px; font-weight: 800; color: var(--gold); }
.wind-badge { display:inline-block; background: rgba(0,0,0,.3); border-radius:6px; padding:2px 8px; margin:2px; }

/* central discard pool — each player's river faces the middle */
.discard-pool {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: 1fr auto 1fr;
  gap: 4px 8px; width: 100%; height: 100%;
  align-items: center; justify-items: center;
}
.dp-zone { display: flex; flex-wrap: wrap; gap: 2px; align-content: flex-start; justify-content: center; }
.dp-slot { display: inline-flex; align-items: center; justify-content: center; flex: none; }
/* a fresh discard flies into the pool from its player's side (slot carries the
   translate so the tile's own rotation is left untouched) */
@keyframes flyB { from { transform: translateY(78px) scale(1.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flyT { from { transform: translateY(-78px) scale(1.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flyR { from { transform: translateX(104px) scale(1.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flyL { from { transform: translateX(-104px) scale(1.4); opacity: 0; } to { transform: none; opacity: 1; } }
.dp-slot.fly-b { animation: flyB .34s cubic-bezier(.25,.9,.35,1); }
.dp-slot.fly-t { animation: flyT .34s cubic-bezier(.25,.9,.35,1); }
.dp-slot.fly-r { animation: flyR .34s cubic-bezier(.25,.9,.35,1); }
.dp-slot.fly-l { animation: flyL .34s cubic-bezier(.25,.9,.35,1); }
.dp-top    { grid-column: 2; grid-row: 1; align-self: end; max-width: 300px; }
.dp-bottom { grid-column: 2; grid-row: 3; align-self: start; max-width: 300px; }
.dp-left   { grid-column: 1; grid-row: 2; justify-self: end; flex-direction: column; align-content: center; max-height: 174px; }
.dp-right  { grid-column: 3; grid-row: 2; justify-self: start; flex-direction: column; align-content: center; max-height: 174px; }
/* wrapper that reserves the rotated tile's bounding box so side discards lie flat */
.dp-rot { width: 30px; height: 22px; display: flex; align-items: center; justify-content: center; flex: none; }
.dp-center {
  grid-column: 2; grid-row: 2; z-index: 2;
  background: rgba(7, 38, 30, 0.82); border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 6px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.4);
}

/* ---- tiles ---- */
.tile {
  position: relative; width: 34px; height: 46px; border-radius: 6px 6px 7px 7px;
  background: linear-gradient(157deg, #fffefb 0%, #f8f2e2 52%, #ece1c8 100%);
  border: 1px solid var(--tile-edge);
  box-shadow:
    inset 0 1.5px 0.5px rgba(255,255,255,.95),
    inset 1.5px 0 1px rgba(255,255,255,.55),
    inset -1.5px -2px 2.5px rgba(120,102,66,.3),
    0 2px 2px rgba(0,0,0,.32);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--ink); user-select: none; flex: none;
}
.tile .big { font-size: 21px; font-weight: 800; line-height: 1; }
.tile .small { font-size: 10px; opacity: .8; margin-top: 1px; }
.tile.face-tile { padding: 2px; }
/* carved-into-ivory look: soft dark shadow below + faint highlight above each stroke */
.tile-face { width: 100%; height: 100%; display: block; filter: drop-shadow(0 0.5px 0.4px rgba(70,52,28,.4)); }
.tile.m .big { color: var(--char); }
.tile.s .big, .tile.s .small { color: var(--bamboo); }
.tile.p .big, .tile.p .small { color: var(--dots); }
.tile.dr .big { color: var(--red); }     /* red dragon */
.tile.dg .big { color: var(--bamboo); }   /* green dragon */
.tile.dw .big { color: #555; }            /* white dragon */
.tile.w .big { color: #1a1a1a; }
.tile.bonus .big { color: #b8860b; }

.tile.sm { width: 24px; height: 33px; }
.tile.sm .big { font-size: 15px; }
.tile.sm .small { font-size: 8px; }
.tile.xs { width: 22px; height: 30px; }
.tile.xs .big { font-size: 13px; }
.tile.xs .small { font-size: 8px; }

.tile.back {
  background: linear-gradient(157deg, #34b07d 0%, #1f9061 52%, #146b46 100%);
  border-color: #0e5236;
  box-shadow:
    inset 0 1.5px 1px rgba(255,255,255,.4),
    inset -1.5px -2px 3px rgba(0,0,0,.32),
    0 2px 2px rgba(0,0,0,.38);
}
/* ornate engraved emblem on the back */
.tile-back-face {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 0.5px 0.4px rgba(0,0,0,.4)) drop-shadow(0 -0.4px 0.3px rgba(255,255,255,.18));
}

.tile.recent { outline: 3px solid var(--gold); z-index: 2; }
/* a freshly thrown tile flashes in (opacity/filter only — safe with rotation) */
@keyframes dropIn { 0% { opacity: 0; filter: brightness(2.2); } 100% { opacity: 1; filter: brightness(1); } }
.tile.drop-in { animation: dropIn .3s ease-out; }
@keyframes modalIn { 0% { transform: scale(.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.modal { animation: modalIn .26s cubic-bezier(.2,.9,.3,1.25); }
@keyframes drawPop { 0% { transform: translateY(-30px) scale(1.12); opacity: .05; } 60% { opacity: 1; } 100% { transform: translateY(0) scale(1); opacity: 1; } }
.your-hand .tile.drawn.fresh { animation: drawPop .3s cubic-bezier(.25,.9,.35,1); }
.tile.dim { opacity: .5; }
.tile.concealed-kong .endcap { }

/* your hand */
.your-hand { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.your-hand .tile {
  width: 44px; height: 60px; cursor: default; transition: transform .12s ease, box-shadow .12s ease;
  border-radius: 7px 7px 9px 9px;
  box-shadow:
    inset 0 2px 0.5px rgba(255,255,255,.95),
    inset 2px 0 1.5px rgba(255,255,255,.5),
    inset -2px -3px 4px rgba(120,102,66,.32),
    0 4px 0 var(--tile-side),       /* the tile's thickness */
    0 5px 0 var(--tile-side-dark),
    0 8px 11px rgba(0,0,0,.5);      /* cast shadow on the table */
}
.your-hand.can-discard .tile { cursor: pointer; }
.your-hand.can-discard .tile:hover {
  transform: translateY(-10px);
  box-shadow:
    inset 0 2px 0.5px rgba(255,255,255,.95),
    inset -2px -3px 4px rgba(120,102,66,.32),
    0 4px 0 var(--tile-side), 0 5px 0 var(--tile-side-dark),
    0 0 0 2px var(--gold), 0 16px 18px rgba(0,0,0,.55);
}
.your-hand .tile.drawn { margin-left: 14px; }

.hand-meta { font-size: 12px; opacity: .85; min-height: 16px; text-align: center; }

/* ---- action bar ---- */
#actionbar { min-height: 46px; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
#actionbar .prompt { font-size: 13px; opacity: .9; margin-right: 6px; }
#actionbar .noyaku-hint {
  flex-basis: 100%; text-align: center; font-size: 12.5px; line-height: 1.45;
  max-width: 640px; margin: 0 auto 2px; padding: 6px 12px;
  background: rgba(138,109,31,.22); border: 1px solid rgba(233,196,106,.5); border-radius: 8px;
}
#actionbar .noyaku-hint b { color: var(--gold); }
.claim-btn { display: flex; align-items: center; gap: 6px; }
.claim-btn .mini { display: flex; gap: 1px; }

/* ---- log ---- */
#log {
  height: 70px; overflow-y: auto; background: var(--panel); border-radius: 8px; padding: 6px 10px;
  font-size: 12px; line-height: 1.5; border: 1px solid rgba(255,255,255,.06);
}
#log .entry { opacity: .9; }
#log .entry.win { color: var(--gold); font-weight: 600; }

/* ---- training stats bar + toast ---- */
#trainbar {
  display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap;
  font-size: 12px; background: var(--panel); border: 1px solid rgba(255,255,255,.06);
  border-radius: 8px; padding: 5px 10px;
}
#trainbar.hidden { display: none; }
#trainbar .stat b { color: var(--gold); font-variant-numeric: tabular-nums; }
#trainbar .stat.bad b { color: #ff9d9d; }

#toast {
  position: fixed; left: 50%; bottom: 156px; transform: translateX(-50%) translateY(8px);
  max-width: 460px; background: #12342a; border-left: 5px solid var(--gold); border-radius: 8px;
  padding: 9px 14px; font-size: 13px; line-height: 1.4; box-shadow: 0 8px 26px rgba(0,0,0,.5);
  z-index: 60; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.hidden { display: none; }
#toast .g { font-weight: 800; margin-right: 6px; }
#toast.optimal { border-left-color: #3fbf6f; } #toast.optimal .g { color: #6fe29a; }
#toast.good { border-left-color: #4aa3c0; } #toast.good .g { color: #8fd6ec; }
#toast.suboptimal { border-left-color: #d8a23a; } #toast.suboptimal .g { color: #f0c46a; }
#toast.bad { border-left-color: #d05151; } #toast.bad .g { color: #ffb3b3; }

/* ---- opening dice roll ---- */
#dice {
  position: fixed; left: 50%; top: 44%; transform: translate(-50%, -50%);
  display: flex; gap: 14px; z-index: 70; pointer-events: none; opacity: 0;
  transition: opacity .3s;
}
#dice.show { opacity: 1; }
#dice.hidden { display: none; }
#dice .die {
  width: 56px; height: 56px; border-radius: 12px; background: linear-gradient(160deg, #fff, #e7e0cf);
  box-shadow: 0 8px 22px rgba(0,0,0,.5); position: relative; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 8px; gap: 2px; animation: diceRoll .55s cubic-bezier(.2,.9,.3,1.2);
}
#dice .die > div { display: flex; align-items: center; justify-content: center; }
#dice .die i { background: #c8202a; border-radius: 50%; width: 9px; height: 9px; }
@keyframes diceRoll {
  0% { transform: rotate(-160deg) scale(.4); opacity: .2; }
  100% { transform: rotate(0) scale(1); opacity: 1; }
}

/* ---- overlay ---- */
#overlay {
  position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.62);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center;
}

/* ---- home / lobby (mobile-gaming marketing landing page) ---- */
#home {
  position: fixed; inset: 0; z-index: 900; display: none; align-items: flex-start; justify-content: center;
  padding: 0 20px 40px; overflow-y: auto;
  background:
    radial-gradient(ellipse 70% 55% at 50% 20%, rgba(60,110,90,.4), transparent 70%),
    radial-gradient(ellipse at 50% 40%, #14342a 0%, #0a1c17 70%, #060f0c 100%);
}
#home.show { display: flex; }

.landing { width: 100%; max-width: 560px; padding-top: calc(36px + env(safe-area-inset-top)); }

/* ---- hero ---- */
.hero { text-align: center; margin-bottom: 34px; }
.hero-icon { font-size: 58px; line-height: 1; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
.hero-title {
  font-size: 34px; font-weight: 800; margin: 10px 0 6px; letter-spacing: .5px;
  background: linear-gradient(180deg, #f6e4b0, #d9b45c); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { opacity: .85; font-size: 15px; line-height: 1.5; max-width: 420px; margin: 0 auto 16px; }
.trust-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 26px; }
.trust-item { font-size: 12px; opacity: .7; background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-radius: 20px; padding: 4px 11px; }
.trust-dot { opacity: .4; }

.hero-mock { display: flex; flex-direction: column; align-items: center; gap: 16px; margin: 6px 0 28px; }
.hero-fan { display: flex; justify-content: center; height: 92px; align-items: flex-end; }
.hero-fan .hero-tile {
  width: 52px; height: 72px; margin-left: -24px; box-shadow: 0 10px 20px rgba(0,0,0,.45);
  transform-origin: 50% 100%;
}
.hero-fan .hero-tile:first-child { margin-left: 0; }
.hero-tip {
  background: #0d2c24; border: 1px solid var(--gold); border-radius: 10px;
  padding: 8px 14px; font-size: 12.5px; box-shadow: 0 8px 20px rgba(0,0,0,.35); max-width: 300px; text-align: center;
}
.hero-tip b { color: var(--gold); }
.cta-row { display: flex; flex-direction: column; gap: 10px; max-width: 340px; margin: 0 auto; }

/* ---- feature grid ---- */
.features { margin-bottom: 30px; }
.features-title { font-size: 18px; font-weight: 800; text-align: center; margin: 0 0 16px; opacity: .95; }
.feature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.feature-card {
  background: rgba(13,44,36,.6); border: 1px solid rgba(233,196,106,.2); border-radius: 14px;
  padding: 14px 12px; text-align: left;
}
.feature-icon { font-size: 22px; margin-bottom: 6px; }
.feature-title { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.feature-desc { font-size: 12px; opacity: .75; line-height: 1.4; }

.util-block {
  background: rgba(13,44,36,.78); border: 1px solid rgba(233,196,106,.35); border-radius: 20px;
  padding: 26px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.5); backdrop-filter: blur(3px); text-align: center;
}
.acct { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; }
.acct-av { font-size: 30px; }
.acct-name { font-weight: 700; font-size: 15px; text-align: left; }
.acct-sub { font-size: 12px; opacity: .7; text-align: left; }
.link-btn { background: none; border: 0; color: var(--gold); cursor: pointer; font-size: 13px; text-decoration: underline; margin-left: auto; }
.link-btn.danger { color: #e08585; }
.link-btn.center { display: block; margin: 8px auto 0; }
.btn.danger { background: #b3352f; color: #fff; border-color: #8f2823; }
.btn.danger:disabled { opacity: .6; }
.confirm-modal { max-width: 400px; }
.confirm-modal .fine { font-size: 12px; opacity: .6; margin-top: 8px; }
.home-actions { display: flex; flex-direction: column; gap: 10px; }
.btn.big { padding: 13px 16px; font-size: 15px; border-radius: 11px; }
.home-foot { font-size: 11px; opacity: .55; margin-top: 16px; text-align: center; }
.home-foot a { color: inherit; text-decoration: underline; }
.install-hint { font-size: 12px; opacity: .72; text-align: center; margin-top: 12px;
  background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-radius: 9px; padding: 8px 10px; }
.install-hint b { color: var(--gold); font-weight: 700; }
.acct-section { margin-bottom: 18px; }
.acct-sub.center { text-align: center; margin-bottom: 10px; }
.acct-edit { margin-left: auto; color: var(--gold); font-size: 12px; }
.acct-btn { width: 100%; cursor: pointer; }
.signin-row { display: flex; flex-direction: column; gap: 8px; }
.signin-btn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 11px;
  border: 0; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.signin-btn .si-ic { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center; font-weight: 800; }
.signin-btn.google { background: #fff; color: #1f1f1f; }
.signin-btn.google .si-ic { color: #4285F4; font-family: Arial, sans-serif; }
.signin-btn.apple { background: #000; color: #fff; }
.signin-btn.apple .si-ic::before { content: ""; }
.plus-badge { display: inline-block; margin-left: 7px; background: linear-gradient(180deg,#f6e4b0,#d9b45c); color: #3a2b08;
  font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; vertical-align: middle; letter-spacing: .5px; }
.btn.plus-cta { background: linear-gradient(180deg,#f6e4b0,#d9b45c); color: #3a2b08; }

/* store */
.store-modal, .lb-modal { max-width: 440px; }
.prod { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px; padding: 11px 13px; margin-bottom: 8px; }
.prod.plus { border-color: rgba(233,196,106,.5); background: rgba(233,196,106,.1); flex-direction: column; align-items: stretch; text-align: center; gap: 8px; }
.prod.hi { outline: 2px solid var(--gold); }
.prod.owned { opacity: .7; }
.prod-title { font-weight: 700; font-size: 14px; }
.prod-desc { font-size: 12px; opacity: .78; line-height: 1.4; margin-top: 2px; }
.prod .btn { flex: none; }
.prod:not(.plus) > div:first-child { flex: 1; }

/* leaderboard */
.lb-list { list-style: none; padding: 0; margin: 0; counter-reset: none; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid rgba(255,255,255,.07); }
.lb-row.me { background: rgba(233,196,106,.12); border-radius: 8px; }
.lb-rank { width: 34px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.lb-av { font-size: 22px; }
.lb-name { font-weight: 600; }
.lb-score { margin-left: auto; font-variant-numeric: tabular-nums; opacity: .85; }

/* ---- auth ---- */
.auth-modal, .friends-modal { max-width: 380px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.auth-tab { flex: 1; background: var(--panel); border: 1px solid rgba(255,255,255,.08); color: #ddd;
  padding: 9px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.auth-tab.on { background: rgba(233,196,106,.16); border-color: var(--gold); color: var(--gold); }
.auth-input { width: 100%; background: #0c3a2e; color: #fff; border: 1px solid #2c6b58; border-radius: 8px;
  padding: 11px 12px; font-size: 15px; margin-bottom: 10px; box-sizing: border-box; }
.auth-avatars { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.auth-av { font-size: 22px; width: 40px; height: 40px; border-radius: 9px; border: 1px solid transparent;
  background: var(--panel); cursor: pointer; }
.auth-av.on { border-color: var(--gold); background: rgba(233,196,106,.16); }
.auth-err { color: #ff9d9d; font-size: 13px; min-height: 16px; margin-bottom: 4px; }

/* ---- friends ---- */
.friend-add { display: flex; gap: 8px; margin-bottom: 4px; }
.friend-add .auth-input { margin-bottom: 0; }
.friend-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid rgba(255,255,255,.07); }
.friend-av { font-size: 22px; }
.friend-name { font-size: 14px; font-weight: 600; }
.friend-row .link-btn { margin-left: auto; }
.btn.sm { padding: 5px 10px; font-size: 12px; margin-left: auto; }
#overlay.hidden { display: none; }
.modal {
  background: #12342a; border: 2px solid var(--gold); border-radius: 14px; padding: 22px 26px;
  max-width: 460px; width: 90%; max-height: 92vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.modal h2 { margin: 0 0 6px; color: var(--gold); }
.modal .sub { opacity: .85; margin-bottom: 12px; font-size: 14px; }
.modal .faan-list { list-style: none; padding: 0; margin: 0 0 12px; }
.modal .faan-list li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,.12); font-size: 14px; }
.modal .total { font-weight: 800; font-size: 16px; margin: 8px 0 14px; }
.modal .modal-tiles { display: flex; gap: 3px; flex-wrap: wrap; margin-bottom: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---- profile ---- */
.profile-modal { max-width: 520px; }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.profile-avatar { font-size: 40px; width: 62px; height: 62px; border-radius: 14px; border: 1px solid var(--gold);
  background: rgba(233,196,106,.12); cursor: pointer; line-height: 1; display: flex; align-items: center; justify-content: center; }
.profile-avatar:hover { background: rgba(233,196,106,.22); }
.profile-name { flex: 1; }
.profile-name-input { width: 100%; background: #0c3a2e; color: #fff; border: 1px solid #2c6b58; border-radius: 8px;
  padding: 7px 10px; font-size: 18px; font-weight: 700; }
.profile-name .sub { margin-top: 3px; }
.lang-row { margin-bottom: 4px; }
.lang-select { width: 100%; background: var(--panel); color: #fff; border: 1px solid rgba(255,255,255,.14);
  border-radius: 9px; padding: 8px 10px; font-size: 13.5px; }
.theme-row { display: flex; gap: 10px; margin-bottom: 4px; }
.theme-opt { flex: 1; background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 8px; cursor: pointer; }
.theme-opt.active { border-color: var(--gold); background: rgba(233,196,106,.1); }
.theme-prev { display: flex; gap: 4px; justify-content: center; padding: 9px; border-radius: 8px;
  background: radial-gradient(ellipse at 50% 40%, #1a9068, #0d3327); }
.theme-nm { font-size: 12px; font-weight: 700; margin-top: 7px; text-align: center; }
.theme-opt.active .theme-nm { color: var(--gold); }
.avatar-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.av-opt { font-size: 22px; width: 40px; height: 40px; border-radius: 9px; border: 1px solid transparent;
  background: var(--panel); cursor: pointer; position: relative; line-height: 1; }
.av-opt.active { border-color: var(--gold); background: rgba(233,196,106,.16); }
.av-opt.locked { opacity: .55; }
.av-opt.locked::after { content: "🔒"; position: absolute; right: -3px; bottom: -3px; font-size: 11px; }

/* ---- Onboarding first-run flow ---- */
.modal.onboard { max-width: 400px; text-align: center; }
.ob-icon { font-size: 52px; line-height: 1; margin: 6px 0 10px; }
.ob-title { font-size: 21px; margin: 0 0 10px; }
.ob-body { font-size: 14.5px; line-height: 1.5; opacity: .9; margin: 0 auto 14px; max-width: 320px; }
.ob-note { font-size: 12.5px; opacity: .7; background: var(--panel); border: 1px solid rgba(255,255,255,.07);
  border-radius: 8px; padding: 8px 10px; margin: 0 auto 4px; max-width: 320px; }
.ob-dots { display: flex; justify-content: center; gap: 7px; margin: 16px 0 14px; }
.ob-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.22); }
.ob-dot.on { background: var(--gold); }
.ob-actions { display: flex; align-items: center; gap: 8px; }
.ob-actions .ob-spacer { flex: 1; }
.ob-actions .link-btn { margin-left: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 4px; }
.stat-cell { background: var(--panel); border: 1px solid rgba(255,255,255,.07); border-radius: 8px; padding: 8px 6px; text-align: center; }
.stat-val { font-size: 18px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 10.5px; opacity: .7; margin-top: 2px; }
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ach { background: var(--panel); border: 1px solid rgba(255,255,255,.07); border-radius: 8px; padding: 9px 8px; text-align: center; opacity: .5; }
.ach.got { opacity: 1; border-color: rgba(233,196,106,.5); background: rgba(233,196,106,.1); }
.ach-icon { font-size: 22px; line-height: 1; }
.ach-name { font-size: 12px; font-weight: 700; margin-top: 3px; }
.ach.got .ach-name { color: var(--gold); }
.ach-desc { font-size: 10px; opacity: .75; line-height: 1.3; margin-top: 1px; }
.hist { display: flex; gap: 4px; flex-wrap: wrap; }
.hist-pip { min-width: 22px; height: 22px; padding: 0 4px; border-radius: 5px; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.hist-pip.win { background: #2c7a4b; color: #cfeedd; }
.hist-pip.loss { background: #4a4a4a; color: #ddd; }
.hist-pip.dealin { background: #8a2e2e; color: #ffcccc; }
.hist-pip.draw { background: #6b5a2c; color: #f0e0b0; }
#toast.ach { border-left-color: var(--gold); } #toast.ach .g { color: var(--gold); }

/* Plus upsell nudge inside the hand-over modal */
.plus-pitch {
  display: flex; align-items: center; gap: 11px; text-align: left;
  margin: 12px 0 2px; padding: 11px 13px; border-radius: 11px;
  background: linear-gradient(120deg, rgba(233,196,106,.16), rgba(233,196,106,.06));
  border: 1px solid rgba(233,196,106,.45);
}
.plus-pitch .pp-star { font-size: 24px; line-height: 1; }
.plus-pitch .pp-text { flex: 1; }
.plus-pitch .pp-title { font-weight: 800; color: var(--gold); font-size: 14px; }
.plus-pitch .pp-sub { font-size: 12px; opacity: .85; line-height: 1.4; margin-top: 2px; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; flex: none; }

/* ---- desktop wide-screen: center the play area; dock the coach as a column ---- */
@media (min-width: 1000px) {
  #app { max-width: 1180px; margin-inline: auto; }
  /* when the coach is open, lay the board + coach side by side (two columns) */
  body.coach-open { display: flex; align-items: stretch; justify-content: center; gap: 12px; }
  body.coach-open #app { margin: 0; max-width: 940px; flex: 1 1 auto; min-width: 0; }
  body.coach-open #coach {
    position: static; flex: 0 0 300px; width: 300px; max-height: none;
    align-self: stretch; margin: 8px 8px 8px 0; box-shadow: none;
  }
}

/* ---- responsive / mobile ---- */
@media (max-width: 820px) {
  body { overflow: auto; height: auto; }
  #app { height: auto; min-height: 100vh; min-height: 100dvh;
    padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right))
             calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left)); }
  .brand { font-size: 16px; }
  .brand span { display: none; }
  #topbar { gap: 8px; }
  .scores { order: 3; width: 100%; gap: 6px; }
  .score-chip { min-width: 0; flex: 1; font-size: 12px; padding: 3px 7px; }
  .controls { font-size: 12px; gap: 7px; flex-wrap: wrap; }
  #table {
    grid-template-columns: 76px 1fr 76px;
    grid-template-rows: minmax(64px, auto) 1.5fr minmax(120px, auto);
  }
  .tile { width: 27px; height: 37px; }
  .tile .big { font-size: 16px; }
  .tile.sm { width: 19px; height: 26px; }
  .tile.sm .big { font-size: 12px; }
  .your-hand .tile { width: 34px; height: 47px; }
  .your-hand .tile .big { font-size: 20px; }
  .your-hand .tile.drawn { margin-left: 8px; }
  .river { max-width: 190px; }
  .seat-left .river, .seat-right .river { max-width: 72px; }
  .hand-backs .tile { width: 14px; height: 19px; }
  /* Coach becomes a top sheet so the hand + buttons stay reachable below.
     `aside#coach` raises specificity above the later base `#coach` rule. */
  aside#coach {
    top: 0; left: 0; right: 0; bottom: auto; width: 100%; max-width: none;
    max-height: 48vh; border-radius: 0 0 12px 12px; border-top: 0;
  }
  #toast { bottom: 116px; width: 92%; }
}

@media (max-width: 520px) {
  #table { grid-template-columns: 50px 1fr 50px; gap: 3px; }
  .tile { width: 21px; height: 29px; }
  .tile .big { font-size: 12px; }
  .tile .small { font-size: 7px; }
  .hand-backs .tile { width: 12px; height: 16px; }
  .your-hand { gap: 3px; }
  .your-hand .tile { width: 29px; height: 40px; }
  .your-hand .tile .big { font-size: 17px; }
  .center-info { font-size: 11px; }
  .center-info .big { font-size: 20px; }
  .controls button, .btn { padding: 5px 8px; font-size: 11px; }
  .controls label { font-size: 11px; }
  #log { height: 46px; }
  #trainbar { font-size: 11px; gap: 8px; }
  .hero-title { font-size: 27px; }
  .hero-sub { font-size: 13.5px; }
  .feature-grid { gap: 8px; }
  .feature-card { padding: 11px 10px; }
  .util-block { padding: 20px 16px; }
}

/* ---- coach panel ---- */
#coach {
  position: fixed; top: 56px; right: 10px; width: 290px; max-height: calc(100vh - 70px);
  overflow-y: auto; background: #0d2c24; border: 1px solid var(--gold); border-radius: 12px;
  padding: 12px 14px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.45); z-index: 50;
}
#coach.hidden { display: none; }
#coach h3 { margin: 0 0 8px; color: var(--gold); font-size: 14px; display: flex; align-items: center; gap: 6px; }
#coach .headline { font-size: 13px; line-height: 1.5; margin-bottom: 10px; }
#coach .headline b { color: var(--gold); }
#coach .reco {
  background: rgba(233,196,106,.12); border: 1px solid rgba(233,196,106,.4);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
#coach .reco .why { flex-basis: 100%; opacity: .85; font-size: 12px; line-height: 1.4; }
#coach .sect-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; opacity: .65; margin: 10px 0 4px; }
#coach table { width: 100%; border-collapse: collapse; }
#coach td { padding: 3px 2px; border-bottom: 1px solid rgba(255,255,255,.07); vertical-align: middle; }
#coach tr.best td { background: rgba(233,196,106,.1); }
#coach td.num { text-align: right; font-variant-numeric: tabular-nums; }
#coach .pill { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 10px; background: #1d6b54; }
#coach .pill.iso { background: #7a3b2e; }
#coach .pill.ok { background: #2c7a4b; }
#coach .pill.no { background: #5a5a5a; }
#coach .pill.safe { background: #2c7a4b; }
#coach .pill.warn { background: #8a6d1f; }
#coach .pill.danger { background: #8a2e2e; }
#coach .warnbox { background: rgba(138,46,46,.25); border: 1px solid #8a2e2e; border-radius: 8px; padding: 7px 9px; margin-bottom: 10px; font-size: 12px; line-height: 1.45; }
#coach .warnbox b { color: #ffb3b3; }
#coach .warnbox .alt { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; }
#coach .threat { font-size: 12px; line-height: 1.45; margin: 3px 0; display: flex; align-items: baseline; gap: 6px; }
#coach .threat .lvl { flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: 1px; }
#coach .lvl3 { background: #e05151; }
#coach .lvl2 { background: #e0a04a; }
#coach .lvl1 { background: #d8d35a; }
#coach .lvl0 { background: #3a6b5a; }
#coach .safe-note { opacity: .8; }
#coach .waitline { display: flex; gap: 3px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
#coach .tiny { font-size: 11px; opacity: .75; }
#coach .tile.xs { width: 20px; height: 27px; }
#coach .tile.xs .big { font-size: 12px; }
#coach .tile.xs .small { font-size: 7px; }
.your-hand .tile.reco-tile { outline: 2px dashed var(--gold); }
