/*
 * River — main.css
 * Shell shares the studio visual system (Frame/Drift lineage): brand tokens,
 * masthead, stage chrome, chips, bankroll, action buttons, info sheet, toast.
 * River-specific stage: two symmetric duel panels (dealer / your hand) with
 * the river card on the printed felt midline between them — Concept A.
 * Phone-first, NO SCROLLING.
 */

:root {
  --bg: #0A0A0B;
  --surface: #131316;
  --elevated: #1C1C20;
  --text-primary: #EDEDF0;
  --text-secondary: #A1A1AA;
  --text-tertiary: #71717A;
  --accent: #10B981;
  --accent-bright: #34D399;
  --accent-dim: #047857;
  --border-subtle: #27272A;
  --border-strong: #3F3F46;
  --warning: #F59E0B;
  --danger: #EF4444;

  /* canonical card (v3) */
  --card-bg: #FFFFFF;
  --card-red: #C4444D;
  --card-black: #0E0E12;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: #1A1A1F;
  min-height: 100dvh;
  font-family: 'Geist', sans-serif;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* ─────── App frame ─────── */
.app {
  width: min(414px, 100vw);
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
  touch-action: manipulation;
}

/* Desktop: render as a centered phone frame */
@media (min-width: 460px) {
  body { padding: 24px 0; align-items: center; }
  .app {
    height: min(860px, calc(100dvh - 48px));
    border-radius: 24px;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 30px 80px -10px rgba(0,0,0,0.7);
  }
}

.app::before {
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 100% 30% at 50% -5%, rgba(16,185,129,0.10), transparent),
    radial-gradient(ellipse 80% 25% at 50% 105%, rgba(245,158,11,0.04), transparent);
  pointer-events: none;
  z-index: 0;
}
.app::after {
  content: '';
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.9' /%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: overlay;
}
.app > * { position: relative; z-index: 2; }

/* ─────── Masthead ─────── */
.masthead {
  flex-shrink: 0;
  padding: calc(16px + env(safe-area-inset-top)) 18px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}
.wordmark {
  font-family: 'Geist', sans-serif;
  font-weight: 500;
  font-size: 19px;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 1;
}
.wordmark .chevron { color: var(--accent); font-weight: 600; }
.game-title {
  font-family: 'Fraunces', serif;
  font-weight: 500; font-style: italic;
  font-size: 20px;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.01em;
}
.mast-right { display: flex; align-items: center; gap: 12px; }
.info-btn {
  background: transparent; border: none; padding: 4px; cursor: pointer;
  color: var(--text-tertiary);
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  transition: color 0.15s, background 0.15s, transform 0.1s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.info-btn:hover { color: var(--accent); background: rgba(16,185,129,0.08); }
.info-btn:active { transform: scale(0.94); }

/* ─────── Stage ─────── */
.stage-wrap {
  flex: 1;
  padding: 14px;
  display: flex;
  align-items: stretch;
  min-height: 0; min-width: 0;
}
.stage {
  flex: 1; min-width: 0;
  position: relative;
  /* size container: card dimensions key off the stage's real height (cqh),
     so the cards grow on tall screens and shrink on short ones — never
     scroll, never overlap */
  container-type: size;
  padding: 12px 12px 0; /* no bottom padding: the readout carries its own margin */
  background: linear-gradient(180deg, var(--surface) 0%, #0F0F11 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow:
    0 0 0 1px rgba(16,185,129,0.04),
    0 14px 28px -10px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.02);
}

/* ─────── Duel panels (Concept A, side-label revision — JH 2026-06-11) ───────
   The eyebrow reads vertically at the panel's left middle, so the cards own
   the full panel height; the fan stays optically centered in the panel. */
.duel-panel {
  flex-shrink: 0;
  position: relative;
  display: flex; align-items: center;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(255,255,255,0.02);
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
}
.panel-label {
  position: absolute; left: 9px; top: 50%;
  /* reads bottom-to-top (D at the bottom), letter tops along the border —
     vertical-rl turned 180° (JH, 2026-06-11) */
  writing-mode: vertical-rl;
  transform: translateY(-50%) rotate(180deg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.22em;
  color: var(--text-tertiary); line-height: 1; font-weight: 500;
  white-space: nowrap;
}
.duel-panel.live {
  border-color: rgba(16,185,129,0.45);
  background: rgba(16,185,129,0.05);
  box-shadow: 0 0 16px -6px rgba(16,185,129,0.35), inset 0 0 0 1px rgba(16,185,129,0.18);
}
.duel-panel.live .panel-label { color: var(--accent); }
.duel-panel.won {
  border-color: var(--accent);
  background: rgba(16,185,129,0.08);
  animation: panel-won 0.8s ease;
  box-shadow: inset 0 0 0 1px rgba(16,185,129,0.5), 0 0 18px -4px rgba(16,185,129,0.45);
}
@keyframes panel-won {
  0% { box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 0 rgba(16,185,129,0.6); }
  50% { box-shadow: inset 0 0 0 1px var(--accent-bright), 0 0 26px 6px rgba(16,185,129,0.6); }
  100% { box-shadow: inset 0 0 0 1px rgba(16,185,129,0.5), 0 0 18px -4px rgba(16,185,129,0.45); }
}
.duel-panel.won .panel-label { color: var(--accent); }
.duel-panel.lost {
  border-color: rgba(239,68,68,0.6);
  background: rgba(239,68,68,0.05);
  box-shadow: inset 0 0 0 1px rgba(239,68,68,0.3);
}
.duel-panel.lost .panel-label { color: var(--danger); }
.duel-panel.push { border-color: var(--border-strong); }
.duel-panel.washed, .midline.washed { opacity: 0.45; }

.fan { flex: 1; display: flex; justify-content: center; gap: 10px; }

/* ─────── Cards (Frame card architecture) ─────── */
/* The felt is never bare (JH): resting cards sit face-down in every seat;
   the deal flips them. No empty-slot state exists on this table.
   EVERY card is the same size — river included (JH: like a casino, cards
   are the same). Sized off the stage's height: three card rows + panel
   chrome + the rule line + the readout must fit with no scroll, so
   width ≈ (stage-height − fixed chrome) / (3 rows × 7/5 aspect). */
.card {
  /* fallback for browsers without container-query units */
  --card-w: clamp(58px, min(17vw, 9.6dvh), 78px);
  /* the real sizing: three equal card rows + chrome fit the stage exactly */
  --card-w: clamp(48px, min(23cqh - 29px, 50vw - 49px), 110px);
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  border-radius: 7px;
  position: relative;
  flex-shrink: 0;
  perspective: 700px;
  box-shadow: 0 3px 8px -1px rgba(0,0,0,0.5);
}
/* below ~330px of stage the printed rule yields its line to the river —
   the ⓘ table carries the economics on screens this short */
@container (max-height: 330px) {
  .felt-rule { display: none; }
}
.card-flip {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}
/* the river turns with ceremony — it decides everything (Drift's stately flip) */
.card.river .card-flip { transition-duration: 0.85s; }
.card.revealed .card-flip { transform: rotateY(180deg); }
.card-back, .card-face {
  position: absolute; inset: 0;
  border-radius: inherit;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-back { background: #0A0A0B; }
.card-back-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.card-back-mark {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Geist', sans-serif; font-weight: 600;
  font-size: calc(var(--card-w) * 0.125);
  color: var(--accent); letter-spacing: -0.02em; line-height: 1;
  user-select: none; pointer-events: none;
}
.card-back-mark .chevron { font-weight: 700; }
.card-face {
  background: var(--card-bg);
  transform: rotateY(180deg);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.card-corner {
  position: absolute; top: 5%; left: 7%;
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 0.82;
}
.card-rank {
  font-family: 'Geist', sans-serif;
  font-weight: 900;
  font-size: calc(var(--card-w) * 0.375);
  line-height: 0.85;
  letter-spacing: -0.06em;
}
.card-rank.tens { font-size: calc(var(--card-w) * 0.30); letter-spacing: -0.09em; }
.card-corner-suit { width: calc(var(--card-w) * 0.27); height: calc(var(--card-w) * 0.27); margin-top: 2%; display: block; }
.card-suit-large { position: absolute; bottom: 5%; right: 6%; width: calc(var(--card-w) * 0.55); height: calc(var(--card-w) * 0.55); }
.red { color: var(--card-red); }
.black { color: var(--card-black); }

/* ─────── The midline: the river on the printed felt rule ─────── */
.midline {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; justify-content: center;
  gap: 5px;
  transition: opacity 0.25s ease;
}
.band { display: flex; align-items: center; gap: 14px; padding: 0 4px; }
.band-line { flex: 1; border-top: 1px solid var(--border-subtle); }
.river-mount { display: flex; align-items: center; justify-content: center; }
.felt-rule {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8.5px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--text-tertiary); text-align: center; line-height: 1.5;
  white-space: nowrap; overflow: hidden;
}

/* ─────── Hand readout (Frame) ─────── */
.hand-readout {
  flex-shrink: 0;
  margin: 0 0 10px;
  width: 100%;
  padding: 11px 18px;
  background: linear-gradient(180deg, rgba(16,185,129,0.12) 0%, transparent 100%);
  border: 1px solid var(--accent);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  position: relative;
  transition: opacity 0.2s ease;
}
.hand-readout.idle { border-color: var(--border-subtle); background: rgba(255,255,255,0.02); }
.hand-readout::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.7;
}
.hand-readout.idle::before { opacity: 0.15; }
.hand-readout-name {
  font-family: 'Fraunces', serif;
  font-weight: 500; font-style: italic;
  font-size: 18px;
  color: var(--text-primary);
  line-height: 1.1; letter-spacing: -0.01em;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hand-readout.idle .hand-readout-name { color: var(--text-tertiary); }
.hand-readout-payout {
  font-family: 'Fraunces', serif;
  font-weight: 500; font-style: italic;
  font-size: 22px;
  color: var(--accent);
  line-height: 1.1; letter-spacing: -0.02em;
  flex-shrink: 0; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hand-readout-payout.loss { color: var(--text-tertiary); }

/* ─────── Bet zone (chips ↔ locked-stake display, swapped by phase) ─────── */
.bet-zone { flex-shrink: 0; padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.bet-col { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; min-height: 55px; justify-content: center; }
.bet-col.hidden { display: none; }
.zone-label {
  font-family: 'JetBrains Mono', monospace; font-size: 9px; text-transform: uppercase;
  letter-spacing: 0.18em; color: var(--accent); line-height: 1; font-weight: 500;
}
.stake-value {
  font-family: 'Fraunces', serif; font-weight: 500; font-style: italic;
  font-size: 26px; color: var(--text-primary); line-height: 1;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.chips-row { display: flex; gap: 6px; flex-shrink: 0; }
.chip {
  background: transparent; border: none; padding: 0; cursor: pointer;
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: transform 0.15s ease;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: scale(0.95); }
.chip:disabled { opacity: 0.35; cursor: not-allowed; }
.chip-face {
  width: 100%; height: 100%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; position: relative;
  box-shadow: 0 3px 7px -2px rgba(0,0,0,0.5), inset 0 -2px 4px rgba(0,0,0,0.25), inset 0 2px 4px rgba(255,255,255,0.18);
}
.chip-face.red { background: linear-gradient(180deg, #E0353E 0%, #B82C34 100%); }
.chip-face.green { background: linear-gradient(180deg, #10B981 0%, #047857 100%); }
.chip-face.black { background: linear-gradient(180deg, #2A2A30 0%, #0E0E12 100%); }
.chip-face.purple { background: linear-gradient(180deg, #9B6CF6 0%, #6D28D9 100%); }
.chip-face::before {
  content: ''; position: absolute; inset: 3px; border-radius: 50%;
  border: 1.5px dashed rgba(255,255,255,0.4); pointer-events: none;
}
.chip-value {
  font-family: 'Fraunces', serif; font-weight: 600; font-style: italic;
  font-size: 15px; color: #fff; line-height: 1; z-index: 1; letter-spacing: -0.02em;
}
.chip.active .chip-face {
  box-shadow:
    0 0 18px 0 rgba(16,185,129,0.7),
    0 3px 7px -2px rgba(0,0,0,0.5),
    inset 0 0 0 2px rgba(255,255,255,0.5),
    inset 0 -2px 4px rgba(0,0,0,0.25),
    inset 0 2px 4px rgba(255,255,255,0.18);
}
.bankroll-col { margin-left: auto; margin-right: 4px; width: 100px; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.bankroll-label {
  font-family: 'JetBrains Mono', monospace; font-size: 9px; text-transform: uppercase;
  letter-spacing: 0.18em; color: var(--accent); line-height: 1; font-weight: 500;
}
.bankroll-value {
  font-family: 'Fraunces', serif; font-weight: 500; font-style: italic;
  font-size: 26px; color: var(--text-primary); line-height: 1;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  padding-right: 4px;
}
.bankroll-value.compact, .stake-value.compact { font-size: 21px; }

/* ─────── Action zone ─────── */
.action-zone {
  flex-shrink: 0;
  padding: 18px 14px calc(28px + env(safe-area-inset-bottom));
  display: flex; gap: 10px;
}
.action-zone .hidden { display: none; }
.primary-action {
  flex: 1.15;
  background: var(--accent);
  color: var(--bg);
  border: 1px solid var(--accent);
  padding: 16px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  position: relative; overflow: hidden; line-height: 1;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.primary-action::before {
  content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  animation: btn-shimmer 3s infinite;
}
@keyframes btn-shimmer { 0% { left: -100%; } 100% { left: 100%; } }
.primary-action:not(.disabled):hover { background: var(--accent-bright); }
.primary-action:not(.disabled):active { transform: scale(0.98); }
.primary-action.disabled { opacity: 0.5; cursor: not-allowed; }
.primary-action.disabled::before { display: none; }
.action-verb {
  font-family: 'Geist', sans-serif; font-weight: 600; font-size: 15px;
  letter-spacing: 0.04em; color: var(--bg); z-index: 1; white-space: nowrap;
}
.action-amount {
  font-family: 'Fraunces', serif; font-style: italic; font-weight: 600;
  font-size: 17px; color: var(--bg); z-index: 1; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* FOLD — the give-it-up button: green outline, exact kept amount (Drift's HOLD recipe) */
.fold-action {
  flex: 1;
  background: rgba(16,185,129,0.07);
  border: 1px solid var(--accent);
  padding: 16px 10px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  line-height: 1;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.fold-action:hover { background: rgba(16,185,129,0.14); }
.fold-action:active { transform: scale(0.98); }
.fold-action.disabled { opacity: 0.5; cursor: not-allowed; }
.fold-action .action-verb { color: var(--accent-bright); }
.fold-action .action-amount { color: var(--accent-bright); font-size: 15px; }
.secondary-action {
  flex-shrink: 0; width: 100px;
  background: transparent; border: 1px solid var(--border-strong);
  color: var(--text-secondary); padding: 16px 0; border-radius: 6px; cursor: pointer;
  font-family: 'Geist', sans-serif; font-weight: 500; font-size: 14px;
  letter-spacing: 0.06em; transition: all 0.15s; line-height: 1;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.secondary-action:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.secondary-action:active { transform: scale(0.98); }

/* ─────── Toast ─────── */
.toast {
  position: absolute; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(8px);
  background: var(--elevated); color: var(--text-primary);
  border: 1px solid var(--accent);
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 8px 24px -6px rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 20; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─────── House rules sheet ─────── */
.sheet {
  position: absolute; inset: 0; z-index: 30;
  background: var(--bg);
  display: flex; flex-direction: column; gap: 20px; /* fits no-scroll at the 672px desktop frame and the ~740px phone class */
  padding: calc(14px + env(safe-area-inset-top)) 20px calc(10px + env(safe-area-inset-bottom));
  opacity: 0; visibility: hidden; transform: translateY(14px);
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.2,0.7,0.2,1), visibility 0.22s;
  overflow-y: auto;
}
.sheet.open { opacity: 1; visibility: visible; transform: translateY(0); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-title {
  font-family: 'Fraunces', serif; font-style: italic; font-weight: 600;
  font-size: 26px; color: var(--text-primary); letter-spacing: -0.01em;
}
.sheet-close {
  background: transparent; border: 1px solid var(--border-strong); color: var(--text-secondary);
  width: 36px; height: 36px; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.sheet-close:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.sheet-section { display: flex; flex-direction: column; gap: 7px; }
.sheet-eyebrow {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.18em; color: var(--accent);
}
.paytable { width: 100%; border-collapse: collapse; }
.paytable td { padding: 4px 0; border-bottom: 1px solid var(--border-subtle); }
.paytable tr:last-child td { border-bottom: none; }
.pt-name { font-family: 'Geist', sans-serif; font-size: 15px; color: var(--text-primary); }
.pt-mult {
  font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums;
  font-size: 13px; text-align: right; font-weight: 500; color: var(--text-secondary);
}
.pt-mult.win { color: var(--accent); }
.sheet-note { font-size: 12px; color: var(--text-tertiary); line-height: 1.45; }

.sheet-steps {
  margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 5px;
}
.sheet-steps li {
  font-size: 14px; line-height: 1.4; color: var(--text-secondary); padding-left: 4px;
}
.sheet-steps li::marker {
  font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent);
}
.sheet-steps strong, .sheet-facts strong, .sheet-note strong { color: var(--text-primary); font-weight: 600; }

.sheet-facts {
  margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px;
}
.sheet-facts li {
  font-size: 13px; line-height: 1.4; color: var(--text-secondary);
  padding-left: 16px; position: relative;
}
.sheet-facts li::before {
  content: ''; position: absolute; left: 2px; top: 0.5em;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .card-flip, .primary-action, .fold-action, .chip, .toast, .sheet,
  .duel-panel, .midline { transition: none; }
  .primary-action::before, .duel-panel.won { animation: none; }
}
