:root {
  color-scheme: dark;
  --bg: #111512;
  --surface: #1a201b;
  --surface-2: #242b25;
  --line: #38423a;
  --text: #f3f5f3;
  --muted: #aab3ac;
  --green: #42c66d;
  --green-dark: #173e25;
  --red: #f05c63;
  --red-dark: #4b1f23;
  --orange: #ef9f3d;
  --orange-dark: #4b3318;
  --blue: #61a7e8;
  --blue-dark: #193851;
  --gold: #e5c269;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overscroll-behavior: none;
}
button { font: inherit; letter-spacing: 0; }
.app-shell { min-height: 100dvh; padding: calc(10px + var(--safe-top)) 14px calc(118px + var(--safe-bottom)); }

.topbar { height: 48px; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid #56715c;
  border-radius: 7px; color: var(--gold); background: #0b0f0c; font-family: Georgia, serif; font-size: 21px; font-weight: 700;
}
.brand-copy { min-width: 0; display: grid; gap: 1px; flex: 1; }
.brand-copy strong { font-size: 16px; }
.brand-copy span { color: var(--muted); font-size: 11px; }
.icon-button {
  width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 7px;
  display: grid; place-items: center; background: var(--surface); color: var(--text);
}
.icon-button svg { width: 19px; height: 19px; }

.session-strip {
  margin-top: 8px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 7px; overflow: hidden;
}
.session-strip > div { padding: 8px 10px; display: grid; gap: 3px; background: var(--surface); }
.session-strip > div + div { border-left: 1px solid var(--line); }
.session-strip span { color: var(--muted); font-size: 10px; }
.session-strip strong { font-size: 14px; }
.session-strip .timer strong { color: var(--gold); font-variant-numeric: tabular-nums; }

.stage-track { margin: 12px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.stage { min-width: 0; display: flex; align-items: center; gap: 5px; color: #778078; font-size: 10px; }
.stage b { width: 20px; height: 20px; border-radius: 50%; border: 1px solid #515b52; display: grid; place-items: center; font-size: 10px; }
.stage span { overflow: hidden; text-overflow: ellipsis; }
.stage.is-active { color: var(--text); }
.stage.is-active b { border-color: var(--gold); color: #17140d; background: var(--gold); }
.stage.is-done { color: var(--green); }
.stage.is-done b { border-color: var(--green); color: var(--green); }

.market-board { border-top: 1px solid var(--line); padding-top: 14px; }
.board-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.eyebrow { color: var(--gold); font-size: 9px; font-weight: 700; }
h1, h2 { margin: 3px 0 0; letter-spacing: 0; }
h1 { font-size: 22px; line-height: 1.08; }
h2 { font-size: 17px; }
.status-pill { flex: none; padding: 5px 7px; border-radius: 6px; background: #253228; color: #b8d9c0; font-size: 10px; }
.phase-hint { margin: 8px 0 11px; color: var(--muted); font-size: 12px; line-height: 1.4; }

.players-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 11px; }
.player { flex: 1; min-width: 0; height: 42px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; display: grid; grid-template-columns: 28px 1fr; grid-template-rows: 1fr 1fr; column-gap: 7px; background: var(--surface); }
.player > span { grid-row: 1 / 3; width: 28px; height: 28px; align-self: center; border-radius: 50%; display: grid; place-items: center; background: #343c35; font-size: 9px; }
.player strong { align-self: end; font-size: 11px; }
.player small { color: var(--muted); font-size: 9px; }
.player.is-you { border-color: #57745e; }

.price-zone { min-height: 154px; display: flex; flex-direction: row-reverse; align-items: center; justify-content: center; gap: 12px; }
.played-card-slot { flex: 0 0 104px; min-height: 142px; padding: 7px; border: 1px dashed #667168; border-radius: 8px; background: #151b16; text-align: center; }
.played-card-slot > span { display: block; color: var(--gold); font-size: 8px; font-weight: 800; letter-spacing: .04em; }
.played-card { min-height: 112px; margin-top: 5px; padding: 8px 5px; border: 2px solid var(--card-accent); border-radius: 7px; background: var(--card-bg); color: var(--card-ink); display: grid; align-content: center; gap: 6px; }
.played-card strong { display: block; font-size: 18px; }
.played-card small { display: block; font-size: 9px; line-height: 1.2; font-weight: 700; }
.price-card { position: relative; width: 124px; height: 154px; transform-style: preserve-3d; transition: transform .55s ease; }
.price-card.is-revealed { transform: rotateY(180deg); }
.price-back, .price-front { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 8px; overflow: hidden; }
.price-back { border: 1px solid #536259; background: #1c231e; display: grid; place-items: center; align-content: center; gap: 7px; text-align: center; }
.price-back svg { width: 38px; height: 38px; color: var(--gold); }
.price-back strong { font-size: 17px; }
.price-back span { color: var(--muted); font-size: 9px; }
.price-front { padding: 8px; transform: rotateY(180deg); background: #ef5b62; color: #25090b; border: 3px solid #ff8c91; display: grid; grid-template-rows: auto auto 1fr auto; text-align: center; }
.price-card.is-long .price-front { background: #71cf84; color: #0b2613; border-color: #42af62; }
.price-card.is-short .price-front { background: #ef5b62; color: #25090b; border-color: #ff8c91; }
.price-front > span { font-size: 7px; font-weight: 700; }
.price-front > strong { font-size: 22px; }
.price-front img { width: 74px; height: 74px; margin: auto; }
.price-front small { font-size: 7px; }

.result-panel { width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); text-align: center; }
.result-label { color: var(--muted); font-size: 9px; }
.result-panel > strong { display: block; margin-top: 4px; color: var(--red); font-size: 42px; line-height: 1; }
.result-panel.is-protected > strong { color: var(--green); }
.result-panel p { margin: 7px 0 12px; color: var(--muted); font-size: 12px; }
.final-stats { color: var(--muted); font-size: 12px; line-height: 1.4; }
.final-summary { margin-top: 14px; display: grid; gap: 10px; }
.final-summary-head { padding: 12px; border: 1px solid var(--gold); border-radius: 8px; background: #201d12; }
.final-summary-head span { color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .06em; }
.final-summary-head strong { display: block; margin-top: 4px; font-size: 18px; }
.final-player-summary { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.final-player-summary.is-you { border-color: var(--gold); }
.final-player-summary h3 { margin: 0; font-size: 15px; }
.final-player-summary b { color: var(--gold); font-size: 22px; }
.final-player-summary p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.final-history { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.final-history summary { padding: 12px; cursor: pointer; font-size: 13px; font-weight: 800; }
.final-history-list { display: grid; gap: 8px; padding: 0 12px 12px; }
.final-history-round { padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.4; }
.final-history-round strong { color: var(--text); }
.score-change { height: 34px; display: flex; align-items: center; justify-content: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 11px; }
.score-change svg { width: 16px; }

.hand-section { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.section-heading > span { color: var(--muted); font-size: 10px; padding-top: 4px; }
.card-rail { margin: 10px -14px 0; padding: 0 14px 7px; display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.card-rail::-webkit-scrollbar { display: none; }
.game-card { position: relative; flex: 0 0 128px; height: 164px; padding: 10px; border: 2px solid var(--card-accent); border-radius: 8px; background: var(--card-bg); color: var(--card-ink); scroll-snap-align: start; display: grid; grid-template-rows: auto 1fr auto; text-align: left; transition: transform .16s ease, box-shadow .16s ease; }
.game-card:disabled { opacity: .4; }
.game-card.is-selected { transform: translateY(-4px); box-shadow: 0 0 0 2px #f3f5f3, 0 8px 20px rgba(0,0,0,.32); }
.game-card .card-kind { font-size: 9px; font-weight: 700; opacity: .75; }
.game-card .card-main { display: grid; place-items: center; align-content: center; gap: 2px; text-align: center; }
.game-card .card-main strong { font-size: 22px; line-height: 1; }
.game-card .card-main img { width: 58px; height: 58px; }
.game-card .card-main i { width: 45px; height: 45px; display: grid; place-items: center; }
.game-card .card-main i svg { width: 38px; height: 38px; }
.game-card small { font-size: 10px; line-height: 1.2; font-weight: 600; }
.game-card.contract-buy { --card-accent: #42af62; --card-bg: #71cf84; --card-ink: #0b2613; }
.game-card.contract-sell { --card-accent: #e0444c; --card-bg: #f06b70; --card-ink: #30090c; }
.game-card.instrument-protect { --card-accent: #48aa68; --card-bg: #dcefe1; --card-ink: #17331f; }
.game-card.instrument-risk { --card-accent: #ef9f3d; --card-bg: #f1dfc4; --card-ink: #3c2810; }
.game-card.event { --card-accent: #4b92d0; --card-bg: #dbeaf7; --card-ink: #15324c; }

.action-dock { position: fixed; left: 0; right: 0; bottom: 0; min-height: calc(92px + var(--safe-bottom)); padding: 11px 14px calc(11px + var(--safe-bottom)); border-top: 1px solid var(--line); background: rgba(17,21,18,.97); display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; z-index: 10; }
.selection-copy { min-width: 0; display: grid; gap: 3px; }
.selection-copy span { color: var(--muted); font-size: 9px; }
.selection-copy strong { font-size: 12px; line-height: 1.2; }
.primary-button { min-width: 150px; height: 46px; border: 0; border-radius: 7px; background: var(--gold); color: #211b0d; font-weight: 800; font-size: 13px; }
.primary-button:disabled { background: #373d38; color: #788078; }

.rules-dialog { width: min(340px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface); color: var(--text); }
.rules-dialog::backdrop { background: rgba(0,0,0,.72); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rules-dialog p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.dialog-action { width: 100%; min-height: 44px; margin-top: 8px; border: 0; border-radius: 7px; background: var(--gold); color: #211b0d; font-weight: 800; }
.result-card { flex: 0 0 128px; height: 112px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); display: grid; align-content: space-between; scroll-snap-align: start; }
.result-card.is-you { border-color: var(--gold); }
.result-card strong { font-size: 11px; }
.result-card span { color: var(--muted); font-size: 11px; }
.result-card b { font-size: 24px; }

@media (min-width: 700px) {
  .app-shell { width: 430px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .action-dock { width: 430px; left: 50%; right: auto; transform: translateX(-50%); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

@media (max-height: 720px) {
  .price-zone { min-height: 128px; }
  .played-card-slot { flex-basis: 92px; min-height: 120px; }
  .price-card { width: 102px; height: 128px; }
  .price-front img { width: 56px; height: 56px; }
  .game-card { height: 132px; }
}
