/* ============================================================
   Semantic Quest — style.css
   Dark playful UI. One accent per level:
     Level 1 (semantics) ... cyan   #22d3ee
     Level 2 (box model) ... violet #a78bfa
     Level 3 (units/color) . green  #34d399
   NOTE FOR CURIOUS STUDENTS (hi!): this stylesheet models what
   it teaches. box-sizing: border-box is set globally, spacing
   uses consistent padding/margin/border, and shadows are subtle.
   Open dev tools — this file is safe to learn from.
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box; /* width/height include padding + border */
}

:root {
  --bg: #101325;
  --bg-soft: #171b33;
  --card: #1d2240;
  --line: #2e3563;
  --ink: #eef0ff;
  --muted: #a8add6;
  --accent-1: #22d3ee;
  --accent-2: #a78bfa;
  --accent-3: #34d399;
  --good: #34d399;
  --bad: #fb7185;
  --gold: #fbbf24;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: clip; /* page itself never scrolls sideways */
}

.wrap {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
  min-width: 0;
}

/* ---------- header / HUD ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(16, 19, 37, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.brand {
  margin: 0;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

.brand-bolt {
  color: var(--gold);
  flex: none;
}

.lang-switch {
  display: flex;
  gap: 4px;
  background: #262c55;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.lang-btn:hover { color: var(--ink); }

.lang-btn[aria-pressed="true"] {
  background: var(--gold);
  color: #0b0e20;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-width: 0;
}

.xp {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.xp-num {
  display: inline-block;
}

.xp-bump {
  animation: bump 0.45s ease;
}

@keyframes bump {
  30% { transform: scale(1.35); color: var(--gold); }
}

.rank {
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  border: 2px solid transparent;
  transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}

.rank-0 { background: #2b3057; color: #c3c8ee; border-color: #454d85; }
.rank-1 { background: rgba(34, 211, 238, 0.14); color: var(--accent-1); border-color: var(--accent-1); }
.rank-2 { background: rgba(167, 139, 250, 0.16); color: var(--accent-2); border-color: var(--accent-2); }
.rank-3 { background: rgba(251, 191, 36, 0.14); color: var(--gold); border-color: var(--gold); }

.level-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 160px;
  min-width: 140px;
}

.level-label {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.bar {
  flex: 1;
  height: 10px;
  min-width: 60px;
  background: #262c55;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
  transition: width 0.4s ease;
}

/* ---------- screens / type ---------- */

#app {
  flex: 1;
  padding-top: 32px;
  padding-bottom: 48px;
}

.screen[hidden] {
  display: none;
}

.kicker {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.kicker.level-1 { color: var(--accent-1); }
.kicker.level-2 { color: var(--accent-2); }
.kicker.level-3 { color: var(--accent-3); }

h1, h2 {
  line-height: 1.2;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(1.7rem, 5.5vw, 2.4rem); }
h2 { font-size: clamp(1.45rem, 4.5vw, 1.9rem); }

.lede {
  color: var(--muted);
  margin: 0 0 20px;
  max-width: 60ch;
}

.lede code, li code, .opt code, .why code, .stem code, p code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: #262c55;
  padding: 1px 6px;
  border-radius: 6px;
  color: #ffd88a;
}

.level-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  gap: 10px;
}

.level-list li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

.dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot-1 { background: var(--accent-1); }
.dot-2 { background: var(--accent-2); }
.dot-3 { background: var(--accent-3); }

.save-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin: 20px 0 12px;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  padding: 12px 22px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.2s;
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
  color: #0b0e20;
  box-shadow: var(--shadow);
}

.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-ghost:hover { border-color: var(--accent-1); }

.btn-danger {
  background: transparent;
  color: var(--bad);
  border-color: var(--bad);
}

.btn-danger:hover { background: rgba(251, 113, 133, 0.12); }

.btn-next {
  background: var(--card);
  color: var(--ink);
  border-color: var(--line);
  margin-top: 14px;
}

.btn-next:hover { border-color: var(--gold); }

.btn-check {
  background: var(--gold);
  color: #0b0e20;
  margin-top: 14px;
}

.btn-check:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* visible keyboard focus everywhere */
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- code snippet ---------- */

.snippet-card {
  margin: 0 0 8px;
  background: #0b0e20;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.snippet-cap {
  padding: 10px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.snippet {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto; /* long lines scroll inside the card, never the page */
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.75;
}

.snippet .ln {
  display: block;
  padding: 0 8px;
  margin: 0 -8px;
  border-radius: 6px;
  border-left: 3px solid transparent;
  white-space: pre;
}

.snippet .ln.active-flag {
  background: rgba(251, 191, 36, 0.1);
  border-left-color: var(--gold);
}

.snippet .ln.fixed-flag {
  opacity: 0.55;
}

.tg { color: #7dd3fc; }
.at { color: var(--accent-2); }
.sv { color: #86efac; }
.cm { color: #6b7199; font-style: italic; }

/* ---------- question cards ---------- */

.q-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

#screen-l1 .q-card { border-top: 4px solid var(--accent-1); }
#screen-l2 .q-card { border-top: 4px solid var(--accent-2); }
#screen-l3 .q-card { border-top: 4px solid var(--accent-3); }

.q-card legend, .q-head {
  font-weight: 700;
  font-size: 1.02rem;
  padding: 0 6px;
}

.stem {
  margin: 6px 0 14px;
  color: var(--ink);
  overflow-wrap: break-word;
}

.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin: 0 0 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
  overflow-wrap: break-word;
}

.opt:hover { border-color: var(--muted); }

.opt input {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--gold);
}

.opt-picked { border-color: var(--gold); }
.opt-right { border-color: var(--good); background: rgba(52, 211, 153, 0.1); }
.opt-wrong { border-color: var(--bad); background: rgba(251, 113, 133, 0.08); }

.q-card.answered .opt { cursor: default; }
.q-card.answered .opt:not(.opt-right):not(.opt-wrong) { opacity: 0.6; }

.feedback {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.feedback.good {
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid var(--good);
  animation: pop 0.4s ease;
}

.feedback.bad {
  background: rgba(251, 113, 133, 0.1);
  border: 1px solid var(--bad);
  animation: shake 0.4s ease;
}

.feedback .verdict { font-weight: 700; }
.feedback.good .verdict { color: var(--good); }
.feedback.bad .verdict { color: var(--bad); }
.why { margin: 4px 0 0; color: var(--ink); }
.xp-note { margin: 6px 0 0; font-weight: 700; color: var(--gold); }

@keyframes pop {
  0% { transform: scale(0.97); }
  50% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ---------- level summaries ---------- */

.summary-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.summary-card h3 { margin: 0 0 6px; font-size: 1.3rem; }
.summary-card p { color: var(--muted); margin: 0 0 16px; }
.summary-card strong { color: var(--gold); }

/* ---------- Level 2 live box demos ---------- */

.stage {
  background: #0b0e20;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 24px 16px;
  margin: 0 0 14px;
  overflow-x: clip;
}

.stage-cap {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 14px;
}

.target-frame {
  position: relative;
  border: 2px dashed var(--gold);
  border-radius: 4px;
}

.target-tag {
  position: absolute;
  top: -12px;
  left: 8px;
  background: var(--gold);
  color: #0b0e20;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.demo-box {
  background: rgba(167, 139, 250, 0.35);
  border: 5px solid var(--accent-2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.r1-box {
  box-sizing: content-box; /* the point of the question: padding+border ADD ON */
  width: 260px;
  height: 110px;
  padding: 20px;
}

.r3-box {
  box-sizing: border-box; /* padding+border fold INTO the declared size */
  width: 300px;
  height: 140px;
  padding: 20px;
  flex-direction: column;
  gap: 4px;
}

.r3-content {
  background: rgba(52, 211, 153, 0.35);
  border: 1px solid var(--good);
  border-radius: 4px;
  padding: 4px 8px;
}

.mp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.mp-col { min-width: 0; }

.mp-cap {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 8px;
}

.mp-pad-child {
  background: var(--accent-2);
  padding: 0 28px;
  color: #0b0e20;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 44px;
  border-radius: 4px;
  width: max-content;
  max-width: 100%;
}

.mp-margin-child {
  background: var(--accent-2);
  color: #0b0e20;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 44px;
  padding: 0 12px;
  margin: 0 28px;
  border-radius: 4px;
  width: max-content;
  max-width: calc(100% - 56px);
}

.mp-legend {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: baseline;
}

.swatch-pad { background: var(--accent-2); }
.swatch-gap { background: #0b0e20; border: 1px solid var(--muted); }

@media (max-width: 430px) {
  .stage { zoom: 0.82; } /* shrink fixed-px demos as a unit: math stays exact */
}

/* ---------- final screen ---------- */

.final-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 22px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.final-rank {
  display: inline-block;
  font-size: 1rem;
  margin: 0 0 8px;
}

.final-xp {
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.final-msg {
  color: var(--muted);
  max-width: 52ch;
  margin: 10px auto 0;
}

.table-title {
  font-size: 1.1rem;
  margin: 0 0 10px;
}

.breakdown {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
}

.breakdown th, .breakdown td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.breakdown thead th {
  background: #262c55;
  font-size: 0.85rem;
  color: var(--muted);
}

.breakdown tbody tr:last-child th,
.breakdown tbody tr:last-child td {
  border-bottom: none;
}

.final-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.review-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 0.92rem;
}

.review-item p { margin: 0 0 6px; }

.review-stem { font-weight: 600; }

.review-correct { color: var(--good); }
.review-yours-ok { color: var(--good); font-weight: 700; }
.review-yours-bad { color: var(--bad); font-weight: 700; }
.review-why { color: var(--muted); }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 18px 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p { margin: 0; }

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