:root {
  --bg: #10151c;
  --panel: #1a222d;
  --border: #2a3542;
  --text: #e6ebf0;
  --muted: #8a97a6;
  --felt: #1d5c3a;
  --raise: #d9534f;
  --call: #3c8de0;
  --fold: #3a4552;
  --play: #3fa66b;
  --defend: #8a63d2;
  --ok: #3fb97a;
  --bad: #e06464;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
header { display: flex; align-items: baseline; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); }
h1 { margin: 0; font-size: 20px; white-space: nowrap; }
h2 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.sub, .muted, small { color: var(--muted); }
kbd {
  font: 11px ui-monospace, monospace;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

main {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 520px);
  grid-template-areas:
    "controls controls"
    "table chart"
    "stats chart"
    "weak chart";
  gap: 16px;
  padding: 16px 24px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; grid-template-areas: "controls" "table" "stats" "chart" "weak"; }
}
main > section { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }

.controls { grid-area: controls; display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
.controls label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.set-notes { flex-basis: 100%; margin: 0; font-size: 13px; color: var(--muted); }
.set-notes a { color: var(--text); }
.controls .divider { width: 1px; align-self: stretch; background: var(--border); }
.controls select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  max-width: 100%;
}

/* Table */
.table-area { grid-area: table; display: flex; flex-direction: column; gap: 16px; }
.table {
  position: relative;
  height: 180px;
  border-radius: 90px;
  background: radial-gradient(ellipse at center, #237048 0%, var(--felt) 70%);
  border: 6px solid #3b2a1c;
  margin: 18px 30px;
}
.seat {
  position: absolute;
  width: 62px;
  height: 46px;
  margin: -23px 0 0 -31px;
  border-radius: 8px;
  background: var(--panel);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}
.seat em { font-style: normal; font-size: 10px; color: var(--muted); font-weight: 500; }
.seat.folded { opacity: 0.4; }
.seat.hero { border-color: #f0c040; box-shadow: 0 0 0 2px rgba(240, 192, 64, 0.3); }
.seat.hero em { color: #f0c040; }
.seat.villain { border-color: var(--raise); }
.seat.villain em { color: var(--raise); }
.hand { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.scenario { font-size: 16px; text-align: center; }
.cards { display: flex; gap: 10px; }
.card {
  width: 64px;
  height: 90px;
  border-radius: 8px;
  background: #f7f7f2;
  color: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}
.card.red { color: #c62828; }

.actions { display: flex; gap: 10px; }
.act, .next {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.act kbd { margin-left: 4px; }
.act:disabled { cursor: default; opacity: 0.35; }
.act.correct { opacity: 1; outline: 3px solid var(--ok); }
.act.wrong { opacity: 1; outline: 3px solid var(--bad); }
.next { background: #2d6a4f; }
.hidden { display: none; }

.feedback { min-height: 22px; text-align: center; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

/* Stats */
.stats { grid-area: stats; display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.stats > div { display: flex; flex-direction: column; }
.stats span { font-size: 22px; font-weight: 700; }
.link { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; text-decoration: underline; }

/* Range grid */
.chart-area { grid-area: chart; }
.legend { display: flex; align-items: center; gap: 6px; min-height: 20px; margin-bottom: 8px; font-size: 13px; flex-wrap: wrap; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-left: 6px; }
.pct { color: var(--muted); margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(13, 1fr); gap: 2px; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.cellinfo { margin: 0 0 8px; min-height: 18px; font-size: 12px; color: var(--muted); }
.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border-radius: 3px;
  background: #222c38;
  color: var(--muted);
}
.cell.revealed { color: #fff; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5); }
.cell.revealed.folded { color: #aab4bf; text-shadow: none; }
.cell.out { background: transparent; color: #4a5562; box-shadow: inset 0 0 0 1px #26303b; }
.cell.me { outline: 3px solid #f0c040; outline-offset: -1px; z-index: 1; font-weight: 700; }

.weak { grid-area: weak; }
.weak ol { margin: 0; padding-left: 20px; }

footer { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 24px calc(24px + env(safe-area-inset-bottom)); }
footer p { margin: 6px 0; }
code { font-family: ui-monospace, monospace; }
.weak li.empty { list-style: none; margin-left: -20px; }

/* Touch devices: no keyboard, no hover — drop the key hints and enlarge targets. */
@media (hover: none) {
  footer .keys { display: none; }
  .act kbd, .next kbd { display: none; }
}
@media (max-width: 480px) {
  header { padding: 14px 16px; }
  main { padding: 12px; gap: 12px; }
  main > section { padding: 14px; }
  .table { height: 150px; border-radius: 75px; margin: 14px 22px; }
  .cards .card { width: 56px; height: 80px; }
  .actions { width: 100%; flex-wrap: wrap; }
  .act { flex: 1 1 40%; min-height: 48px; font-size: 16px; }
  .next { width: 100%; min-height: 48px; font-size: 16px; }
  .stats { gap: 18px; }
}

/* Focus mode: strip the chrome so the drill and range chart get the screen.
   The controls row is hidden but comes back via the "Charts & settings" chip. */
.focusbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 30;
}
body.focus .focusbar { display: flex; }
.chip {
  border: 1px solid var(--border);
  background: rgba(16, 21, 28, 0.7);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-expanded="true"] { background: #2d6a4f; border-color: #2d6a4f; color: #fff; }
header .chip { margin-left: auto; flex: none; }
header .sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.focus header,
body.focus .stats,
body.focus footer { display: none; }
body.focus:not(.settings-open) .controls { display: none; }
body.focus main { padding-top: 8px; padding-bottom: 76px; }

/* Stack the controls on narrow screens. This must live after the base .controls
   rule so it actually wins — a <select> is as wide as its longest option, which
   otherwise pushes the whole page wider than the phone. nowrap matters too: a
   wrapping column container spills items into extra columns off to the right. */
@media (max-width: 860px) {
  .controls { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 12px; }
  .controls .divider { display: none; }
  .controls label { flex-direction: column; align-items: stretch; gap: 4px; }
  .controls label.check { flex-direction: row; align-items: center; gap: 8px; }
  .controls select { width: 100%; min-width: 0; }
}
