/* Card-room layout: the felt table is the hero of the page, review and coach sit beside it as a quiet column. */
:root {
  --bg: #eceee9;
  --surface: #fbfcfa;
  --surface-2: #f3f5f1;
  --ink: #1a1f1b;
  --muted: #59625b;
  --line: #d3d9d2;
  --felt: #1f5c45;
  --felt-deep: #174634;
  --felt-line: #2f7a5d;
  --rail: #2b2420;
  --brass: #b5832a;
  --brass-ink: #2b1d05;
  --card: #fffdf8;
  --card-line: #d9d4c8;
  --suit-s: #1a1f1b;
  --suit-h: #c23b2a;
  --suit-d: #2a64b0;
  --suit-c: #1f7a48;
  --best: #1d7f52;
  --best-bg: #e2f2e9;
  --ok: #3567a3;
  --ok-bg: #e4edf8;
  --warn: #9a6a07;
  --warn-bg: #fbf0d6;
  --bad: #b8361f;
  --bad-bg: #fbe4df;
  --focus: #2a64b0;

  --font-display: 'Bricolage Grotesque', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --radius: 10px;
  --gap: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111412;
    --surface: #191d1a;
    --surface-2: #20251f;
    --ink: #e7ebe6;
    --muted: #9aa49c;
    --line: #2d342e;
    --felt: #1b4d3a;
    --felt-deep: #133a2b;
    --felt-line: #2a6a51;
    --rail: #0b0d0c;
    --brass: #d6a446;
    --brass-ink: #241703;
    --card: #f4f1ea;
    --card-line: #c8c2b5;
    --best: #5cc492;
    --best-bg: #173527;
    --ok: #7fb0ea;
    --ok-bg: #1a2a3d;
    --warn: #e2b04a;
    --warn-bg: #3a2c0f;
    --bad: #f07f69;
    --bad-bg: #3d1d16;
    --focus: #7fb0ea;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111412;
  --surface: #191d1a;
  --surface-2: #20251f;
  --ink: #e7ebe6;
  --muted: #9aa49c;
  --line: #2d342e;
  --felt: #1b4d3a;
  --felt-deep: #133a2b;
  --felt-line: #2a6a51;
  --rail: #0b0d0c;
  --brass: #d6a446;
  --brass-ink: #241703;
  --card: #f4f1ea;
  --card-line: #c8c2b5;
  --best: #5cc492;
  --best-bg: #173527;
  --ok: #7fb0ea;
  --ok-bg: #1a2a3d;
  --warn: #e2b04a;
  --warn-bg: #3a2c0f;
  --bad: #f07f69;
  --bad-bg: #3d1d16;
  --focus: #7fb0ea;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-wrap: balance; margin: 0; }
code { font-family: var(--font-mono); font-size: 0.9em; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms, transform 80ms;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--brass); border-color: var(--brass); color: var(--brass-ink); }
.btn-primary:hover { border-color: var(--ink); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--felt); color: #f4f1ea; font-size: 18px;
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.stats { display: flex; gap: 18px; margin: 0 0 0 auto; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stats dd { margin: 0; font-family: var(--font-mono); font-size: 15px; font-variant-numeric: tabular-nums; }
.topbar-actions { display: flex; gap: 6px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  gap: var(--gap);
  padding-block: var(--gap);
  padding-inline: 16px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}
.play { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

/* Table */
.table-wrap { width: 100%; }
.table {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 68vh;
  margin: 0 auto;
}
.felt {
  position: absolute;
  inset: 13% 9% 15%;
  border-radius: 999px;
  background: radial-gradient(ellipse at 50% 40%, var(--felt-line) 0%, var(--felt) 45%, var(--felt-deep) 100%);
  border: 12px solid var(--rail);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06), 0 10px 30px rgba(0, 0, 0, 0.18);
  display: grid;
  place-items: center;
}
.center { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pot {
  font-family: var(--font-mono);
  font-size: 14px;
  color: #f4f1ea;
  background: rgba(0, 0, 0, 0.28);
  padding: 3px 12px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.board { display: flex; gap: 6px; min-height: 64px; }
.street-label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(244, 241, 234, 0.7); }

/* Cards */
.card {
  --w: 44px;
  width: var(--w);
  height: calc(var(--w) * 1.42);
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--card-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  user-select: none;
}
.card .rank { font-size: calc(var(--w) * 0.46); }
.card .suit { font-size: calc(var(--w) * 0.42); margin-top: 2px; }
.card.s { color: var(--suit-s); }
.card.h { color: var(--suit-h); }
.card.d { color: var(--suit-d); }
.card.c { color: var(--suit-c); }
.card.back {
  background: repeating-linear-gradient(45deg, #7a2b1f 0 4px, #8d3526 4px 8px);
  border: 2px solid #f4f1ea;
}
.card.deal { animation: deal 260ms ease-out both; }
@keyframes deal { from { transform: translateY(-8px) scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }

/* Seats */
.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 112px;
  z-index: 2;
}
.seat-cards { display: flex; gap: 3px; height: 46px; align-items: flex-end; }
.seat-cards .card { --w: 32px; }
.seat.is-hero .seat-cards { height: 64px; }
.seat.is-hero .seat-cards .card { --w: 46px; }
.seat-plate {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 6px;
  font-size: 12px;
  line-height: 1.35;
}
.seat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-pos {
  position: relative;
  z-index: 1;
  margin-bottom: -12px;
  padding: 1px 9px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--ink);
  color: var(--surface);
  border: 1px solid var(--surface);
}
.seat-pos.pos-blinds { background: var(--ok); color: #fff; }
.seat-pos.pos-btn { background: var(--brass); color: var(--brass-ink); }
.seat-plate { padding-top: 10px; }
.seat-tag { grid-column: 1 / -1; }
.seat-stack { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.seat-tag { font-size: 11px; color: var(--muted); }
.seat.is-hero .seat-plate { border-color: var(--brass); }
.seat.is-active .seat-plate { box-shadow: 0 0 0 2px var(--brass); }
.seat.is-folded > :not(.seat-pos) { opacity: 0.45; }
.seat.is-winner .seat-plate { border-color: var(--best); box-shadow: 0 0 0 2px var(--best); }
.seat-action {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translate(-50%, -100%);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--ink);
  color: var(--surface);
  border-radius: 999px;
  padding: 2px 8px;
  pointer-events: none;
}
.seat-grade {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 8px;
}
.bet-chip {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #f4f1ea;
  z-index: 1;
}
.bet-chip::before {
  content: '';
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--brass);
  border: 2px dashed #f4f1ea;
}
.dealer-btn {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 24px; height: 24px; border-radius: 50%;
  background: #f4f1ea; color: #1a1f1b;
  display: grid; place-items: center;
  font: 700 12px var(--font-display);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  z-index: 1;
}

/* Action bar */
.action-bar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 200ms, box-shadow 200ms;
}
.action-bar.flash-best { border-color: var(--best); box-shadow: 0 0 0 3px var(--best-bg); }
.action-bar.flash-ok { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.action-bar.flash-inaccuracy { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.action-bar.flash-mistake { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.action-status { font-size: 14px; color: var(--muted); min-height: 21px; }
.action-status strong { color: var(--ink); font-weight: 600; }
.action-row, .raise-row, .flow-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.act { min-width: 96px; font-size: 15px; }
.act-fold { color: var(--bad); }
.act-aggro { background: var(--felt); border-color: var(--felt); color: #f4f1ea; }
.act-aggro:hover { border-color: var(--ink); }
.act.is-recommended { box-shadow: 0 0 0 3px var(--best); }
.raise-label { font-size: 13px; color: var(--muted); }
.raise-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.raise-custom { display: flex; gap: 6px; }
.raise-custom input {
  width: 84px;
  font: inherit;
  font-family: var(--font-mono);
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}
.flow-row { justify-content: space-between; }
.flow-row .btn-primary { margin-left: auto; }

/* Side column */
.side {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 110px);
  position: sticky;
  top: 16px;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 8px;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brass); }
.panel { padding: 14px; overflow-y: auto; min-height: 0; flex: 1; }
.panel-heading { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-family: var(--font-body); font-weight: 600; margin: 18px 0 8px; }

/* Feedback card */
.feedback {
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.feedback p { margin: 0; }
.feedback-title { font-weight: 600; }
.feedback-text { color: var(--muted); font-size: 14px; }
.feedback.level-best { background: var(--best-bg); border-color: var(--best); }
.feedback.level-ok { background: var(--ok-bg); border-color: var(--ok); }
.feedback.level-inaccuracy { background: var(--warn-bg); border-color: var(--warn); }
.feedback.level-mistake { background: var(--bad-bg); border-color: var(--bad); }
.feedback.level-hint { background: var(--surface-2); border-color: var(--brass); border-style: dashed; }
.feedback .feedback-text { color: var(--ink); }
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 10px;
  width: fit-content;
}
.badge.level-best { background: var(--best); color: var(--surface); }
.badge.level-ok { background: var(--ok); color: var(--surface); }
.badge.level-inaccuracy { background: var(--warn); color: var(--surface); }
.badge.level-mistake { background: var(--bad); color: var(--surface); }
.badge.level-hint { background: var(--brass); color: var(--brass-ink); }
.facts { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.facts li { margin: 2px 0; }
.feedback-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.feedback-actions .btn { min-height: 34px; padding: 4px 12px; font-size: 13px; }

/* Journal */
.journal { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.journal li button {
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 0;
  padding: 6px 10px;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: baseline;
}
.journal li button.level-best { border-left-color: var(--best); }
.journal li button.level-ok { border-left-color: var(--ok); }
.journal li button.level-inaccuracy { border-left-color: var(--warn); }
.journal li button.level-mistake { border-left-color: var(--bad); }
.journal .j-hand { font-family: var(--font-mono); color: var(--muted); }
.journal .j-level { font-size: 12px; color: var(--muted); }
.journal-empty { color: var(--muted); font-size: 13px; }

/* History */
.history { display: flex; flex-direction: column; gap: 12px; font-size: 14px; }
.history h4 { margin: 0 0 4px; font-family: var(--font-body); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.history ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.history li.is-hero { font-weight: 600; }
.history .mini-cards { display: inline-flex; gap: 3px; }
.history .mini-cards .card { --w: 22px; box-shadow: none; }
.result-box { border-top: 1px solid var(--line); padding-top: 10px; }

/* Coach chat */
.panel-coach { display: flex; flex-direction: column; padding: 0; }
.coach { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.coach-off { padding: 14px; }
.chat { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 240px; }
.chat-msg { border-radius: 12px; padding: 10px 12px; font-size: 14px; max-width: 92%; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 6px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ul, .chat-msg ol { margin: 4px 0; padding-left: 20px; }
.chat-user { background: var(--felt); color: #f4f1ea; align-self: flex-end; }
.chat-assistant { background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; }
.chat-msg.is-pending { color: var(--muted); }
.chat-msg .chat-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.chat-suggestions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 14px 8px; }
.chip {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--muted); }
.chat-form { border-top: 1px solid var(--line); padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.chat-form textarea {
  font: inherit;
  resize: vertical;
  min-height: 52px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}
.chat-form-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-form-row .btn-primary { margin-left: auto; }
.chat-error { color: var(--bad); font-size: 13px; }
.speed-slider { width: 100%; accent-color: var(--felt); }
.speed-scale { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.speed-scale output { color: var(--ink); font-variant-numeric: tabular-nums; }
.check, .radio { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.radio-hint { align-items: flex-start; line-height: 1.4; }
.radio-hint input { margin-top: 3px; }
.check { font-size: 13px; color: var(--muted); }

/* Dialogs */
.sheet {
  width: min(880px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
}
.sheet-narrow { width: min(520px, calc(100vw - 32px)); }
.sheet::backdrop { background: rgba(10, 14, 11, 0.55); }
.sheet[open] { display: flex; flex-direction: column; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 22px; }
.sheet-body { padding: 16px 18px 22px; overflow-y: auto; }
.help-nav { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 18px 0; }
.help-nav .chip[aria-current="true"], .range-controls .chip[aria-current="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.help-section h3 { font-size: 20px; margin-bottom: 10px; }
.help-section p, .help-section li { max-width: 68ch; }
.help-section table { border-collapse: collapse; width: 100%; font-size: 14px; }
.help-section th, .help-section td { text-align: left; border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.help-section th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.table-scroll { overflow-x: auto; }
.help-cards { display: inline-flex; gap: 3px; }
.help-cards .card { --w: 26px; box-shadow: none; }
.range-controls { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.range-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 2px;
  max-width: 560px;
}
.range-cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--muted);
}
.range-cell.on { background: var(--felt); color: #f4f1ea; }
.range-cell.hero { outline: 3px solid var(--brass); outline-offset: -2px; font-weight: 700; color: var(--ink); }
.range-cell.hero.on { color: #f4f1ea; }
.range-meta { font-size: 14px; color: var(--muted); margin: 8px 0 0; }
.settings fieldset { border: 0; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 6px; }
.settings legend { font-weight: 600; margin-bottom: 6px; }
.settings select, .settings input[type="password"] {
  font: inherit; padding: 8px 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
}
.settings .check { color: var(--ink); font-size: 14px; }
.settings-foot { display: flex; justify-content: flex-end; }

/* Responsive */
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; max-height: none; }
  .chat { max-height: 60vh; }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .stats { order: 3; width: 100%; margin: 0; justify-content: space-between; }
  .topbar-actions { margin-left: auto; }
  .table { aspect-ratio: 3 / 4; max-height: none; }
  .felt { inset: 14% 12% 16%; border-width: 8px; }
  .seat { width: 82px; }
  .seat-plate { padding: 9px 6px 3px; font-size: 11px; grid-template-columns: 1fr; }
  .seat-pos { font-size: 12px; padding: 0 7px; }
  .seat-tag { display: none; }
  .seat-cards { height: 36px; }
  .seat-cards .card { --w: 24px; }
  .seat.is-hero .seat-cards { height: 52px; }
  .seat.is-hero .seat-cards .card { --w: 38px; }
  .board .card { --w: 34px; }
  .act { min-width: 0; flex: 1; }
  .raise-presets { width: 100%; }
  .raise-presets .act { flex: 1 1 auto; min-width: 72px; white-space: nowrap; padding-inline: 10px; font-size: 14px; }
  .raise-custom { width: 100%; }
  .raise-custom input { flex: 1; }
}

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