/* Shared styles for the Concepts practice pages (see drill.js). */
:root {
  --primary:              #cc785c;
  --primary-active:       #a9583e;
  --ink:                  #141413;
  --body:                 #3d3d3a;
  --muted:                #6c6a64;
  --muted-soft:           #8e8b82;
  --hairline:             #e6dfd8;
  --canvas:               #faf9f5;
  --surface-soft:         #f5f0e8;
  --surface-card:         #efe9de;
  --surface-cream-strong: #e8e0d2;
  --accent-amber:         #e8a55a;
  --accent-teal:          #5db8a6;
  --success:              #5db872;
  --error:                #c64545;
  --font-display: 'Cormorant Garamond', 'Tiempos Headline', Georgia, serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: var(--canvas);
  color: var(--body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 60px;
  gap: 14px;
}

/* ── Top nav ── */
.top-nav {
  width: 100%;
  height: 64px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 4px;
}
.top-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color .15s;
}
.top-nav a:hover { color: var(--ink); }
.nav-spike path { fill: var(--muted); transition: fill .15s; }
.top-nav a:hover .nav-spike path { fill: var(--ink); }
.nav-crumb { color: var(--muted-soft); font-size: 14px; margin-left: 6px; }
#theme-toggle {
  margin-left: auto;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 12px;
  height: 32px;
  transition: color .15s, border-color .15s, background .15s;
}
#theme-toggle:hover { background: var(--surface-soft); color: var(--ink); }

h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -1px;
  color: var(--ink);
  text-align: center;
}
.concept-sub {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  max-width: 480px;
  line-height: 1.55;
  margin-top: -6px;
}

/* ── Screens ── */
.screen {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.screen[hidden] { display: none; }

/* ── Setup cards ── */
.setup-card {
  width: 100%;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.setup-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}
.setup-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Segmented options: <div class="seg" data-setting="…"><button data-value="…">…</button></div> */
/* One row by default; wordy 4-option groups go 2×2 on narrow screens (add .compact to opt out). */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}
@media (max-width: 560px) {
  .seg:not(.compact):has(> button:nth-child(4)) { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
}
.seg button {
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  background: var(--canvas);
  color: var(--muted);
  border: 1.5px solid var(--hairline);
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  text-align: center;
  line-height: 1.3;
}
.seg button small { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted-soft); margin-top: 2px; }
.seg button:hover:not(.active) { background: var(--surface-soft); color: var(--body); }
.seg button.active { border-color: var(--primary); color: var(--ink); }
.seg-sym { color: var(--primary); font-weight: 700; margin-right: 4px; }

/* ── Buttons ── */
.btn-primary, .btn-secondary {
  padding: 10px 26px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-primary { background: var(--primary); color: #fff; border: none; }
.btn-primary:hover { background: var(--primary-active); }
.btn-secondary { background: var(--canvas); color: var(--ink); border: 1px solid var(--hairline); }
.btn-secondary:hover { background: var(--surface-soft); }
.btn-wide { width: 100%; height: 48px; font-size: 15px; }

/* ── Game header ── */
.game-header { width: 100%; display: flex; gap: 10px; }
.stat-box {
  flex: 1;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}
.stat-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 2px;
}
.stat-value {
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  font-weight: 900;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#cd-timer { color: var(--success); transition: color .3s; }
#cd-timer.warning { color: var(--accent-amber); }
#cd-timer.danger  { color: var(--primary); animation: cd-pulse .6s ease-in-out infinite alternate; }
@keyframes cd-pulse { from { opacity: 1; } to { opacity: .45; } }

/* ── Problem card ── */
.problem-card {
  width: 100%;
  background: var(--surface-card);
  border: 2px solid var(--hairline);
  border-radius: 12px;
  padding: 26px 22px 20px;
  text-align: center;
  transition: border-color .18s, background .18s;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.problem-card.correct { border-color: var(--success); background: rgba(93,184,114,.07); }
.problem-card.wrong   { border-color: var(--error);   background: rgba(198,69,69,.07); }
.problem-prompt {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.problem-text {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 10vw, 4rem);
  font-weight: 500;
  letter-spacing: -0.5px;
  color: var(--ink);
  line-height: 1.15;
  font-variant-numeric: lining-nums;
}
.problem-text.long  { font-size: clamp(1.8rem, 7vw, 3rem); }
.problem-text.xlong { font-size: clamp(1.45rem, 5.6vw, 2.4rem); }
.problem-text.xxlong { font-size: clamp(1.2rem, 4.6vw, 2rem); }
.problem-text sup, .choice-btn sup, .explain sup { font-size: 0.62em; line-height: 0; }
.feedback-text { font-size: 14px; font-weight: 500; min-height: 20px; color: transparent; }
.feedback-text.correct { color: var(--success); }
.feedback-text.wrong   { color: var(--error); }

/* ── Numeric answer ── */
.answer-row { width: 100%; display: flex; gap: 8px; }
#cd-input {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 16px;
  font-family: var(--font-body);
  font-size: 1.35rem;
  font-weight: 600;
  background: var(--canvas);
  color: var(--ink);
  border: 2px solid var(--hairline);
  border-radius: 8px;
  outline: none;
  text-align: center;
  transition: border-color .15s;
  cursor: default;
  caret-color: transparent;
}
#cd-input.correct { border-color: var(--success); }
#cd-input.wrong   { border-color: var(--error); }

.numpad { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.numpad.four { grid-template-columns: repeat(4, 1fr); }
.numpad[hidden] { display: none; }
.numpad-key {
  height: 50px;
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 500;
  background: var(--surface-card);
  color: var(--ink);
  border: 1.5px solid var(--hairline);
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s, transform .08s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.numpad-key:hover  { background: var(--surface-cream-strong); }
.numpad-key:active { transform: scale(.93); background: var(--surface-cream-strong); }
.numpad-key.muted  { background: var(--surface-soft); color: var(--muted); font-size: 1.1rem; }
.numpad-key.submit { background: var(--primary); color: #fff; border-color: var(--primary); font-size: 1.4rem; }
.numpad-key.submit:hover { background: var(--primary-active); border-color: var(--primary-active); }

/* ── Multiple choice ── */
.choice-grid { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-btn {
  position: relative;
  min-height: 72px;
  padding: 14px 12px 14px 30px;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 4.4vw, 1.5rem);
  font-weight: 500;
  font-variant-numeric: lining-nums;
  background: var(--surface-card);
  color: var(--ink);
  border: 2px solid var(--hairline);
  border-radius: 10px;
  cursor: pointer;
  transition: background .1s, border-color .12s, transform .08s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.choice-btn:hover:not(:disabled) { background: var(--surface-cream-strong); }
.choice-btn:active:not(:disabled) { transform: scale(.97); }
.choice-btn:disabled { cursor: default; }
.choice-key {
  position: absolute; top: 8px; left: 10px;
  font-family: var(--font-body); font-size: 11px; font-weight: 600; color: var(--muted-soft);
}
.choice-btn.correct { border-color: var(--success); background: rgba(93,184,114,.12); }
.choice-btn.wrong   { border-color: var(--error);   background: rgba(198,69,69,.10); }
.choice-btn.dim     { opacity: .45; }

.key-hint { font-size: 12px; color: var(--muted-soft); text-align: center; }

/* ── Explanation panel (practice mode + review) ── */
.explain {
  width: 100%;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--body);
  text-align: left;
}
.explain[hidden] { display: none; }
.explain p + p, .explain p + .steps, .explain .steps + p, .explain p + svg, .explain svg + p { margin-top: 8px; }
.explain strong { color: var(--ink); }
.explain .math { font-family: var(--font-display); font-size: 1.2em; font-weight: 500; font-variant-numeric: lining-nums; color: var(--ink); white-space: nowrap; }
.steps { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.steps li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.steps .math { white-space: normal; }
.step-note { font-size: 12.5px; color: var(--muted); }
.hl { background: rgba(204,120,92,.18); color: var(--primary-active); border-radius: 4px; padding: 0 3px; }
.numline { width: 100%; height: auto; display: block; color: var(--muted); }
.numline .start  { fill: var(--muted); }
.numline .end    { fill: var(--primary); }
.numline .arrow  { stroke: var(--primary); fill: none; }
.numline .lbl    { fill: var(--muted); font-family: var(--font-body); font-size: 11px; }
.numline .lbl.zero { fill: var(--ink); font-weight: 600; }
.numline .jump   { fill: var(--primary-active); font-family: var(--font-body); font-size: 12px; font-weight: 600; }

.practice-row { width: 100%; display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.practice-row[hidden] { display: none; }

/* ── Results ── */
.result-hero { text-align: center; }
.result-score {
  font-family: var(--font-display);
  font-size: clamp(4rem, 14vw, 6rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -2px;
  color: var(--primary);
}
.result-score-label { font-size: 14px; color: var(--muted); margin-top: 4px; }
.result-stats { width: 100%; display: flex; gap: 10px; }
.result-stat {
  flex: 1;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 16px 12px;
  text-align: center;
}
.result-stat-val { font-size: 1.8rem; font-weight: 900; color: var(--ink); line-height: 1; }
.result-stat-label { font-size: 11px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-top: 5px; }
.result-rating {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  font-weight: 400;
  color: var(--ink);
  text-align: center;
}
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.review { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.review[hidden] { display: none; }
.review-title { font-size: 11px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.review details {
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 14px;
}
.review summary {
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
  list-style: none;
}
.review summary::-webkit-details-marker { display: none; }
.review summary::before { content: '▸'; color: var(--muted-soft); font-size: 12px; }
.review details[open] summary::before { content: '▾'; }
.review .math { font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; color: var(--ink); font-variant-numeric: lining-nums; }
.review .yours { font-size: 13px; color: var(--error); }
.review .right { font-size: 13px; color: var(--success); }
.review .explain { margin-top: 10px; }

/* ── Tutorial ── */
.tutorial-trigger {
  margin-left: auto; margin-right: 8px; width: 32px; height: 32px;
  background: var(--surface-soft); border: 1px solid var(--hairline);
  border-radius: 50%; color: var(--muted);
  font-family: var(--font-body); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: background .15s, color .15s;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.tutorial-trigger + #theme-toggle { margin-left: 0; }
.tutorial-trigger:hover { background: var(--surface-card); color: var(--ink); }
.tutorial-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.tutorial-overlay[hidden] { display: none; }
.tutorial-box {
  background: var(--canvas); border-radius: 16px;
  padding: 32px 28px 24px; max-width: 440px; width: 100%;
  position: relative; box-shadow: 0 24px 64px rgba(0,0,0,0.18);
}
.tutorial-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--muted); line-height: 1; padding: 4px;
}
.tutorial-close:hover { color: var(--ink); }
.tutorial-step-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted-soft); margin-bottom: 10px; }
.tutorial-title { font-family: var(--font-display); font-size: 1.55rem; font-weight: 400; color: var(--ink); line-height: 1.2; margin-bottom: 10px; }
.tutorial-body { font-size: 0.9rem; line-height: 1.7; color: var(--body); margin-bottom: 22px; }
.tutorial-body sup { font-size: 0.7em; }
.tutorial-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 20px; }
.tutorial-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hairline); transition: background .15s; }
.tutorial-dot.active { background: var(--primary); }
.tutorial-nav { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.t-btn { font-family: var(--font-body); font-size: 0.88rem; font-weight: 500; padding: 7px 16px; border-radius: 8px; cursor: pointer; transition: background .15s, color .15s; border: 1px solid transparent; }
.t-btn[hidden] { display: none; }
.t-btn-secondary { background: var(--surface-soft); border-color: var(--hairline); color: var(--muted); }
.t-btn-secondary:hover { background: var(--surface-card); color: var(--ink); }
.t-btn-primary { background: var(--primary); color: #fff; }
.t-btn-primary:hover { background: var(--primary-active); }

/* ── Dark mode ── */
html.dark-mode body              { background: #0f0f1a; color: #ddd; }
html.dark-mode h1                { color: #fff; }
html.dark-mode .concept-sub      { color: #666; }
html.dark-mode .top-nav          { border-bottom-color: #2a2a3e; background: #0f0f1a; }
html.dark-mode .top-nav a        { color: #555; }
html.dark-mode .top-nav a:hover  { color: #aaa; }
html.dark-mode .nav-crumb        { color: #444; }
html.dark-mode .nav-spike path   { fill: #555; }
html.dark-mode .top-nav a:hover .nav-spike path { fill: #aaa; }
html.dark-mode #theme-toggle     { background: none; border-color: #333; color: #555; }
html.dark-mode #theme-toggle:hover { background: #1a1a2e; color: #ccc; border-color: #555; }
html.dark-mode .setup-card       { background: #1a1a2e; border-color: #2a2a3e; }
html.dark-mode .setup-label, html.dark-mode .setup-hint { color: #666; }
html.dark-mode .seg button       { background: #12121f; border-color: #2a2a3e; color: #666; }
html.dark-mode .seg button small { color: #555; }
html.dark-mode .seg button:hover:not(.active) { background: #1a1a2e; color: #aaa; }
html.dark-mode .seg button.active { background: #1a1a2e; border-color: var(--primary); color: #fff; }
html.dark-mode .btn-secondary    { background: transparent; color: #888; border-color: #333; }
html.dark-mode .btn-secondary:hover { background: #1a1a2e; color: #ccc; }
html.dark-mode .stat-box         { background: #1a1a2e; border-color: #2a2a3e; }
html.dark-mode .stat-label       { color: #555; }
html.dark-mode .stat-value       { color: #fff; }
html.dark-mode .problem-card     { background: #1a1a2e; border-color: #2a2a3e; }
html.dark-mode .problem-card.correct { background: rgba(93,184,114,.09); border-color: var(--success); }
html.dark-mode .problem-card.wrong   { background: rgba(198,69,69,.09); border-color: var(--error); }
html.dark-mode .problem-prompt   { color: #666; }
html.dark-mode .problem-text     { color: #fff; }
html.dark-mode #cd-input         { background: #0f0f1a; color: #fff; border-color: #2a2a3e; }
html.dark-mode #cd-input.correct { border-color: var(--success); }
html.dark-mode #cd-input.wrong   { border-color: var(--error); }
html.dark-mode .numpad-key       { background: #1a1a2e; border-color: #2a2a3e; color: #ddd; }
html.dark-mode .numpad-key:hover { background: #252538; }
html.dark-mode .numpad-key.muted { background: #12121f; color: #666; }
html.dark-mode .numpad-key.submit { background: var(--primary); border-color: var(--primary); color: #fff; }
html.dark-mode .choice-btn       { background: #1a1a2e; border-color: #2a2a3e; color: #fff; }
html.dark-mode .choice-btn:hover:not(:disabled) { background: #252538; }
html.dark-mode .choice-btn.correct { border-color: var(--success); background: rgba(93,184,114,.14); }
html.dark-mode .choice-btn.wrong   { border-color: var(--error); background: rgba(198,69,69,.14); }
html.dark-mode .choice-key       { color: #555; }
html.dark-mode .key-hint         { color: #444; }
html.dark-mode .explain          { background: #12121f; border-color: #2a2a3e; border-left-color: var(--primary); color: #aaa; }
html.dark-mode .explain strong, html.dark-mode .explain .math { color: #fff; }
html.dark-mode .step-note        { color: #666; }
html.dark-mode .hl               { background: rgba(204,120,92,.22); color: #e89a80; }
html.dark-mode .numline          { color: #555; }
html.dark-mode .numline .lbl     { fill: #666; }
html.dark-mode .numline .lbl.zero { fill: #ddd; }
html.dark-mode .numline .start   { fill: #777; }
html.dark-mode .numline .jump    { fill: #e89a80; }
html.dark-mode .result-stat      { background: #1a1a2e; border-color: #2a2a3e; }
html.dark-mode .result-stat-val  { color: #fff; }
html.dark-mode .result-rating    { color: #fff; }
html.dark-mode .review details   { background: #1a1a2e; border-color: #2a2a3e; }
html.dark-mode .review .math     { color: #fff; }
html.dark-mode .tutorial-box     { background: #1a1a2e; }
html.dark-mode .tutorial-title   { color: #fff; }
html.dark-mode .tutorial-body    { color: #aaa; }
html.dark-mode .tutorial-dot     { background: #2a2a3e; }
html.dark-mode .tutorial-dot.active { background: var(--primary); }
html.dark-mode .t-btn-secondary  { background: #252540; border-color: #2a2a3e; color: #888; }
html.dark-mode .t-btn-secondary:hover { background: #30304a; color: #ddd; }
html.dark-mode .tutorial-close   { color: #555; }
html.dark-mode .tutorial-close:hover { color: #aaa; }
html.dark-mode .tutorial-trigger { background: #1a1a2e; border-color: #2a2a3e; color: #555; }
html.dark-mode .tutorial-trigger:hover { background: #252540; color: #aaa; }

@media (max-width: 420px) {
  .choice-btn { min-height: 64px; padding-left: 24px; }
  .problem-card { padding: 22px 14px 16px; }
}
