/* Vector Vault: self-contained module stylesheet.
   Inherits root tokens/topbar from ../styles.css, then defines its own identity. */
@import url("../styles.css");

:root {
  --indigo: #466f96;
  --indigo-2: #355877;
  --indigo-soft: #e7eddc;
  --indigo-line: #cdd9c2;
}

/* ---- topbar mark tinted indigo ---- */
.mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  background: linear-gradient(135deg, var(--indigo), var(--indigo-2));
  box-shadow: 0 6px 16px rgba(70, 111, 150, .35);
}
.topbar nav a:hover { color: var(--indigo); }

/* ---- shared element styling ---- */
button, textarea, select, input { font: inherit; }
button { cursor: pointer; }
canvas {
  display: block;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
code {
  background: var(--indigo-soft);
  color: #2f4d68;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: .92em;
}

main { max-width: 1100px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }

/* ===== sticky level rail ===== */
.level-rail {
  position: fixed;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 10px;
  border: 1px solid var(--indigo-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.level-rail a {
  position: relative;
  padding: 8px 12px 8px 16px;
  border-radius: 9px;
  font-size: .82rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
  transition: background .25s, color .25s, transform .25s;
}
.level-rail a::before {
  content: "";
  position: absolute;
  left: 4px; top: 50%;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--indigo-line);
  transform: translateY(-50%);
  transition: background .25s, box-shadow .25s;
}
.level-rail a.active {
  color: var(--indigo);
  background: var(--indigo-soft);
  transform: translateX(2px);
}
.level-rail a.active::before {
  background: var(--indigo);
  box-shadow: 0 0 0 4px rgba(70, 111, 150, .18);
}

/* ===== hero ===== */
.hero {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  gap: clamp(28px, 5vw, 64px);
  align-items: center;
  padding: clamp(40px, 6vw, 80px) 0 clamp(30px, 4vw, 56px);
}
.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5.4vw, 4.4rem);
  line-height: 1.04;
  background: linear-gradient(120deg, #243b2f, var(--indigo) 60%, var(--indigo-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .lead { margin: 18px 0; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 26px; }

.outcomes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 18px;
  border: 1px solid var(--indigo-line);
  border-radius: 12px;
  background: var(--indigo-soft);
}
.outcomes strong { flex: 1 0 100%; margin-bottom: 4px; }
.outcomes span {
  padding: 5px 11px;
  border-radius: 20px;
  background: #fff;
  border: 1px solid var(--indigo-line);
  font-size: .82rem;
  font-weight: 750;
  color: #2f4d68;
}

.hero-visual { position: relative; }
.hero-visual canvas { aspect-ratio: 16 / 11; }
.vault-badge {
  position: absolute;
  left: 14px; bottom: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 30px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--indigo-line);
  font-size: .8rem;
  font-weight: 800;
  color: var(--indigo);
}
.vault-badge span {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--indigo);
  box-shadow: 0 0 0 4px rgba(70, 111, 150, .2);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ===== buttons ===== */
.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px;
  border: 1px solid var(--indigo-line);
  border-radius: 9px;
  padding: 0 18px;
  background: #fff;
  color: var(--indigo);
  font-weight: 800;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.button:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(70,111,150,.2); }
.button.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--indigo), var(--indigo-2));
}

/* ===== levels ===== */
.level {
  padding: clamp(40px, 6vw, 72px) 0;
  border-top: 1px solid var(--line);
  scroll-margin-top: 70px;
}
.level-head { max-width: 760px; margin-bottom: 28px; }
.level-head h2 {
  margin: 6px 0 12px;
  font-size: clamp(1.7rem, 4vw, 2.9rem);
  line-height: 1.08;
}
/* reveal on scroll */
.level .panel, .level .math-card, .level .concept > * {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .6s ease, transform .6s ease;
}
.level.in-view .panel,
.level.in-view .math-card,
.level.in-view .concept > * { opacity: 1; transform: none; }

/* ===== panels ===== */
.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: clamp(18px, 3vw, 26px);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 10px; font-size: 1.25rem; }
.panel p { color: var(--muted); line-height: 1.65; }
.panel p strong, .panel li strong { color: var(--ink); }
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-title h3 { margin: 0; }
.tag {
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--indigo-soft);
  color: var(--indigo);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.concept {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 22px;
  margin-bottom: 22px;
}
.explain-card.wide { margin-bottom: 22px; }

.callout {
  margin-top: 14px;
  padding: 12px 16px;
  border-left: 4px solid var(--indigo);
  border-radius: 0 10px 10px 0;
  background: var(--indigo-soft);
  color: #2f4d68 !important;
  font-size: .95rem;
}

/* concept SVGs */
.diagram-card { display: flex; flex-direction: column; }
.concept-svg { width: 100%; height: auto; margin: auto 0; }
.svg-lbl { font: 800 12px Inter, system-ui, sans-serif; fill: var(--ink); }
.cap { margin-top: 8px; font-size: .9rem; }

/* labs */
.lab { margin-bottom: 22px; }
.lab .hint { margin-top: 0; color: var(--muted); }
.lab canvas { aspect-ratio: 16 / 9; margin: 14px 0; }
.lab-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  font-weight: 800;
}
.readout div, .metric-grid div {
  padding: 10px 12px;
  border: 1px solid var(--indigo-line);
  border-radius: 10px;
  background: var(--indigo-soft);
  text-align: center;
}
.readout small, .metric-grid small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.readout b, .metric-grid b { font-size: 1.2rem; color: var(--indigo); }

.sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.sliders label, .search-controls label, .cos-demo label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: .9rem;
}
.sliders input[type=range], .search-controls input[type=range] { flex: 1; accent-color: var(--indigo); }
.sliders output, .search-controls output { min-width: 38px; font-weight: 800; color: var(--indigo); }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

/* worked examples */
.worked { margin-bottom: 4px; border-left: 4px solid var(--indigo-2); }
.example-list { margin: 8px 0; padding-left: 20px; color: var(--muted); line-height: 1.9; }

/* ===== math cards ===== */
.math-card {
  margin: 0 0 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.math-render {
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--indigo-soft), #fff);
  border-bottom: 1px solid var(--line);
  text-align: center;
  font-size: 1.05rem;
  overflow-x: auto;
}
.math-card figcaption { padding: 18px 22px; }
.math-card figcaption p { color: var(--muted); line-height: 1.65; margin: 0 0 12px; }
.math-card figcaption p strong { color: var(--ink); }
.legend { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 6px; }
.legend li {
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--indigo-soft);
  color: var(--ink);
  font-size: .92rem;
}
.legend li strong { color: var(--indigo); }
.micro { font-size: .85rem; font-style: italic; }

.cos-demo canvas { aspect-ratio: 2 / 1; margin: 10px 0; }
.cos-demo input[type=range] { flex: 1; accent-color: var(--indigo); }
.metric { font-weight: 800; color: var(--indigo); margin: 4px 0 0; }

/* ===== expert search ===== */
.search-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
}
.search-controls select {
  padding: 8px 12px;
  border: 1px solid var(--indigo-line);
  border-radius: 9px;
  background: #fff;
  font-weight: 750;
}
.rank-list { margin: 14px 0 0; padding-left: 22px; }
.rank-list li {
  padding: 7px 12px;
  margin-bottom: 7px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 750;
  transition: background .3s, border-color .3s;
}
.rank-list li.top { background: var(--indigo-soft); border-color: var(--indigo); }
.rank-list .score { float: right; color: var(--indigo); font-weight: 800; }

/* code card */
.code-card { margin-bottom: 22px; }
.code-block {
  margin: 0;
  padding: 16px;
  border-radius: 10px;
  background: #1f2a22;
  color: #dde5cf;
  overflow-x: auto;
  font-size: .86rem;
  line-height: 1.55;
}
.code-block code { background: none; color: inherit; padding: 0; }
.code-explanation { margin-top: 12px; }
.code-explanation p {
  padding: 9px 12px;
  margin: 0 0 8px;
  border-radius: 8px;
  background: var(--indigo-soft);
  color: var(--ink);
}
.code-explanation strong { color: var(--indigo); }

/* quiz */
.quiz .q { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px dashed var(--line); }
.quiz .q:last-of-type { border-bottom: none; }
.q-text { font-weight: 800; color: var(--ink) !important; margin: 0 0 10px; }
.opts { display: flex; flex-wrap: wrap; gap: 10px; }
.opts button {
  padding: 9px 14px;
  border: 1px solid var(--indigo-line);
  border-radius: 9px;
  background: #fff;
  font-weight: 750;
  transition: background .2s, border-color .2s, transform .15s;
}
.opts button:hover { transform: translateY(-2px); border-color: var(--indigo); }
.opts button.correct { background: #d9f5ec; border-color: var(--green); color: #0a5b49; }
.opts button.wrong { background: #fbe0e9; border-color: var(--rose); color: #8a1d44; }
.opts button:disabled { cursor: default; }
.feedback { margin: 10px 0 0; font-weight: 750; min-height: 1.2em; }
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--rose); }

/* footer + back to top */
footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px clamp(16px, 4vw, 40px);
  border-top: 1px solid var(--line);
  color: var(--muted);
}
footer a { font-weight: 800; color: var(--indigo); }

.back-to-top {
  position: fixed;
  right: 18px; bottom: 18px;
  z-index: 25;
  padding: 10px 14px;
  border: none;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--indigo), var(--indigo-2));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(70,111,150,.4);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .3s, transform .3s;
}
.back-to-top.show { opacity: 1; pointer-events: auto; transform: none; }

/* ===== responsive ===== */

/* Tablet/laptop: tighten the two-column concept grid before it gets cramped */
@media (max-width: 1024px) {
  .concept { gap: 18px; }
  .level { scroll-margin-top: 64px; }
}

/* Below 980px the fixed vertical side-rail would crowd/cover content: turn it
   into a compact, horizontally scrollable in-flow bar. Stays usable, never
   overflows the viewport, never covers content. */
@media (max-width: 980px) {
  .level-rail {
    position: static;
    top: auto;
    left: auto;
    transform: none;
    z-index: 9;
    flex-direction: row;
    gap: 6px;
    margin: 10px auto 0;
    padding: 8px;
    border-radius: 12px;
    width: calc(100% - 32px);
    max-width: 1100px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(255, 255, 255, .92);
  }
  .level-rail a {
    flex: 0 0 auto;
    padding: 7px 12px;
    font-size: .78rem;
  }
  .level-rail a::before { display: none; }
  .level-rail a.active { transform: none; }
  /* sections clear the sticky topbar */
  .level { scroll-margin-top: 60px; }
}

@media (max-width: 860px) {
  .hero, .concept { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .hero-visual canvas { aspect-ratio: 16 / 10; }
  /* stacked topbar is taller, give anchors more clearance */
  .level { scroll-margin-top: 116px; }
}

/* Phones: single-column widgets, reflowed metric grids, tighter type */
@media (max-width: 640px) {
  main { padding: 0 16px; }
  .level { padding: 36px 0; }
  .level-head { margin-bottom: 22px; }

  /* metric / readout grids collapse to a comfortable 2-up, then 1-up lower down */
  .readout,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .readout b, .metric-grid b { font-size: 1.05rem; }

  /* sliders / search controls stack so labels + ranges never overflow */
  .sliders { grid-template-columns: 1fr; gap: 12px; }
  .search-controls { gap: 12px; }
  .search-controls label { flex: 1 1 100%; }
  .search-controls select { width: 100%; }

  .panel { padding: 18px; }
  .panel h3 { font-size: 1.15rem; }
  .lab canvas { aspect-ratio: 4 / 3; }
}

@media (max-width: 480px) {
  main { padding: 0 14px; }
  .level { padding: 30px 0; }

  .hero { padding: 28px 0 20px; }
  .hero h1 { font-size: clamp(1.9rem, 8.5vw, 2.6rem); }
  .hero-actions { gap: 10px; }
  .hero-actions .button { flex: 1 1 100%; }

  .level-head h2 { font-size: clamp(1.5rem, 7vw, 2rem); }

  /* every metric/readout grid + ranking goes single column */
  .readout,
  .metric-grid { grid-template-columns: 1fr; }

  .panel-title { flex-wrap: wrap; }
  .panel { padding: 16px; }

  .math-render { padding: 18px 12px; font-size: .98rem; }
  .math-card figcaption { padding: 14px 16px; }

  .cos-demo canvas { aspect-ratio: 3 / 2; }
  .lab canvas { aspect-ratio: 1 / 1; }

  .code-block { padding: 14px; font-size: .8rem; }

  .opts button { flex: 1 1 100%; }

  .level-rail a { padding: 6px 10px; font-size: .74rem; }
}

/* Very small phones: guard against any residual overflow */
@media (max-width: 360px) {
  main { padding: 0 12px; }
  .panel { padding: 14px; }
  .hero h1 { font-size: clamp(1.7rem, 9vw, 2.2rem); }
  .sliders label,
  .cos-demo label { flex-wrap: wrap; }
  .outcomes { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
  .level .panel, .level .math-card, .level .concept > * { opacity: 1; transform: none; transition: none; }
  html { scroll-behavior: auto; }
}

/* ===== beautiful-math highlight callout ===== */
.beauty-note {
  margin: 0 0 22px;
  padding: 16px 20px;
  border: 1px solid var(--indigo-line);
  border-left: 4px solid var(--indigo);
  border-radius: 0 14px 14px 0;
  background: linear-gradient(180deg, var(--indigo-soft), var(--panel));
  box-shadow: var(--shadow);
}
.beauty-note .beauty-label {
  margin: 0 0 6px;
  color: var(--indigo);
  font-weight: 800;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.beauty-note .beauty-eq {
  margin: 4px 0 12px;
  text-align: center;
  font-size: 1.05rem;
  overflow-x: auto;
}
.beauty-note p { color: var(--muted); line-height: 1.65; margin: 0; }
.beauty-note p strong { color: var(--ink); }
.beauty-note p em { color: var(--indigo-2); font-style: italic; }
/* reveal-on-scroll: match the .panel / .math-card treatment */
.level .beauty-note { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s ease; }
.level.in-view .beauty-note { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .level .beauty-note { opacity: 1; transform: none; transition: none; }
}
@media (max-width: 480px) {
  .beauty-note { padding: 14px 16px; }
  .beauty-note .beauty-eq { font-size: .98rem; }
}

/* curse-of-dimensionality histogram (Advanced tier) */
#curseCanvas { aspect-ratio: 16 / 9; margin: 14px 0; width: 100%; }

/* =====================================================================
   POLISH PASS: additive micro-interactions & a11y focus states.
   CSS-only; transitions limited to opacity/transform/shadow/border/outline
   so interactive canvases never reflow. Fully gated by reduced-motion below.
   ===================================================================== */

/* --- gentle hover lift on content cards (matches .button feel) --- */
.panel,
.math-card {
  transition: box-shadow .25s ease, transform .25s ease, border-color .25s ease;
}
.level.in-view .panel:hover,
.level.in-view .math-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(70, 111, 150, .16);
  border-color: var(--indigo-line);
}
/* labs hold live widgets, so keep them planted and only warm the border */
.level.in-view .panel.lab:hover {
  transform: none;
  box-shadow: var(--shadow);
  border-color: var(--indigo-line);
}

/* --- accessible keyboard focus rings (visible only for keyboard users) --- */
.button:focus-visible,
.opts button:focus-visible,
.search-controls select:focus-visible,
.sliders input[type=range]:focus-visible,
.search-controls input[type=range]:focus-visible,
.cos-demo input[type=range]:focus-visible,
.level-rail a:focus-visible,
footer a:focus-visible,
.topbar nav a:focus-visible {
  outline: 3px solid rgba(70, 111, 150, .45);
  outline-offset: 2px;
  border-radius: 9px;
}
.cos-demo input[type=range]:focus-visible,
.sliders input[type=range]:focus-visible,
.search-controls input[type=range]:focus-visible {
  border-radius: 20px;
}

/* --- readout / metric tiles: faint hover warmth (no movement) --- */
.readout div,
.metric-grid div,
.legend li {
  transition: border-color .25s ease, background .25s ease;
}
.readout div:hover,
.metric-grid div:hover {
  border-color: var(--indigo);
}

/* --- rank-list rows: subtle slide on hover, top stays distinct --- */
.rank-list li {
  transition: background .3s ease, border-color .3s ease, transform .2s ease;
}
.rank-list li:hover {
  transform: translateX(3px);
  border-color: var(--indigo);
}

/* --- outcome chips: tiny lift so the hero feels alive --- */
.outcomes span {
  transition: transform .18s ease, box-shadow .2s ease, border-color .2s ease;
}
.outcomes span:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(70, 111, 150, .14);
  border-color: var(--indigo);
}

/* --- select hover/focus warmth --- */
.search-controls select {
  transition: border-color .2s ease, box-shadow .2s ease;
}
.search-controls select:hover {
  border-color: var(--indigo);
}

/* --- long-content hardening: never let a token/word widen the layout --- */
.panel p,
.legend li,
.example-list li,
.code-explanation p,
.q-text {
  overflow-wrap: break-word;
  word-break: normal;
}
/* typeset math can be wider than the card, so keep the horizontal scroll usable
   and hint it on touch (math-render already has overflow-x:auto) */
.math-render {
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

/* --- reduced-motion: neutralise every transition added above --- */
@media (prefers-reduced-motion: reduce) {
  .panel,
  .math-card,
  .readout div,
  .metric-grid div,
  .legend li,
  .rank-list li,
  .outcomes span,
  .search-controls select {
    transition: none !important;
  }
  .level.in-view .panel:hover,
  .level.in-view .math-card:hover,
  .rank-list li:hover,
  .outcomes span:hover {
    transform: none !important;
  }
}
