/* DSA Arena: self-contained. Inherit root tokens, define everything else. */
@import url("../styles.css");

:root { --accent: #9a5236; }
.mark { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 7px; color: #fff; background: var(--accent); }

/* pattern prev/next navigation */
.study-nav { display: flex; align-items: stretch; justify-content: space-between; gap: 12px; margin: 22px 0 2px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.snav { display: flex; flex-direction: column; gap: 3px; min-height: 54px; padding: 9px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; text-align: left; font: inherit; color: inherit; transition: transform .08s, border-color .12s, box-shadow .12s; max-width: 46%; }
.snav:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: 0 4px 14px rgba(154,82,54,.16); }
.snav.next { text-align: right; align-items: flex-end; border-color: var(--accent); }
.snav-k { font-size: .72rem; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.snav-n { font-weight: 800; font-size: .93rem; line-height: 1.2; color: var(--ink); }
.snav-pos { align-self: center; font-variant-numeric: tabular-nums; font-weight: 800; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.snav-spacer { max-width: 46%; display: flex; align-items: center; color: var(--muted); font-weight: 700; font-size: .9rem; }
@media (max-width: 560px) { .snav, .snav-spacer { max-width: none; flex: 1 1 100%; } .snav.next { text-align: left; align-items: flex-start; } .snav-pos { order: -1; flex: 1 1 100%; text-align: center; } }
button { cursor: pointer; font: inherit; }

.hl { color: var(--accent); }
.eyebrow { margin: 0 0 12px; color: var(--rose); font-size: .78rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .95fr); gap: clamp(24px, 5vw, 60px); align-items: center; padding: clamp(44px, 7vw, 84px) clamp(18px, 4vw, 56px); min-height: 560px; background: radial-gradient(900px 420px at 12% -10%, #e4ecd9, transparent 60%), var(--paper); }
.hero h1 { margin: 0; font-size: clamp(2rem, 4.6vw, 3.8rem); line-height: 1.05; }
.lead { color: var(--muted); line-height: 1.7; font-size: clamp(1rem, 1.6vw, 1.15rem); max-width: 60ch; }
.hero-badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.hero-badges span { border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; background: var(--panel); font-weight: 800; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.button { display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font-weight: 850; transition: transform .15s ease, box-shadow .15s ease; }
.button:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.hero-stage { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.hero-stage canvas { display: block; width: 100%; height: auto; }

/* ---------- bands / titles ---------- */
.band, .arena, .next { padding: clamp(40px, 6vw, 80px) clamp(18px, 4vw, 56px); border-top: 1px solid var(--line); }
.band { background: #e7ede0; }
.section-title { max-width: 820px; margin: 0 auto 26px; text-align: center; }
.section-title h2 { margin: 6px 0 10px; font-size: clamp(1.7rem, 3.4vw, 2.8rem); }
.section-title .lead { margin-inline: auto; }

/* ---------- pattern grid ---------- */
.pattern-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: 12px; max-width: 1200px; margin: 0 auto; }
.pattern-card { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 16px 14px 14px; border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease; }
.pattern-card:hover { transform: translateY(-3px); box-shadow: 0 20px 44px rgba(24, 35, 49, .16); }
.pattern-card.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.pc-emoji { font-size: 1.5rem; }
.pc-num { position: absolute; top: 12px; right: 12px; font-size: .72rem; font-weight: 900; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, #fff); border-radius: 999px; padding: 2px 8px; }
.pattern-card strong { font-size: 1rem; color: var(--ink); }
.pc-hook { color: var(--muted); font-size: .82rem; line-height: 1.4; }

/* ---------- arena ---------- */
.pattern-head { display: flex; align-items: center; gap: 16px; max-width: 1200px; margin: 0 auto 18px; padding: 16px 18px; border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.pattern-head .ph-emoji { font-size: 2.4rem; }
.pattern-head h2 { margin: 2px 0; font-size: clamp(1.4rem, 3vw, 2.1rem); color: var(--accent); }
.pattern-head .ph-hook { margin: 0; color: var(--muted); font-weight: 600; }
.arena-grid { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: 18px; max-width: 1200px; margin: 0 auto; align-items: start; }
.card { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); padding: clamp(16px, 2.4vw, 24px); }
.pattern-explainer .idea { line-height: 1.65; color: var(--ink); }
.pattern-explainer .idea p { margin: 0 0 10px; }
.lbl { margin: 16px 0 6px; font-size: .72rem; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.when { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.6; }
.cx { margin: 0; font-weight: 700; color: var(--ink); }
.algo { margin: 0; padding-left: 22px; color: var(--ink); line-height: 1.6; }
.algo li { margin-bottom: 6px; }
.algo code, .variants code, .idea code { background: #e7eddc; padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
.variants { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.55; }
.variants li { margin-bottom: 6px; } .variants strong { color: var(--ink); }
.pitfalls { margin: 0; padding-left: 0; list-style: none; color: var(--ink); line-height: 1.55; }
.pitfalls li { margin-bottom: 5px; }
.template { margin: 0; background: #20281f; color: var(--paper); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-left: 4px solid var(--d, var(--muted)); border-radius: 6px; padding: 3px 8px; font-weight: 800; font-size: .8rem; background: var(--panel); }

/* ---------- solver ---------- */
.problem-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.ptab { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); flex: 1 1 160px; }
.ptab .pt-diff { font-size: .68rem; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; color: var(--d, var(--muted)); }
.ptab .pt-name { font-size: .82rem; font-weight: 700; color: var(--ink); }
.ptab.active { border-color: var(--d, var(--accent)); box-shadow: inset 0 0 0 2px var(--d, var(--accent)); }
.problem-title { margin: 6px 0 4px; font-size: 1.15rem; }
.diff-pill { display: inline-block; font-size: .7rem; font-weight: 900; text-transform: uppercase; color: #fff; background: var(--d, var(--muted)); border-radius: 6px; padding: 2px 8px; vertical-align: middle; }
.problem-idea { margin: 0 0 12px; color: var(--muted); line-height: 1.6; }

.stage-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.stage-wrap canvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.side-panel { display: none; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; }
.var { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 7px; padding: 3px 8px; background: var(--panel); font-size: .82rem; }
.var .vk { font-weight: 900; color: var(--accent); }
.var .vv { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--ink); }
.side-html { color: var(--muted); font-size: .86rem; line-height: 1.5; margin-top: 6px; }

.player { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.player-btn { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-weight: 800; }
.player-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.player-btn:hover { border-color: var(--accent); }
.speed { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: .85rem; color: var(--muted); }
.speed input { max-width: 120px; }
.step-counter { margin-left: auto; font-weight: 800; color: var(--muted); font-size: .85rem; }
.pbar { height: 5px; margin-top: 10px; border-radius: 4px; background: var(--line); overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width .28s ease; }
.step-desc { min-height: 2.4em; margin: 10px 0 0; padding: 10px 12px; border-radius: 9px; background: #e7eddc; color: var(--ink); line-height: 1.5; font-weight: 600; }

.code-wrap { margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #20281f; color: var(--line); font-weight: 800; font-size: .82rem; }
.mini { border: 1px solid #3a4636; background: #2b3527; color: var(--paper); border-radius: 6px; padding: 3px 10px; font-weight: 700; font-size: .78rem; }
.code-block { margin: 0; max-height: 360px; overflow: auto; background: #20281f; padding: 10px 0; }
.code-block code { display: block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; line-height: 1.55; }
.cline { display: block; padding: 0 14px; white-space: pre; color: #dbe6d2; border-left: 3px solid transparent; }
.cline.hot { background: rgba(154, 82, 54, .28); border-left-color: var(--accent); color: #fff; }
.complexity { margin: 10px 0 0; color: var(--muted); font-size: .9rem; }
.complexity strong { color: var(--ink); }

/* ---------- quiz ---------- */
.panel-head { max-width: 1000px; margin: 0 auto 12px; text-align: right; }
.panel-head strong { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; background: var(--panel); font-weight: 900; }
.quiz-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 14px; max-width: 1000px; margin: 0 auto; }
.quiz-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--panel); box-shadow: var(--shadow); }
.quiz-card strong { display: block; margin-bottom: 10px; line-height: 1.4; }
.q-opts { display: grid; gap: 8px; }
.q-opts button { text-align: left; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-weight: 700; }
.q-opts button:hover:not(:disabled) { border-color: var(--accent); }
.q-opts button.correct { background: var(--green); border-color: var(--green); color: #fff; }
.q-opts button.wrong { background: var(--rose); border-color: var(--rose); color: #fff; }

.next { text-align: center; background: linear-gradient(180deg, #f1eed8, var(--paper)); }
.next .actions { justify-content: center; }

/* ---------- reveal ---------- */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in { opacity: 1; transform: none; }

/* ---------- responsive ---------- */
@media (max-width: 920px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .arena-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .ptab { flex: 1 1 100%; }
  .actions .button { flex: 1 1 100%; justify-content: center; }
  .step-counter { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; } .pattern-card:hover { transform: none; } html { scroll-behavior: auto; } }

/* ---------- beautiful-math callout ---------- */
.beauty-note { margin: 16px 0 4px; padding: 14px 16px 13px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; background: linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 86%, var(--paper))); }
.beauty-tag { display: inline-block; font-size: .68rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.beauty-name { margin: 6px 0 0; font-weight: 850; font-size: .98rem; color: var(--ink); line-height: 1.3; }
.beauty-eq { margin: 10px 0; padding: 9px 12px; border-radius: 9px; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); color: var(--ink); font-family: "Cambria Math", "Georgia", "Times New Roman", serif; font-style: italic; font-size: 1.12rem; text-align: center; letter-spacing: .01em; }
.beauty-why { margin: 8px 0 0; color: var(--muted); line-height: 1.65; font-size: .92rem; }

/* ---------- Binary-Search-on-the-Answer math lab ---------- */
.bsa-wrap { max-width: 1000px; margin: 0 auto; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); padding: clamp(16px, 2.4vw, 24px); }
.bsa-math { display: grid; gap: 6px; margin-bottom: 12px; }
.bsa-eq { margin: 0; text-align: center; font-weight: 800; color: var(--ink); line-height: 1.5; font-size: clamp(.86rem, 1.6vw, 1rem); }
.bsa-eq .f0 { color: var(--clay); }
.bsa-eq .f1 { color: var(--green); }
.bsa-eq sub { font-size: .72em; }
#bsaCanvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.bsa-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.bsa-slider { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: .85rem; color: var(--muted); }
.bsa-slider input { max-width: 200px; }
.bsa-stat { margin-left: auto; font-weight: 800; color: var(--ink); font-size: .85rem; font-variant-numeric: tabular-nums; }
.bsa-cap { margin: 12px 0 0; color: var(--muted); line-height: 1.6; font-size: .9rem; }
@media (max-width: 560px) { .bsa-stat { margin-left: 0; width: 100%; } .bsa-slider input { max-width: 140px; } }

/* ---------- polish: keyboard focus visibility (additive, accessibility) ---------- */
.button:focus-visible,
.player-btn:focus-visible,
.snav:focus-visible,
.ptab:focus-visible,
.mini:focus-visible,
.q-opts button:focus-visible,
.pattern-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 70%, #fff);
  outline-offset: 2px;
}
.speed input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- polish: tactile press feedback (reuses existing hover transitions) ---------- */
.player-btn, .q-opts button, .mini, .ptab {
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease, background-color .18s ease, color .18s ease;
}
.button:active, .player-btn:active, .snav:active { transform: translateY(0); }
.q-opts button:active:not(:disabled) { transform: translateY(1px); }

/* ---------- polish: subtle hover on secondary surfaces ---------- */
.quiz-card { transition: transform .15s ease, box-shadow .15s ease; }
.quiz-card:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(24, 35, 49, .12); }
.chip { transition: border-color .12s ease, transform .12s ease; }
.chip:hover { transform: translateY(-1px); border-color: var(--accent); }
.var { transition: border-color .12s ease; }
.var:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* ---------- polish: smoother state transitions ---------- */
.q-opts button.correct, .q-opts button.wrong { transition: background-color .25s ease, border-color .25s ease, color .25s ease; }
.cline { transition: background-color .2s ease, border-left-color .2s ease, color .2s ease; }
.diff-pill { transition: background-color .2s ease; }
.pc-num { transition: background-color .15s ease; }
.pattern-card:hover .pc-num { background: color-mix(in srgb, var(--accent) 22%, #fff); }

/* ---------- polish: typography & scroll micro-refinements ---------- */
.step-counter, .panel-head strong { font-variant-numeric: tabular-nums; }
.lbl { text-rendering: optimizeLegibility; }
.code-block { scroll-behavior: smooth; overscroll-behavior: contain; }
.step-desc { transition: background-color .2s ease; }

/* ---------- polish: responsive hardening for wide media ---------- */
.arena-grid > * { min-width: 0; }
.stage-wrap, .code-wrap { max-width: 100%; }
.template, .code-block { max-width: 100%; }
.code-block code { word-break: normal; }
@media (max-width: 560px) {
  .pattern-head { gap: 12px; padding: 14px; }
  .code-block { max-height: 300px; }
  .quiz-list { gap: 12px; }
}

/* ---------- polish: respect reduced motion for all new effects ---------- */
@media (prefers-reduced-motion: reduce) {
  .quiz-card:hover, .chip:hover, .button:active, .player-btn:active, .snav:active,
  .q-opts button:active:not(:disabled) { transform: none; }
  .code-block { scroll-behavior: auto; }
}
