/* Games (/games/): the board, the leaderboard and the two 3D tables. Its own file so the games
   app touches no shared CSS; it reads the tokens in site.css (--card, --line, --tang, ...).
   Every class starts with gm-: the site already owns .bar, .foot, .btn, .chip and friends.
   Bump the ?v= on the link in templates/games/ when this file changes.
   Phone is the base; the board gets a second column at 960px. The 3D tables are dark on purpose
   (a perya at night) in both themes, so the stage uses its own --g-* colours. */

/* ---------- the head and the coin pill ---------- */
.gm-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; }
.gm-head h1 { margin-top: 6px; }
.gm-head p { margin: 8px 0 0; color: var(--txt-2); max-width: 62ch; }
.gm-pill { display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px 5px 6px; border-radius: 999px; background: color-mix(in srgb, var(--sun) 28%, var(--card)); color: var(--sun-on); font: 600 14px var(--mono); white-space: nowrap; }
.gm-pill:hover { text-decoration: none; }
:root[data-theme="dark"] .gm-pill { color: var(--sun-ink); }
.gm-dot { width: 22px; height: 22px; flex: none; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff3b0, var(--sun) 45%, #d9a600); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .15); }

/* ---------- the board ---------- */
.gm-lay { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-items: start; }
.gm-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.gm-card { position: relative; display: grid; align-content: end; gap: 3px; min-height: 150px; padding: 18px; border-radius: var(--r); color: #fff; overflow: hidden; box-shadow: 0 1px 2px var(--shadow); transition: transform .15s; }
a.gm-card:hover { text-decoration: none; transform: translateY(-2px); }
.gm-card h2 { color: #fff; font-size: 26px; }
.gm-card p { font-size: 13px; color: rgba(255, 255, 255, .94); max-width: 30ch; }
.gm-go { margin-top: 8px; font-weight: 700; font-size: 13px; }
.gm-tag { position: absolute; top: 14px; right: 14px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, .22); font: 600 10.5px var(--mono); }
/* White text on every card in both themes: the fills are fixed, not tokens (the *-ink tokens turn light in dark mode). */
.gm-trivia { background: linear-gradient(135deg, #3644d6, #232f9e); }
.gm-color { background: linear-gradient(135deg, #b8430a, #a3153d); }
.gm-lucky { background: linear-gradient(135deg, #04837c, #0b5d58); }
.gm-art { position: absolute; left: 18px; top: 18px; display: flex; gap: 6px; transform: rotate(-6deg); }
.gm-art i { width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, .2); display: grid; place-items: center; font: 700 14px var(--display); font-style: normal; color: #fff; }
.gm-trivia .gm-art i:nth-child(1)::after { content: "A"; } .gm-trivia .gm-art i:nth-child(2)::after { content: "B"; } .gm-trivia .gm-art i:nth-child(3)::after { content: "C"; }
.gm-color .gm-art i:nth-child(1) { background: #f2c01c; } .gm-color .gm-art i:nth-child(2) { background: #ee6aa9; } .gm-color .gm-art i:nth-child(3) { background: #2361d6; }
.gm-lucky .gm-art i { background: #fbf7ee; color: #1b1c22; width: 26px; height: 34px; border-radius: 6px; }
.gm-lucky .gm-art i:nth-child(1)::after { content: "9"; } .gm-lucky .gm-art i:nth-child(2)::after { content: "K"; color: #c4202b; } .gm-lucky .gm-art i:nth-child(3) { display: none; }

.gm-side { display: grid; gap: 14px; }
.gm-box { background: var(--card); border-radius: var(--r); padding: 18px; box-shadow: 0 1px 2px var(--shadow); display: grid; gap: 10px; }
:root[data-theme="dark"] .gm-box { box-shadow: inset 0 0 0 1px var(--line); }
.gm-box h2 { font-size: 15px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.gm-box h2 small { font: 500 11px var(--mono); color: var(--txt-3); }
.gm-eyebrow { font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--txt-3); }
.gm-bal { font: 800 38px/1 var(--display); color: var(--txt-hi); display: flex; align-items: center; gap: 10px; }
.gm-bal .gm-dot { width: 30px; height: 30px; }
.gm-box form { margin: 0; }
.gm-hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.gm-hist li { display: grid; grid-template-columns: 1fr auto; gap: 8px; color: var(--txt-2); }
.gm-hist b { font: 600 12px var(--mono); color: var(--txt-hi); }
.gm-hist .up { color: var(--ok); }
.gm-hist .down { color: var(--danger); }
.gm-rules { margin: 0; padding-left: 18px; display: grid; gap: 6px; color: var(--txt-2); font-size: 13px; }

.gm-lb { display: grid; gap: 4px; }
.gm-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; padding: 5px 8px; border-radius: 10px; color: var(--txt); }
.gm-row .n { font: 600 12px var(--mono); color: var(--txt-3); }
.gm-row .p { font: 600 13px var(--mono); color: var(--txt-hi); }
.gm-row .u { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--txt-hi); }
.gm-row.me { background: color-mix(in srgb, var(--grape) 12%, transparent); }
.gm-row.gap { padding: 0 8px; color: var(--txt-3); }
.gm-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.gm-tab { height: 34px; padding: 0 14px; border-radius: 999px; display: inline-flex; align-items: center; background: var(--sunk); color: var(--txt-hi); font-weight: 600; font-size: 13px; }
.gm-tab:hover { text-decoration: none; background: var(--line); }
.gm-tab.on { background: var(--txt-hi); color: var(--on-hi); }
.gm-note { color: var(--txt-3); font-size: 12.5px; }

/* ---------- a game page ---------- */
.gm-crumb { font: 500 12px var(--mono); color: var(--txt-3); }
.gm-help { color: var(--txt-2); font-size: 13px; max-width: 80ch; }

.gm-stage {
  --g-night: #090b14; --g-panel: rgba(13, 14, 24, .82); --g-ink: #fff6df; --g-muted: #bdb5cc; --g-marquee: #ffd23f;
  --g-sign: #9d1e22; --g-win: #66e38c; --g-lose: #ff8270; --g-push: #8fd3ff; --g-line: rgba(255, 246, 223, .14);
  position: relative; height: clamp(560px, calc(100svh - 200px), 860px); overflow: hidden; isolation: isolate;
  container-type: inline-size; border-radius: var(--r); background: var(--g-night); color: var(--g-ink);
  box-shadow: 0 1px 2px var(--shadow);
}
.gm-stage [hidden] { display: none !important; }
.gm-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; outline: none; }
.gm-loading { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; font: 700 18px var(--display); color: var(--g-marquee); background: var(--g-night); }
.gm-hud { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: 12px 14px; }
.gm-hud > * { pointer-events: auto; }
.gm-lbl { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--g-muted); }
.gm-num { font-family: var(--display); font-weight: 800; font-variant-numeric: tabular-nums; }

.gm-top { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 10px; pointer-events: none; }
.gm-top > * { pointer-events: auto; }
.gm-wallet, .gm-histbox, .gm-barbox { background: var(--g-panel); border: 1px solid var(--g-line); border-radius: 14px; backdrop-filter: blur(8px); }
.gm-wallet { justify-self: start; padding: 8px 12px; display: grid; gap: 2px; }
.gm-wallet .row { display: flex; align-items: center; gap: 10px; }
#bal { font-size: 22px; color: var(--g-marquee); }
.gm-back { color: var(--g-muted); font-size: 12px; font-weight: 600; border: 1px solid var(--g-line); border-radius: 8px; padding: 3px 8px; }
.gm-back:hover { color: var(--g-ink); text-decoration: none; }
.gm-sign { display: none; font-family: 'Bungee', Impact, 'Arial Black', sans-serif; font-weight: 400; font-size: clamp(18px, 2.6vw, 30px); letter-spacing: .04em; color: var(--g-marquee); background: var(--g-sign); padding: 10px 22px 8px; border-radius: 10px; text-shadow: 0 2px 0 #5a0d10, 0 0 18px rgba(255, 200, 60, .55); box-shadow: 0 0 0 3px #5a0d10, 0 0 0 6px var(--g-marquee), 0 0 30px rgba(255, 190, 40, .35); position: relative; white-space: nowrap; }
.gm-sign::after { content: ""; position: absolute; inset: -10px; border-radius: 14px; pointer-events: none; background: radial-gradient(circle, #fff3b0 0 2.2px, transparent 2.8px) 0 0 / 14px 14px; -webkit-mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); padding: 4px; animation: gm-chase 1.2s steps(2) infinite; }
@keyframes gm-chase { 50% { background-position: 7px 0; } }
.gm-sign small { display: block; font: 800 10px var(--ui); letter-spacing: .3em; color: #ffe9a6; text-align: center; margin-top: 2px; text-shadow: none; }
.gm-histbox { justify-self: end; padding: 8px 12px; display: grid; gap: 6px; min-width: 0; max-width: 100%; }
#hist { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; min-height: 16px; }
.gm-roll { display: flex; gap: 2px; padding: 3px; border-radius: 6px; background: rgba(255, 255, 255, .06); }
.gm-roll i, .gm-chip i { display: block; width: 10px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); }
.gm-empty { font-size: 12px; color: var(--g-muted); }
.gm-h { font: 800 12px var(--display); padding: 3px 7px; border-radius: 6px; background: rgba(255, 255, 255, .06); }
.gm-h small { font: 600 10px var(--ui); color: var(--g-muted); margin: 0 3px; }
.gm-h.win { box-shadow: inset 0 0 0 1px var(--g-win); color: var(--g-win); }
.gm-h.lose { box-shadow: inset 0 0 0 1px var(--g-lose); color: var(--g-lose); }
.gm-h.push { box-shadow: inset 0 0 0 1px var(--g-push); color: var(--g-push); }

.gm-middle { flex: 1; display: grid; place-items: start center; padding-top: 14px; pointer-events: none; }
.gm-middle > * { grid-area: 1 / 1; }
.gm-middle.mid { place-items: center; }
.gm-banner { background: var(--g-panel); border: 1px solid var(--g-line); border-radius: 16px; padding: 14px 20px; text-align: center; display: grid; gap: 10px; backdrop-filter: blur(8px); animation: gm-pop .35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes gm-pop { from { transform: scale(.85); opacity: 0; } }
.gm-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.gm-chip { display: flex; align-items: center; gap: 6px; font: 800 13px var(--ui); letter-spacing: .08em; text-transform: uppercase; padding: 6px 10px; border-radius: 8px; background: rgba(255, 255, 255, .07); }
.gm-chip i { width: 14px; height: 14px; }
#outcome { font: 800 22px var(--display); }
#outcome.win { color: var(--g-win); }
#outcome.lose { color: var(--g-lose); } #outcome.push { color: var(--g-push); }
.gm-hand { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-weight: 800; }
.gm-cards { font-weight: 600; color: var(--g-muted); letter-spacing: .04em; }
.gm-hand .gm-num { font-size: 18px; min-width: 22px; }
.gm-toast { justify-self: center; align-self: start; margin-top: 10px; max-width: 92%; background: var(--g-sign); color: var(--g-ink); font-weight: 600; padding: 8px 14px; border-radius: 10px; box-shadow: 0 0 0 2px var(--g-marquee); text-align: center; }

.gm-foot { display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.gm-barbox { pointer-events: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; padding: 10px; max-width: 100%; }
.gm-pickers { display: flex; gap: 8px; }
.gm-pick { width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer; font: 800 12px var(--display); color: #2b2d33; position: relative; background: radial-gradient(circle at 35% 30%, #ffffff, #c9ccd3 45%, #8d929c 75%, #c4c8cf); box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .12), inset 0 0 0 6px rgba(255, 255, 255, .35), 0 3px 0 #5d6068, 0 6px 12px rgba(0, 0, 0, .4); transition: transform .12s; }
.gm-pick.big { background: radial-gradient(circle at 50% 50%, #e3e6ea 0 42%, #8d929c 44%, transparent 46%), radial-gradient(circle at 35% 30%, #fff0b5, #d9ae3e 50%, #9a7420 80%, #d6ad45); }
.gm-pick:hover { transform: translateY(-2px); }
.gm-pick[aria-checked="true"] { transform: translateY(-5px); box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .12), 0 0 0 3px var(--g-marquee), 0 8px 0 -2px #5d6068, 0 12px 18px rgba(0, 0, 0, .5); }
.gm-betbox { display: grid; gap: 2px; min-width: 60px; }
#bet { font-size: 20px; }
.gm-actions { display: flex; gap: 8px; }
.gm-btn { font: 800 13px var(--ui); letter-spacing: .04em; padding: 10px 12px; border-radius: 11px; cursor: pointer; border: 1px solid var(--g-line); background: rgba(255, 255, 255, .07); color: var(--g-ink); }
.gm-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.gm-btn:disabled { opacity: .4; cursor: not-allowed; }
.gm-btn.primary { font: 800 15px var(--display); padding: 10px 16px; background: var(--g-marquee); color: #3a1a05; border: 0; box-shadow: 0 4px 0 #a5790c, 0 0 24px rgba(255, 210, 63, .35); }
.gm-btn.primary:hover:not(:disabled) { background: #ffe066; }
.gm-btn.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #a5790c; }
.gm-stage button:focus-visible, .gm-stage a:focus-visible { outline: 3px solid #8fd3ff; outline-offset: 3px; }
.gm-stage kbd { font: 600 11px var(--ui); border: 1px solid var(--g-line); border-radius: 4px; padding: 0 4px; }
.gm-pointer { position: absolute; transform: translate(calc(-100% - 26px), -50%); pointer-events: none; white-space: nowrap; background: var(--g-marquee); color: #3a1a05; font: 800 12px var(--ui); letter-spacing: .04em; padding: 6px 10px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .45); }
.gm-pointer::after { content: ""; position: absolute; right: -6px; top: 50%; translate: 0 -50%; border: 6px solid transparent; border-right: 0; border-left-color: var(--g-marquee); }

/* score tags that follow each hand on the table (Lucky 9) */
.gm-badge { position: absolute; transform: translate(-50%, -50%); pointer-events: none; display: flex; align-items: center; gap: 5px; white-space: nowrap; background: var(--g-panel); border: 1px solid var(--g-line); border-radius: 10px; padding: 3px 4px 3px 6px; font: 800 9px var(--ui); letter-spacing: .1em; text-transform: uppercase; }
.gm-badge .gm-st { color: var(--g-marquee); letter-spacing: .04em; }
.gm-badge .gm-sc { min-width: 20px; height: 20px; padding: 0 4px; box-sizing: border-box; display: grid; place-items: center; border-radius: 7px; background: rgba(255, 255, 255, .09); font: 800 12px var(--display); letter-spacing: 0; }
.gm-badge .gm-sc:empty { display: none; }
.gm-badge.win .gm-sc { background: var(--g-win); color: #062b14; }
.gm-badge.lose .gm-sc { background: var(--g-lose); color: #3a0a05; }
.gm-badge.push .gm-sc { background: var(--g-push); color: #06243a; }
#badges { position: absolute; inset: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) { .gm-sign::after, .gm-banner { animation: none; } }

/* ---------- tablet and wider ---------- */
@media (min-width: 640px) {
  .gm-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gm-card { min-height: 190px; }
  .gm-side { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}
@media (min-width: 1100px) {
  .gm-lay { grid-template-columns: minmax(0, 1fr) 320px; }
  .gm-side { grid-template-columns: minmax(0, 1fr); }
}
/* the stage reads its own width, not the window's: the sidebar takes 250px of a wide window */
@container (min-width: 700px) {
  .gm-top { grid-template-columns: 1fr auto 1fr; }
  .gm-sign { display: block; }
  .gm-hud { padding: 12px 16px; }
  #bal { font-size: 26px; }
  .gm-barbox { gap: 14px 22px; padding: 12px 16px; }
  .gm-pick { width: 50px; height: 50px; font-size: 14px; }
  .gm-btn { padding: 12px 16px; font-size: 14px; }
  .gm-btn.primary { font-size: 18px; padding: 11px 22px; }
  .gm-badge { font-size: 11px; gap: 8px; padding: 3px 4px 3px 10px; }
  .gm-badge .gm-sc { min-width: 24px; height: 24px; font-size: 15px; }
}

/* ---------- phone and tablet: the table first, big touch targets ----------
   Everything here sits inside one media query, so a wide screen draws exactly as before. */
@media (max-width: 1024px) {
  .gm-stage { height: max(540px, calc(100svh - 128px)); scroll-margin-top: 64px; }
  .gm-sign, .gm-help kbd { display: none !important; }
  .gm-hud { padding: 6px 8px; }
  .gm-top, .gm-stage .gm-top { grid-template-columns: auto minmax(0, 1fr); gap: 8px; }
  .gm-wallet { padding: 4px 8px; }
  .gm-wallet .gm-lbl, .gm-histbox .gm-lbl { display: none; }
  .gm-wallet .row { gap: 8px; }
  #bal { font-size: 22px; }
  .gm-back { min-height: 36px; display: inline-flex; align-items: center; }
  .gm-histbox { padding: 6px 8px; }
  #hist { flex-wrap: nowrap; overflow: hidden; }
  #hist > :nth-child(n + 5) { display: none; }
  .gm-h { font-size: 13px; padding: 4px 8px; }
  .gm-roll i { width: 12px; height: 12px; }
  .gm-barbox { display: grid; grid-template-columns: minmax(0, 1fr) auto; width: 100%; max-width: 560px; gap: 6px 10px; padding: 6px 8px; }
  .gm-pickers { justify-content: space-between; }
  .gm-pick, .gm-pick.big { width: 48px; height: 48px; font-size: 14px; }
  .gm-pick[aria-checked="true"] { transform: translateY(-3px); }
  .gm-betbox { min-width: 44px; text-align: right; }
  .gm-barbox > .gm-actions { grid-column: 1 / -1; }
  .gm-barbox > .gm-actions[hidden] { display: none; }
  .gm-actions .gm-btn { flex: 1; min-height: 48px; font-size: 15px; padding: 10px 6px; white-space: nowrap; }
  .gm-btn.primary { flex: 1.4; font-size: 17px; }
  .gm-middle.mid { place-items: end center; padding-bottom: 6px; }
  .gm-banner { padding: 8px 14px; gap: 4px; }
  .gm-banner .gm-lbl, #hands { display: none; }
  #outcome { font-size: 20px; }
  .gm-chip { font-size: 15px; padding: 6px 10px; }
  .gm-chip i { width: 16px; height: 16px; }
  .gm-toast { align-self: end; margin: 0 0 6px; font-size: 14px; }
  .gm-badge.gm-off { display: none; }
  .gm-badge { font-size: 11px; padding: 3px 6px; }
  .gm-badge .gm-sc { min-width: 24px; height: 24px; font-size: 15px; }
  .gm-pointer { font-size: 13px; }
}
@media (max-width: 1024px) {
  /* Color Game: the roll result sits where the tray meets the board */
  #stage[data-roll] .gm-middle { place-items: end center; padding: 0 0 4px; }
  #stage[data-roll] .gm-banner { padding: 6px 10px; }
  #stage[data-roll] .gm-chips { gap: 5px; flex-wrap: nowrap; }
  #stage[data-roll] .gm-chip { font-size: 12.5px; letter-spacing: .03em; padding: 5px 7px; gap: 5px; }
}
