/* Decision Making: calm, mobile-first, dark by default. */

:root {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --line: #2f2f2c;
  --text: #f4f3ef;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --good: #3dbb7f;
  --good-soft: rgba(61, 187, 127, 0.14);
  --bad: #e66767;
  --bad-soft: rgba(230, 103, 103, 0.14);
  /* Frequency-grid series (validated categorical slots 1–3) + neutral */
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --dot: #3a3a37;
  --card-face: #f3f1ea;
  --card-ink: #1d1d1b;
  --suit-s: #1d1d1b;
  --suit-h: #d23b3b;
  --suit-d: #2465c7;
  --suit-c: #18804a;
  --radius: 16px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #efede8;
  --line: #e0ded7;
  --text: #0f0f0e;
  --text-2: #4a4945;
  --muted: #6e6d68;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --good: #1d8a56;
  --good-soft: rgba(29, 138, 86, 0.1);
  --bad: #c73c3c;
  --bad-soft: rgba(199, 60, 60, 0.09);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --dot: #dad8d1;
  --card-face: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
b, strong { font-weight: 650; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; }

/* ---------- Screen layout: content on top, actions in the thumb zone ---------- */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px var(--gutter) 0;
  min-height: 56px;
}
.topbar .title { flex: 1; font-weight: 650; font-size: 17px; }
.content { flex: 1; padding: 8px var(--gutter) 24px; }
.actions {
  position: sticky; bottom: 0;
  padding: 12px var(--gutter) calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 24px);
  display: grid; gap: 10px;
}
.actions.two { grid-template-columns: 1fr 1fr; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 56px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 17px; font-weight: 600;
  padding: 12px 18px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.45; }
.btn:focus-visible, .choice:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.icon-btn {
  min-width: 48px; min-height: 48px;
  border: 0; background: transparent; border-radius: 12px;
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-2);
  display: inline-grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }

/* Big two-line answer buttons (EV options) */
.choice {
  text-align: left;
  min-height: 72px;
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 16px;
  cursor: pointer;
  touch-action: manipulation;
}
.choice:active { background: var(--surface-2); }
.choice .label { display: block; font-weight: 650; font-size: 18px; }
.choice .detail { display: block; color: var(--text-2); font-size: 15px; margin-top: 2px; }

/* ---------- Text ---------- */
h1 { font-size: 30px; line-height: 1.15; margin: 8px 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 22px; line-height: 1.25; margin: 4px 0 8px; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); }
.small { font-size: 15px; }
.eyebrow { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.card.tight { padding: 12px 14px; }

/* ---------- Home ---------- */
.home-hero { padding-top: 24px; }
.home-hero p { color: var(--text-2); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.tile .k { font-size: 13px; color: var(--muted); }
.tile .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 14px; font-weight: 500; color: var(--muted); }
.nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Round ---------- */
.progress { display: flex; gap: 5px; flex: 1; }
.progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress span.done { background: var(--accent); }
.progress span.now { background: var(--text-2); }
.round-meta { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
}
.scenario-body { font-size: 18px; }
.question { font-weight: 650; font-size: 19px; margin-top: 4px; }

details.primer { background: var(--accent-soft); border-radius: 14px; padding: 4px 14px; margin: 8px 0 12px; }
details.primer summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; list-style: none; }
details.primer summary::-webkit-details-marker { display: none; }
details.primer summary::after { content: "＋"; margin-left: auto; color: var(--muted); }
details.primer[open] summary::after { content: "－"; }
details.primer p { font-size: 15px; color: var(--text-2); }

/* Slider (Bayes) */
.estimate { text-align: center; }
.estimate .readout { font-size: 52px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.estimate .hint { font-size: 14px; color: var(--muted); }
.slider-row { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; align-items: center; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 48px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--line); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--line); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); margin-top: -12px; border: 3px solid var(--surface);
}
input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); }
.step-btn { min-width: 48px; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; cursor: pointer; }

/* Poker table */
.table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.hand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }
.hand-row .who { font-size: 14px; color: var(--muted); }
.hand-row .who b { display: block; color: var(--text); font-size: 15px; }
.cards { display: flex; gap: 6px; flex-wrap: wrap; }
.pcard {
  width: 44px; height: 60px; border-radius: 7px;
  background: var(--card-face); color: var(--card-ink);
  display: grid; place-items: center; align-content: center;
  font-weight: 700; font-size: 20px; line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  font-family: var(--font);
}
.pcard .s { font-size: 18px; margin-top: 2px; }
.pcard.s-s { color: var(--suit-s); } .pcard.s-h { color: var(--suit-h); }
.pcard.s-d { color: var(--suit-d); } .pcard.s-c { color: var(--suit-c); }
.pcard.mini { width: 34px; height: 44px; font-size: 15px; border-radius: 6px; }
.pcard.mini .s { font-size: 14px; }
.board { display: flex; gap: 6px; justify-content: center; padding: 12px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); margin: 8px 0; }
.money-row { display: flex; justify-content: space-around; text-align: center; margin-top: 8px; }
.money-row .k { font-size: 13px; color: var(--muted); }
.money-row .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Bridges */
.bridge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bcard {
  display: flex; flex-direction: column; align-items: stretch; text-align: left;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  padding: 6px 8px 10px; min-height: 48px; font: inherit; color: inherit;
  touch-action: manipulation;
}
button.bcard { cursor: pointer; }
.bcard[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); padding: 5px 7px 9px; }
.bcard.best { border: 2px solid var(--good); padding: 5px 7px 9px; }
.bcard.picked { border: 2px dashed var(--bad); padding: 5px 7px 9px; }
.bcard .bridge-art { width: 100%; height: auto; display: block; }
.bcard .lbl { font-weight: 650; font-size: 15px; line-height: 1.25; }
.bcard .spec { font-size: 13px; color: var(--muted); }
.bcard .tonnes { font-size: 15px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.conf-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.conf-row .btn { padding: 12px 4px; }
.calib { display: grid; grid-template-columns: auto auto 1fr; gap: 6px 16px; font-variant-numeric: tabular-nums; align-items: baseline; }
.calib .k { font-size: 13px; color: var(--muted); }

/* ---------- Feedback ---------- */
.verdict { border-radius: var(--radius); padding: 14px 16px; margin: 8px 0 4px; display: flex; gap: 12px; align-items: flex-start; }
.verdict.good { background: var(--good-soft); }
.verdict.bad { background: var(--bad-soft); }
.verdict .icon { font-size: 22px; font-weight: 800; line-height: 1.3; }
.verdict.good .icon { color: var(--good); }
.verdict.bad .icon { color: var(--bad); }
.verdict .h { font-weight: 700; font-size: 19px; }
.verdict .s { color: var(--text-2); font-size: 15px; }
ol.steps { padding-left: 22px; margin: 0; }
ol.steps li { margin: 0 0 10px; font-size: 16px; }
ol.steps li::marker { color: var(--muted); font-weight: 600; }
.takeaway { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin: 16px 0; font-weight: 600; }
.realworld { font-size: 15px; color: var(--text-2); }
.realworld .eyebrow { display: block; margin-bottom: 4px; }

/* Frequency grid */
.grid-wrap svg { width: 100%; height: auto; display: block; }
.legend { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; font-size: 14px; }
.legend li { display: flex; gap: 8px; align-items: center; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---------- Summary & stats ---------- */
.score-big { font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-big small { font-size: 20px; color: var(--muted); font-weight: 600; }
.type-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.type-row:last-child { border-bottom: 0; }
.type-row .name { font-weight: 600; }
.type-row .val { font-variant-numeric: tabular-nums; color: var(--text-2); }
.bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.badge-up { color: var(--good); font-size: 13px; font-weight: 600; }
.insight .eyebrow { display: block; margin-bottom: 4px; }
.insight .name { font-size: 19px; font-weight: 700; margin-bottom: 4px; }

.spark { position: relative; margin-top: 6px; }
.spark svg { width: 100%; height: 64px; display: block; overflow: visible; }
.spark .tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%);
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600;
  padding: 4px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none;
}

/* ---------- Settings ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { min-height: 48px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.stack { display: grid; gap: 10px; }
textarea { width: 100%; min-height: 120px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 12px; font-family: var(--mono); font-size: 13px; }
.note { font-size: 14px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 600;
  z-index: 10; max-width: calc(100vw - 32px);
}

/* Confirm dialog */
dialog { border: 0; border-radius: 20px; padding: 20px; background: var(--surface); color: var(--text); width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog .actions { position: static; padding: 12px 0 0; background: none; }

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