/* KeplinFamily Academy — stylesheet
   Design: dark "hardware lab" theme, system font stack (no web-font request),
   compositor-only animations, reduced-motion respected. */

:root {
  --bg: #0a0d1f;
  --bg-soft: #131737;
  --surface: #171c3f;
  --surface-raised: #1f2554;
  --border: #2b3268;
  --border-strong: #3d4690;
  --text: #f1f2ff;
  --text-dim: #a6addd;
  --primary: #7c6cff;
  --primary-light: #9d90ff;
  --accent: #ffb84d;
  --accent-deep: #ff8a1f;
  --success: #34d399;
  --success-dim: #1c7a53;
  --danger: #ff5d73;
  --info: #4cc9f0;
  --locked: #5b6291;
  --newegg: #f58220;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 14px 40px rgba(0, 0, 0, .45);
  --glow: 0 0 0 1px rgba(124, 108, 255, .35), 0 12px 34px rgba(124, 108, 255, .22);
  --max: 1120px;
  font-size: 17px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}
body {
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 10% -10%, rgba(124, 108, 255, .22), transparent 60%),
    radial-gradient(900px 480px at 100% 0%, rgba(255, 184, 77, .12), transparent 55%),
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
  background-size: auto, auto, 36px 36px, 36px 36px;
  background-attachment: fixed, fixed, fixed, fixed;
  font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.015em; font-weight: 800; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); }
p { margin: 0 0 1em; }
a { color: var(--primary-light); }
button { font-family: inherit; }
strong { font-weight: 700; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Header / Footer ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 13, 31, .78);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -.01em;
}
.brand-emoji {
  font-size: 1.25rem;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #3f2fb8);
  box-shadow: 0 6px 18px rgba(124, 108, 255, .35);
}
.brand-text strong { color: var(--accent); font-weight: 800; }
.header-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 120px;
}
.header-progress-track {
  flex: 1;
  height: 9px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.header-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}
.header-progress-label { font-size: .78rem; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.site-footer { text-align: center; color: var(--text-dim); font-size: .78rem; padding: 30px 20px 50px; }
.site-footer a { color: var(--text-dim); }

.app-main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 30px 20px 80px;
  min-height: 60vh;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: .98rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease, background .15s ease;
  background: var(--primary);
  color: white;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(124, 108, 255, .4); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); color: #2b1600; }
.btn-accent:hover { box-shadow: 0 8px 22px rgba(255, 184, 77, .4); }
.btn-success { background: var(--success); color: #05281a; }
.btn-ghost { background: transparent; border: 1px solid var(--border-strong); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--primary-light); box-shadow: none; }
.btn-small { padding: 8px 14px; font-size: .8rem; }
.btn-block { width: 100%; }

/* ---------- Hero / dashboard ---------- */
.hero { text-align: center; padding: 14px 0 34px; }
.hero h1 { font-size: clamp(1.9rem, 4.2vw, 2.8rem); }
.hero h1 .grad { background: linear-gradient(90deg, var(--primary-light), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--text-dim); max-width: 640px; margin: 0 auto 1em; font-size: 1.02rem; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px auto 0; max-width: 760px; }
.chip {
  font-size: .76rem; font-weight: 700; letter-spacing: .02em;
  padding: 6px 11px; border-radius: 999px;
  background: rgba(124, 108, 255, .14); border: 1px solid rgba(124, 108, 255, .35); color: var(--text);
}

.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
  margin: 0 auto 10px; max-width: 760px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; text-align: left;
}
.stat .stat-num { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .stat-label { font-size: .74rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 40px 0 16px; gap: 12px; }
.section-title h2 { font-size: .9rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .12em; font-weight: 800; margin: 0; }
.section-title .section-sub { font-size: .82rem; color: var(--text-dim); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }

.module-card {
  --card-accent: var(--primary);
  position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 40%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  text-align: left;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 170px;
  overflow: hidden;
  isolation: isolate;
}
.module-card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--card-accent), transparent 85%);
  opacity: .9;
}
.module-card::after {
  content: "";
  position: absolute; width: 160px; height: 160px; right: -60px; top: -60px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--card-accent) 35%, transparent), transparent 70%);
  z-index: -1;
}
.module-card:hover:not(.is-locked) { transform: translateY(-4px); border-color: var(--primary-light); box-shadow: var(--glow); }
.module-card.is-locked { cursor: not-allowed; opacity: .55; filter: saturate(.4); }
.module-card .card-emoji { font-size: 1.9rem; line-height: 1; }
.module-card .card-title { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.module-card .card-tagline { font-size: .8rem; color: var(--text-dim); line-height: 1.4; }
.module-card .card-index { font-size: .7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.module-card .card-status { margin-top: auto; font-size: .8rem; font-weight: 700; display: flex; align-items: center; gap: 6px; padding-top: 8px; }
.status-passed { color: var(--success); }
.status-unlocked { color: var(--accent); }
.status-locked { color: var(--locked); }
.card-score { font-size: .74rem; color: var(--text-dim); }

.special-card { border: 1px dashed var(--primary-light); background: linear-gradient(160deg, rgba(124, 108, 255, .16), var(--surface)); }
.special-card.is-locked { border-style: dashed; border-color: var(--border); }

/* ---------- Module content page ---------- */
.module-header { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.module-header .emoji-badge {
  font-size: 2.1rem;
  background: linear-gradient(135deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  width: 66px; height: 66px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.module-header h1 { margin-bottom: 2px; }
.module-kicker { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: var(--text-dim); font-weight: 800; }
.module-tagline { color: var(--text-dim); margin-top: 2px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 18px; color: var(--text-dim); text-decoration: none; font-size: .9rem; }
.back-link:hover { color: var(--text); }

.content-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  margin-bottom: 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset;
}
.content-block h3 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  margin-bottom: 14px;
}
.content-block p { font-size: 1.02rem; }
.content-block.history { border-left: 4px solid #8e6bff; }
.content-block.scenario { border-left: 4px solid var(--accent); background: linear-gradient(160deg, rgba(255, 184, 77, .08), var(--surface)); }
.content-block.funfacts { border-left: 4px solid var(--success); }
.content-block ul { margin: 0; padding-left: 1.2em; }
.content-block li { margin-bottom: 10px; }

.content-block.has-side-media {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr);
  gap: 26px;
  align-items: start;
}
@media (max-width: 820px) { .content-block.has-side-media { grid-template-columns: 1fr; } }
.lesson-media { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 84px; }
@media (max-width: 820px) { .lesson-media { position: static; } }

/* Key terms */
.terms { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 6px 0 4px; }
.term {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: .86rem;
}
.term dt { font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.term dd { margin: 0; color: var(--text-dim); line-height: 1.45; }

/* Timeline */
.timeline { list-style: none; margin: 18px 0 4px 6px; padding: 0 0 0 22px; border-left: 2px solid var(--border-strong); position: relative; }
.timeline li { position: relative; margin-bottom: 12px; font-size: .94rem; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.timeline li::before {
  content: ""; position: absolute; left: -29px; top: .45em; width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary-light); box-shadow: 0 0 0 4px rgba(124, 108, 255, .18);
}
.timeline .tl-year {
  font-weight: 800; font-size: .76rem; letter-spacing: .03em; color: var(--accent);
  background: rgba(255, 184, 77, .12); border: 1px solid rgba(255, 184, 77, .35);
  border-radius: 6px; padding: 1px 7px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.timeline .tl-text { color: var(--text); flex: 1; min-width: 200px; }

.scenario-reveal-btn { margin-top: 10px; }
.scenario-answer {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: none;
}
.scenario-answer.is-visible { display: block; }

.module-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 30px; gap: 12px; flex-wrap: wrap; }

/* ---------- Quiz ---------- */
.quiz-wrap { max-width: 700px; margin: 0 auto; }
.quiz-progress { display: flex; gap: 6px; margin-bottom: 18px; }
.quiz-dot { flex: 1; height: 6px; border-radius: 4px; background: var(--border); transition: background .25s ease; }
.quiz-dot.is-done { background: var(--primary-light); }
.quiz-dot.is-current { background: var(--accent); }
.quiz-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.quiz-meta { font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim); font-weight: 800; margin-bottom: 8px; }
.quiz-question { font-size: 1.18rem; font-weight: 800; margin-bottom: 20px; letter-spacing: -.01em; }
.quiz-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  color: var(--text);
  cursor: pointer;
  font-size: .98rem;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.quiz-choice:hover:not(:disabled) { border-color: var(--primary-light); transform: translateX(2px); }
.quiz-choice:disabled { cursor: default; }
.quiz-choice .choice-key {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  font-size: .75rem; font-weight: 800; background: var(--surface-raised); color: var(--text-dim); border: 1px solid var(--border);
}
.quiz-choice.is-correct { border-color: var(--success); background: rgba(52, 211, 153, .14); }
.quiz-choice.is-correct .choice-key { background: var(--success); color: #05281a; border-color: var(--success); }
.quiz-choice.is-wrong { border-color: var(--danger); background: rgba(255, 93, 115, .14); }
.quiz-choice.is-wrong .choice-key { background: var(--danger); color: #fff; border-color: var(--danger); }
.quiz-explain { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--bg-soft); border: 1px solid var(--border); font-size: .95rem; }
.quiz-explain.correct { border-color: var(--success); }
.quiz-explain.wrong { border-color: var(--danger); }
.quiz-footer { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.quiz-hint { font-size: .74rem; color: var(--text-dim); }

.quiz-result { text-align: center; }
.quiz-result .result-emoji { font-size: 2.4rem; }
.quiz-result .big-score { font-size: 3.6rem; font-weight: 900; margin: 6px 0; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.quiz-result .big-score.pass { color: var(--success); }
.quiz-result .big-score.fail { color: var(--danger); }
.quiz-result .result-actions { display: flex; gap: 12px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

/* ---------- Builder ---------- */
.builder-layout { display: grid; grid-template-columns: 1.45fr 1fr; gap: 20px; }
@media (max-width: 820px) { .builder-layout { grid-template-columns: 1fr; } }

.case-board {
  background:
    linear-gradient(rgba(255, 255, 255, .03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .03) 1px, transparent 1px),
    var(--surface);
  background-size: 18px 18px, 18px 18px, auto;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    "cpu    cooler ram"
    "m2ssd  m2ssd  ram"
    "mobo   mobo   mobo"
    "gpu    gpu    psu"
    "cables cables cables";
  gap: 12px;
  align-content: start;
  position: relative;
}
.case-board::before {
  content: "VIRTUAL MID-TOWER CASE — side panel off";
  position: absolute; top: -11px; left: 18px;
  font-size: .64rem; font-weight: 800; letter-spacing: .12em; color: var(--text-dim);
  background: var(--bg); padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border);
}
.drop-zone[data-zone="cpu"] { grid-area: cpu; }
.drop-zone[data-zone="ram"] { grid-area: ram; }
.drop-zone[data-zone="m2ssd"] { grid-area: m2ssd; }
.drop-zone[data-zone="cooler"] { grid-area: cooler; }
.drop-zone[data-zone="mobo"] { grid-area: mobo; }
.drop-zone[data-zone="psu"] { grid-area: psu; }
.drop-zone[data-zone="gpu"] { grid-area: gpu; }
.drop-zone[data-zone="cables"] { grid-area: cables; }

.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 92px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  font-size: .8rem;
  color: var(--text-dim);
  background: rgba(10, 13, 31, .35);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
  cursor: pointer;
}
.drop-zone:hover { border-color: var(--primary-light); }
.drop-zone.drag-over { border-color: var(--primary-light); background: rgba(124, 108, 255, .14); transform: scale(1.01); }
.drop-zone.is-filled { border-style: solid; border-color: var(--success); background: rgba(52, 211, 153, .08); color: var(--text); cursor: default; }
.drop-zone .zone-label { font-weight: 800; text-transform: uppercase; letter-spacing: .06em; font-size: .68rem; }
.drop-zone .zone-ghost { font-size: 1.4rem; opacity: .35; filter: grayscale(1); }
.drop-zone .zone-part { font-size: 1.7rem; }

.parts-tray {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.parts-tray-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: var(--text-dim); font-weight: 800; margin: 2px 2px 6px; }
.part-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: grab;
  font-weight: 700;
  font-size: .9rem;
  transition: border-color .15s ease, transform .15s ease;
  user-select: none;
}
.part-chip:hover { border-color: var(--primary-light); transform: translateX(2px); }
.part-chip:active { cursor: grabbing; }
.part-chip.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 184, 77, .35); }
.part-chip.is-placed { opacity: .3; pointer-events: none; text-decoration: line-through; }
.part-chip .part-emoji { font-size: 1.3rem; }
.part-chip .part-sub { font-size: .72rem; color: var(--text-dim); font-weight: 600; margin-left: auto; }

.builder-feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  min-height: 24px;
  font-size: .9rem;
}
.builder-feedback.good { border-color: var(--success); color: var(--success); }
.builder-feedback.bad { border-color: var(--danger); color: var(--danger); }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: none; }
.checklist input[type="checkbox"] { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--success); flex-shrink: 0; }
.checklist .step-title { font-weight: 800; }
.checklist .step-note { color: var(--text-dim); font-size: .9rem; margin-top: 2px; }

.locked-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}
.locked-banner .big-emoji { font-size: 3rem; margin-bottom: 10px; }

/* ---------- Module page stepper / pagination ---------- */
.page-stepper { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 20px; padding-bottom: 4px; scrollbar-width: thin; }
.page-tab {
  flex: 1;
  min-width: 96px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.page-tab .tab-num { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: .62rem; background: var(--surface-raised); border: 1px solid var(--border); }
.page-tab:hover { border-color: var(--primary-light); color: var(--text); }
.page-tab.is-active { border-color: var(--primary-light); color: var(--text); background: rgba(124, 108, 255, .18); }
.page-tab.is-active .tab-num { background: var(--primary); border-color: var(--primary); color: #fff; }

.page-pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 26px; gap: 12px; flex-wrap: wrap; }
.page-counter { color: var(--text-dim); font-size: .85rem; font-variant-numeric: tabular-nums; }

/* ---------- Media: real photos ---------- */
.media-figure { margin: 16px 0 0; text-align: center; }
.has-side-media .media-figure { margin-top: 0; }
.media-figure img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 340px;
  aspect-ratio: var(--ar, 4 / 3);
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  content-visibility: auto;
}
.media-figure.fit-contain img { object-fit: contain; padding: 6px; }
.media-link { display: block; border-radius: var(--radius-sm); transition: transform .18s ease, box-shadow .18s ease; }
.media-link:hover { transform: translateY(-2px); box-shadow: var(--glow); }
.media-figure figcaption { margin-top: 8px; font-size: .78rem; color: var(--text-dim); line-height: 1.45; }
.media-figure figcaption .credit { color: var(--text-dim); text-decoration: underline; text-underline-offset: 2px; opacity: .8; white-space: nowrap; }
.media-figure.is-broken img, .media-figure.is-broken .media-link { display: none; }
.media-figure.is-broken::before { content: "Photo unavailable (offline?)"; display: block; padding: 24px; border: 1px dashed var(--border); border-radius: var(--radius-sm); color: var(--text-dim); font-size: .8rem; }
.media-row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.media-row .media-figure { flex: 1 1 240px; max-width: 360px; }

.shop-btn {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff9a3c, var(--newegg));
  color: #2a1200;
  font-weight: 800;
  font-size: .8rem;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(245, 130, 32, .3);
  transition: transform .15s ease, box-shadow .15s ease;
}
.shop-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(245, 130, 32, .42); }
.shop-btn .shop-arrow { font-size: .9em; opacity: .8; }

/* ---------- Media: custom animated diagrams ---------- */
.diagram-box {
  margin: 16px 0 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  contain: content;
}
.diagram-svg { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; }
.diagram-note { margin: 10px 0 0; font-size: .84rem; color: var(--text-dim); line-height: 1.5; }

/* All diagram motion is transform/opacity only. Off-screen diagrams get
   .is-paused from app.js (IntersectionObserver) so they cost nothing. */
.diagram-svg.is-paused * { animation-play-state: paused !important; }

.anim-travel { animation: d-travel var(--dur, 2.4s) linear infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-travel {
  0% { transform: translate(0, 0); opacity: 0; }
  12% { opacity: 1; }
  88% { opacity: 1; }
  100% { transform: translate(var(--dx, 0px), var(--dy, 0px)); opacity: 0; }
}
.anim-blink { animation: d-blink var(--dur, 2s) ease-in-out infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-blink { 0%, 100% { opacity: 0; } 50% { opacity: .9; } }
.anim-flash { animation: d-flash var(--dur, 1.6s) ease-in-out infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-flash { 0%, 100% { opacity: 0; } 45%, 55% { opacity: .85; } }
.anim-seq { animation: d-seq var(--dur, 4s) linear infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-seq { 0% { opacity: .9; } 18% { opacity: .9; } 26%, 100% { opacity: 0; } }
/* Spinning groups sit inside a static <g transform="translate(cx cy)"> parent, so rotating
   about the local origin (0 0) spins them in place. (A CSS transform would otherwise
   override an SVG transform attribute on the same element.) */
.anim-spin { animation: d-spin var(--dur, 1s) linear infinite; transform-box: view-box; transform-origin: 0 0; }
@keyframes d-spin { to { transform: rotate(360deg); } }
.anim-sweep { animation: d-sweep 1.9s ease-in-out infinite; }
@keyframes d-sweep { 0%, 100% { transform: rotate(-16deg); } 50% { transform: rotate(14deg); } }
.anim-rise { animation: d-rise var(--dur, 2s) ease-out infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-rise { 0% { transform: translateY(0); opacity: .9; } 100% { transform: translateY(var(--dy, -80px)); opacity: 0; } }
.anim-flow { animation: d-flow var(--dur, 1.5s) ease-in-out infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-flow { 0% { transform: translateX(0); opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { transform: translateX(var(--dx, 40px)); opacity: 0; } }
.anim-io-step { animation: d-io-step 7s ease-in-out infinite; }
@keyframes d-io-step {
  0%, 8% { transform: translateX(0); opacity: 1; }
  22%, 32% { transform: translateX(100px); }
  46%, 56% { transform: translateX(200px); }
  70%, 84% { transform: translateX(300px); opacity: 1; }
  92% { transform: translateX(300px); opacity: 0; }
  100% { transform: translateX(0); opacity: 0; }
}
.anim-instr { animation: d-instr 6s ease-in-out infinite; animation-delay: var(--delay, 0s); opacity: 0; }
@keyframes d-instr {
  0% { transform: translateX(0); opacity: 0; }
  5% { opacity: 1; }
  20% { transform: translateX(0); }
  25%, 45% { transform: translateX(96px); }
  50%, 70% { transform: translateX(192px); }
  75%, 93% { transform: translateX(288px); opacity: 1; }
  100% { transform: translateX(288px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .diagram-svg * { animation: none !important; }
  .anim-travel, .anim-blink, .anim-flash, .anim-seq, .anim-rise, .anim-flow, .anim-instr { opacity: .75; }
  .anim-io-step { opacity: 1; }
  .btn, .module-card, .quiz-choice, .part-chip, .media-link, .shop-btn { transition: none; }
}


/* =====================================================================
   Accounts, dialogs, toasts, certificate, celebration
   ===================================================================== */
[hidden] { display: none !important; }
.boot-loading { text-align: center; color: var(--text-dim); padding: 120px 0; }
.grad { background: linear-gradient(90deg, var(--primary-light), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.btn-lg { padding: 15px 28px; font-size: 1.06rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { box-shadow: 0 8px 22px rgba(255, 93, 115, .4); }
.btn-danger-ghost { background: transparent; border: 1px solid var(--danger); color: var(--danger); white-space: nowrap; }
.btn-danger-ghost:hover { background: rgba(255, 93, 115, .12); box-shadow: none; }

/* ---------- Header: account chip + sync status ---------- */
.header-user { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text);
  padding: 5px 12px 5px 5px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 700; font-size: .86rem; max-width: 190px; transition: border-color .15s ease;
}
.user-chip:hover { border-color: var(--primary-light); }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-avatar, .avatar {
  display: grid; place-items: center; border-radius: 50%; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--primary), #3f2fb8);
}
.user-avatar { width: 28px; height: 28px; font-size: .8rem; flex-shrink: 0; }
.sync-status { font-size: .74rem; font-weight: 700; color: var(--text-dim); white-space: nowrap; }
.sync-status.is-saved { color: var(--success); }
.sync-status.is-saving { color: var(--text-dim); }
.sync-status.is-offline, .sync-status.is-error { color: var(--accent); }
@media (max-width: 720px) {
  .header-inner { gap: 10px; padding: 10px 14px; }
  .brand-text { display: none; }
  .sync-status { display: none; }
  .header-progress-label { display: none; }
}

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .82rem; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; }
.field small { font-weight: 600; opacity: .8; }
input:not([type]), input[type="text"], input[type="password"] {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--bg-soft); color: var(--text); font: inherit;
}
input:not([type]):focus, input[type="text"]:focus, input[type="password"]:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(124, 108, 255, .3); }
.check { display: flex; align-items: center; gap: 8px; font-size: .84rem; color: var(--text-dim); margin: -4px 0 14px; cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.form-error { color: var(--danger); font-size: .88rem; font-weight: 600; min-height: 1.3em; margin-bottom: 10px; }
.field-hint { color: var(--accent); font-size: .82rem; margin-top: 8px; }
.field-hint:empty { display: none; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 240px; min-width: 0; }
.name-panel .inline-form .btn { flex: 0 0 auto; }
@media (max-width: 640px) { .name-panel .inline-form .btn { flex: 1 1 100%; } }
.stack-form { max-width: 420px; margin-top: 14px; }

/* ---------- Sign in / create account ---------- */
.auth-wrap { display: grid; place-items: center; padding: 20px 0 40px; }
.auth-card {
  width: min(460px, 100%); background: linear-gradient(180deg, rgba(255, 255, 255, .03), transparent 40%), var(--surface);
  border: 1px solid var(--border-strong); border-radius: 24px; padding: 34px 30px 28px; box-shadow: var(--shadow); text-align: center;
}
.auth-card h1 { font-size: 1.9rem; margin-bottom: 4px; }
.auth-logo {
  width: 64px; height: 64px; margin: 0 auto 14px; display: grid; place-items: center; font-size: 1.9rem; border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), #3f2fb8); box-shadow: 0 10px 28px rgba(124, 108, 255, .4);
}
.auth-sub { color: var(--text-dim); margin-bottom: 22px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 14px; margin-bottom: 20px; }
.auth-tab { border: 0; background: transparent; color: var(--text-dim); padding: 10px; border-radius: 10px; font-weight: 800; font-size: .9rem; cursor: pointer; }
.auth-tab.is-active { background: var(--surface-raised); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, .08) inset; }
.auth-notice { background: rgba(124, 108, 255, .14); border: 1px solid rgba(124, 108, 255, .4); border-radius: 12px; padding: 10px 12px; font-size: .88rem; margin-bottom: 16px; }
.auth-card form { text-align: left; }
.auth-help { margin: 18px 0 0; font-size: .82rem; color: var(--text-dim); text-align: left; line-height: 1.55; }
.auth-help code { background: var(--bg-soft); padding: 1px 5px; border-radius: 5px; }

/* ---------- Account page ---------- */
.account-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.avatar { width: 64px; height: 64px; font-size: 1.7rem; flex-shrink: 0; box-shadow: var(--shadow); }
.account-head h1 { margin-bottom: 2px; }
.stats-left { margin-left: 0; max-width: none; }
.stat-of { color: var(--text-dim); font-size: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px; }
.panel h2 { font-size: 1.05rem; margin-bottom: 6px; }
.panel-note { color: var(--text-dim); font-size: .9rem; margin-bottom: 12px; }
.panel-danger { border-color: rgba(255, 93, 115, .45); background: linear-gradient(160deg, rgba(255, 93, 115, .07), var(--surface)); }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 0; border-top: 1px solid var(--border); }
.danger-row:first-of-type { border-top: 0; }
.danger-row .panel-note { margin: 4px 0 0; }
@media (max-width: 640px) { .danger-row { flex-direction: column; align-items: flex-start; } }
.disclosure summary { cursor: pointer; font-weight: 700; color: var(--primary-light); }

/* ---------- Dialog + toasts ---------- */
dialog.dialog {
  padding: 0; border: 1px solid var(--border-strong); border-radius: 20px; background: var(--surface); color: var(--text);
  width: min(460px, calc(100% - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog.dialog::backdrop { background: rgba(5, 7, 20, .72); backdrop-filter: blur(3px); }
.dialog-form { padding: 24px; }
.dialog-form h2 { font-size: 1.25rem; }
.dialog-body { color: var(--text-dim); font-size: .95rem; margin-bottom: 16px; }
.dialog-body strong { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 10px; align-items: center; width: min(520px, calc(100% - 28px)); pointer-events: none; }
.toast {
  background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: 14px; padding: 12px 16px; font-size: .92rem; font-weight: 600;
  box-shadow: var(--shadow); pointer-events: auto; animation: toast-in .25s ease both; text-align: center;
}
.toast-success { border-color: var(--success); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity .3s ease, transform .3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Pass celebration ---------- */
.confetti-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
.victory { position: relative; text-align: center; padding: 26px 0 30px; isolation: isolate; }
.victory::before {
  content: ""; position: absolute; left: 50%; top: -10px; width: 520px; height: 520px; margin-left: -260px; z-index: -1;
  background: radial-gradient(circle, rgba(255, 184, 77, .28), rgba(124, 108, 255, .14) 45%, transparent 70%);
}
.victory-trophy { font-size: 5.6rem; line-height: 1; display: inline-block; animation: trophy-pop .9s cubic-bezier(.2, 1.4, .4, 1) both, trophy-float 3.2s ease-in-out .9s infinite; filter: drop-shadow(0 12px 24px rgba(255, 184, 77, .45)); }
@keyframes trophy-pop { from { transform: scale(.2) rotate(-18deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes trophy-float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
.victory-kicker { margin-top: 6px; font-size: .78rem; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: var(--accent); }
.victory h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); margin: 6px 0 4px; }
.victory-score { font-weight: 900; font-size: clamp(3.4rem, 10vw, 6rem); line-height: 1; letter-spacing: -.04em; color: var(--success); font-variant-numeric: tabular-nums; }
.victory-score small { font-size: .45em; margin-left: 2px; }
.victory p { max-width: 640px; margin: 10px auto 0; color: var(--text-dim); font-size: 1.05rem; }
.victory p strong { color: var(--text); }
.victory-banner {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin: 0 auto 22px; padding: 18px 22px; border-radius: var(--radius);
  border: 1px solid rgba(255, 184, 77, .5); background: linear-gradient(120deg, rgba(255, 184, 77, .16), rgba(124, 108, 255, .12));
}
.victory-banner-trophy { font-size: 2.6rem; }
.victory-banner-text { flex: 1 1 260px; }
.victory-banner h2 { margin: 0 0 2px; font-size: 1.25rem; }
.victory-banner p { margin: 0; color: var(--text-dim); font-size: .94rem; }

/* ---------- Certificate preview (scales like the PDF: 1cqw = 1% of its width) ---------- */
.name-panel label { display: block; margin-bottom: 8px; }
.cert-sheet {
  container-type: inline-size; position: relative; aspect-ratio: 792 / 612; width: 100%; max-width: 880px; margin: 0 auto 22px;
  background: #fdf8e9; color: #1c1a3d; font-family: "Times New Roman", Times, "Liberation Serif", serif; box-shadow: var(--shadow); border-radius: 4px;
}
.cert-inner { position: absolute; inset: 3.03cqw; border: .76cqw solid #332994; display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 5.6cqw; }
.cert-inner::before { content: ""; position: absolute; inset: 1.6cqw; border: .2cqw solid #c29a33; pointer-events: none; }
.cert-inner::after { content: ""; position: absolute; inset: 2.3cqw; border: .06cqw solid #c29a33; pointer-events: none; }
.cert-chip { font-size: 3.4cqw; line-height: 1; }
.cert-academy { margin-top: 1.1cqw; font: 700 1.64cqw/1 Helvetica, Arial, sans-serif; letter-spacing: .3em; text-transform: uppercase; color: #332994; padding-left: .3em; }
.cert-title { margin: 1.9cqw 0 0; font-size: 5.8cqw; line-height: 1.05; font-weight: 700; color: #332994; }
.cert-rule { position: relative; width: 28cqw; height: .2cqw; margin: 1.4cqw 0 0; background: linear-gradient(90deg, #c29a33 0 44%, transparent 44% 56%, #c29a33 56%); }
.cert-rule span { position: absolute; left: 50%; top: 50%; width: 1.1cqw; height: 1.1cqw; background: #c29a33; transform: translate(-50%, -50%) rotate(45deg); }
.cert-lead { margin: 2.6cqw 0 0; font-size: 2.4cqw; font-style: italic; color: #615c75; }
.cert-name { margin-top: 1.1cqw; padding: 0 4cqw .4cqw; min-width: 24cqw; max-width: 80cqw; font-size: 5.8cqw; line-height: 1.15; font-style: italic; font-weight: 700; color: #1c1a3d; border-bottom: .16cqw solid #c29a33; overflow-wrap: anywhere; }
.cert-body { margin: 2.4cqw 0 0; max-width: 73cqw; font-size: 1.96cqw; line-height: 1.37; }
.cert-score { margin: 1.4cqw 0 0; font: 700 1.58cqw/1 Helvetica, Arial, sans-serif; color: #332994; }
.cert-foot { position: absolute; left: 8cqw; right: 8cqw; bottom: 6.2cqw; display: flex; align-items: flex-end; justify-content: space-between; }
.cert-foot-item { position: relative; display: flex; flex-direction: column; align-items: center; width: 22.5cqw; padding-bottom: .3cqw; border-bottom: .13cqw solid #c29a33; }
.cert-foot-val { font-size: 1.9cqw; padding-bottom: .5cqw; }
.cert-foot-val.cert-id { font: 700 1.58cqw Helvetica, Arial, sans-serif; padding-top: .35cqw; padding-bottom: .65cqw; }
.cert-foot-lab { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: .8cqw; white-space: nowrap; font: 1.02cqw Helvetica, Arial, sans-serif; letter-spacing: .2em; text-transform: uppercase; color: #615c75; }
.cert-seal {
  width: 11.5cqw; height: 11.5cqw; margin-bottom: -1.2cqw; display: grid; place-items: center; border-radius: 50%; font-size: 6cqw; color: #fdf8e9;
  background: radial-gradient(circle at 35% 30%, #e6c46a, #c29a33 55%, #9a7414); box-shadow: 0 0 0 .5cqw #c29a33, 0 .8cqw 1.6cqw rgba(0, 0, 0, .25); outline: .3cqw solid #fdf8e9; outline-offset: -1.4cqw;
}
.cert-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 0 0 26px; }

@media print {
  @page { size: letter landscape; margin: 0; }
  .site-header, .site-footer, .toasts, .no-print, .confetti-canvas { display: none !important; }
  html, body { background: #fff !important; }
  .app-main { padding: 0 !important; max-width: none !important; min-height: 0 !important; }
  .cert-sheet { max-width: none; width: 100vw; margin: 0; box-shadow: none; border-radius: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .cert-sheet * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) {
  .victory-trophy { animation: none; }
  .toast { animation: none; }
}
