/* shared styles */
:root {
    --bg: #0a0a0c; --bg-1: #111116; --bg-2: #16161e; --bg-3: #1c1c26;
    --line: #25252f; --line-2: #34343f;
    --ink: #f5f1e8; --ink-2: #b3acb8; --ink-3: #6f6878; --ink-4: #4b4655;
    --red: #ff2d3a; --pink: #ff5577; --purple: #8b6fff;
    --grad: linear-gradient(180deg, #ff2d3a 0%, #ff4d6d 35%, #b265ff 70%, #8b6fff 100%);
    --grad-h: linear-gradient(90deg,  #ff2d3a 0%, #ff4d6d 35%, #b265ff 70%, #8b6fff 100%);
    --correct: #5fc97f;
    --font-serif:   'Source Serif 4', Charter, Georgia, serif;
    --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
    --font-ui:      'Manrope', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', ui-monospace, Menlo, monospace;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
    font-family: var(--font-serif); font-size: 17px; line-height: 1.65;
    -webkit-font-smoothing: antialiased; }
  body::before { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 100;
    opacity: 0.035; mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }
  body::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: -1;
    background: radial-gradient(1100px 700px at 95% -5%, rgba(255,45,58,0.07), transparent 60%),
                radial-gradient(1000px 700px at -5% 100%, rgba(139,111,255,0.07), transparent 60%); }
  a { color: var(--ink); text-decoration: none; border-bottom: 1px solid transparent;
      transition: color 140ms, border-color 140ms; }
  button { font-family: inherit; font-size: inherit; cursor: pointer; }

  .site { min-height: 100vh; display: flex; flex-direction: column; }
  .topbar { border-bottom: 1px solid var(--line); padding: 18px 32px;
    display: flex; justify-content: space-between; align-items: center;
    background: rgba(10,10,12,0.7); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 50; }
  .wordmark { display: flex; align-items: center; gap: 12px; font-family: var(--font-display);
    font-weight: 800; font-size: 19px; letter-spacing: -0.02em; line-height: 1; border-bottom: none; }
  .wordmark .brand-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
  .wordmark .muted { color: var(--ink-3); font-family: var(--font-mono); font-weight: 400; font-size: 11px;
    letter-spacing: 0.12em; text-transform: uppercase; margin-left: 6px; padding-left: 14px; line-height: 0.85;
    position: relative; }
  .wordmark .muted::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 1px; height: 19px; background: var(--line); }
  .topnav { display: flex; gap: 28px; font-family: var(--font-ui); font-size: 14px; font-weight: 500; }
  .topnav a { color: var(--ink-2); border: none; padding: 4px 0; position: relative; transition: color 140ms; }
  .topnav a:hover { color: var(--ink); }
  /* Active tab indicator: gradient underline that extends to the topbar's bottom border */
  .topnav a.active { color: var(--ink); }
  .topnav a.active::after {
    content: '';
    position: absolute; left: 0; right: 0; bottom: -23px;
    height: 2px;
    background: var(--grad-h);
  }
  /* Brand logomark used in the topbar wordmark. Works for either <img> or <svg>. */
  .wordmark .logo-mark {
    width: 32px; height: 32px;
    display: block;
    flex-shrink: 0;
    border-radius: 5px;
    object-fit: cover;
    border: 1px solid var(--line);
  }
  main { flex: 1; padding: 32px 32px 80px; max-width: 880px; width: 100%; margin: 0 auto; }
  footer { padding: 28px 32px; border-top: 1px solid var(--line); color: var(--ink-3);
    font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
    display: flex; justify-content: space-between; text-transform: uppercase; }

  h1 { font-family: var(--font-display); font-size: clamp(40px, 5.4vw, 64px); font-weight: 700;
    line-height: 1.0; letter-spacing: -0.035em; margin: 0 0 20px; color: var(--ink); }

  .crumb { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em;
    text-transform: uppercase; color: var(--ink-3); margin-bottom: 16px; }
  .crumb a { color: var(--ink-3); border: none; }
  .crumb a:hover { color: var(--ink-2); }
  .crumb .sep { margin: 0 10px; color: var(--ink-4); }
  .crumb .topic-list { display: inline-flex; align-items: center; gap: 8px; }
  .crumb .topic-list .dot { color: var(--ink-4); margin: 0 2px; }
  .crumb .topic-list .active { font-weight: 700; background: var(--grad-h);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

  .topic-narrative { max-width: 64ch; margin: 28px 0 8px; }
  .topic-narrative p { font-family: var(--font-serif); font-size: 19px; line-height: 1.65;
    margin: 0 0 22px; color: var(--ink-2); }
  .topic-narrative p strong { color: var(--ink); font-weight: 600; }
  .topic-narrative p em { color: var(--ink); font-style: italic; }

  .btn {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 12px 20px;
    color: var(--ink);
    font-family: var(--font-ui); font-weight: 600; font-size: 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    background:
      linear-gradient(var(--bg-1), var(--bg-1)) padding-box,
      var(--grad-h) border-box;
    transition: background 180ms, box-shadow 180ms, transform 140ms;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
  }
  .btn:hover {
    background:
      linear-gradient(var(--bg-2), var(--bg-2)) padding-box,
      var(--grad-h) border-box;
    box-shadow: 0 0 18px rgba(255, 77, 109, 0.18);
    transform: translateY(-1px);
  }
  .btn.ghost {
    background: transparent;
    color: var(--ink-2);
    border: 1px solid var(--line-2);
  }
  .btn.ghost:hover {
    color: var(--ink);
    border-color: var(--ink-3);
    background: transparent;
    box-shadow: none;
    transform: translateY(-1px);
  }

  /* ==========================================================
     PROGRESS INDICATORS : one visual language per activity type
     ========================================================== */

  /* Lesson: 10 horizontal pips, one per skill-check scenario.
     Pip width 16px + gap 5px = 21px stride. 10 pips = 16*10 + 5*9 = 205px.
     Gradient is sliced across the full row so red flows to blue across all ten. */
  .skill-pips { display: inline-flex; gap: 5px; }
  .skill-pip {
    width: 16px; height: 6px;
    border: 1px solid var(--ink-4);
    border-radius: 2px;
    background: transparent;
    transition: background 200ms;
  }
  .skill-pip.filled {
    background: var(--grad-h);
    background-size: 205px 100%;
    background-repeat: no-repeat;
    border-color: transparent;
    box-shadow: 0 0 6px rgba(255,77,109,0.4);
  }
  .skill-pips .skill-pip:nth-child(1).filled  { background-position:    0 0; box-shadow: 0 0 6px rgba(255,45,58,0.45); }
  .skill-pips .skill-pip:nth-child(2).filled  { background-position: -21px 0; box-shadow: 0 0 6px rgba(255,65,90,0.45); }
  .skill-pips .skill-pip:nth-child(3).filled  { background-position: -42px 0; box-shadow: 0 0 6px rgba(255,77,109,0.45); }
  .skill-pips .skill-pip:nth-child(4).filled  { background-position: -63px 0; box-shadow: 0 0 6px rgba(255,90,140,0.45); }
  .skill-pips .skill-pip:nth-child(5).filled  { background-position: -84px 0; box-shadow: 0 0 6px rgba(220,95,180,0.45); }
  .skill-pips .skill-pip:nth-child(6).filled  { background-position:-105px 0; box-shadow: 0 0 6px rgba(190,100,210,0.45); }
  .skill-pips .skill-pip:nth-child(7).filled  { background-position:-126px 0; box-shadow: 0 0 6px rgba(178,101,255,0.45); }
  .skill-pips .skill-pip:nth-child(8).filled  { background-position:-147px 0; box-shadow: 0 0 6px rgba(160,105,255,0.45); }
  .skill-pips .skill-pip:nth-child(9).filled  { background-position:-168px 0; box-shadow: 0 0 6px rgba(150,108,255,0.45); }
  .skill-pips .skill-pip:nth-child(10).filled { background-position:-189px 0; box-shadow: 0 0 6px rgba(139,111,255,0.45); }

  /* Player: in-question progress pip strip. Unlike skill-pips, these are
     transient state markers (current question is highlighted, past are dim). */
  .q-pips { display: inline-flex; gap: 4px; }
  .q-pip {
    width: 10px; height: 5px;
    border: 1px solid var(--ink-4);
    border-radius: 2px;
    background: transparent;
  }
  .q-pip.done {
    background: var(--ink-3);
    border-color: var(--ink-3);
  }
  .q-pip.current {
    background: var(--pink);
    border-color: var(--pink);
    box-shadow: 0 0 6px rgba(255, 85, 119, 0.5);
  }

  /* Diagnostic: horizontal score bar */
  .score-bar {
    width: 130px; height: 6px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
  }
  .score-bar .fill {
    height: 100%;
    background: var(--grad-h);
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(255,77,109,0.35);
  }

  /* Targeted Practice: round pips, one per identified misconception */
  .mc-pips { display: inline-flex; gap: 7px; align-items: center; flex-wrap: wrap; }
  .mc-pip {
    width: 10px; height: 10px; border-radius: 50%;
    background: transparent;
    border: 1.5px solid var(--pink);
    box-shadow: 0 0 5px rgba(255,85,119,0.4);
    transition: all 200ms;
  }
  .mc-pip.cleared {
    background: var(--correct);
    border-color: var(--correct);
    box-shadow: none;
  }

  /* Indicator label (shared across all three) */
  .indicator-row {
    display: flex; align-items: center; gap: 14px;
    padding-top: 14px;
    margin-top: 14px;
    border-top: 1px solid var(--line);
  }
  .indicator-label {
    font-family: var(--font-mono); font-size: 11.5px;
    color: var(--ink-3); letter-spacing: 0.05em;
  }
  .indicator-label .strong { color: var(--ink-2); font-weight: 600; }
  .indicator-label .correct { color: var(--correct); font-weight: 600; }
  .indicator-label .pending { color: var(--pink); font-weight: 600; }
  .indicator-label .sep { color: var(--ink-4); margin: 0 8px; }

  /* ==========================================================
     INTERACTIVE APPLET : collapsible disclosure
     ========================================================== */
  .applet-disclosure {
    margin: 8px 0 18px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    position: relative;
  }
  .applet-disclosure[open] {
    background: linear-gradient(180deg, transparent 0%, rgba(17,17,22,0.55) 14%);
  }
  .applet-disclosure summary {
    list-style: none;
    cursor: pointer;
    padding: 22px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
  }
  .applet-disclosure summary::-webkit-details-marker { display: none; }
  .applet-disclosure summary::marker { content: ''; }

  .ad-eyebrow {
    font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em;
    text-transform: uppercase; color: var(--ink-3); font-weight: 600;
    display: inline-flex; align-items: center; gap: 18px;
    white-space: nowrap;
    transition: color 200ms;
  }
  .ad-eyebrow::before,
  .ad-eyebrow::after {
    content: '';
    display: block;
    width: 64px; height: 1px;
    background: var(--grad-h);
    opacity: 0.85;
    transition: width 220ms, opacity 200ms;
  }
  .applet-disclosure summary:hover .ad-eyebrow { color: var(--ink); }
  .applet-disclosure summary:hover .ad-eyebrow::before,
  .applet-disclosure summary:hover .ad-eyebrow::after {
    width: 84px; opacity: 1;
  }

  .ad-body {
    padding: 8px 4px 28px;
  }
  .ap-canvas {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px 18px;
    position: relative;
  }
  .ap-canvas svg {
    width: 100%; height: auto; display: block;
  }
  /* Applet-frame variant: matches the Walk-the-line sandbox atmosphere so the
     topic page figure reads as a still frame from the same world. */
  .ap-canvas.applet-frame {
    background: radial-gradient(ellipse at top, #15002a 0%, #0a0015 40%, #000008 100%);
    border-color: rgba(217, 70, 239, 0.18);
    padding: 18px 20px;
  }
  .ap-readouts {
    display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap;
  }
  .ap-readout {
    display: inline-flex; align-items: baseline; gap: 8px;
    padding: 7px 14px;
    background: var(--bg-2); border: 1px solid var(--line);
    border-radius: 6px;
    font-family: var(--font-mono); font-size: 13px;
    line-height: 1;
  }
  .ap-readout-label { color: var(--ink-3); font-style: italic; }
  .ap-readout-value { color: var(--ink); font-weight: 600; letter-spacing: 0.02em; }
  .ap-readout.vector {
    border-color: rgba(255, 77, 109, 0.45);
    background: rgba(255, 77, 109, 0.07);
  }
  .ap-readout.vector .ap-readout-value {
    background: var(--grad-h);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  }
  .ap-caption {
    font-family: var(--font-ui); font-size: 12.5px;
    color: var(--ink-3); margin: 18px 0 0; line-height: 1.5;
    letter-spacing: 0.01em;
  }

  /* ==========================================================
     TEACHING FIGURE : static figure inline in narrative,
     followed by a CTA to the dedicated sandbox page
     ========================================================== */
  .topic-figure {
    margin: 26px 0 22px;
    padding: 0;
    display: block;
  }
  .topic-figure .ap-caption {
    margin-top: 16px;
  }
  .topic-figure .figure-cta {
    margin-top: 18px;
  }

  /* ================ MOCKUP A: STACKED CARDS ================ */
  .section-head {
    margin: 56px 0 18px;
    max-width: 64ch;
    display: flex; align-items: baseline; gap: 14px;
    padding-bottom: 14px; border-bottom: 1px solid var(--line);
  }
  .section-head h2 {
    font-family: var(--font-display); font-size: 26px; font-weight: 600;
    letter-spacing: -0.02em; margin: 0; color: var(--ink);
  }
  .section-head .count {
    font-family: var(--font-mono); font-size: 11px; color: var(--ink-3);
    letter-spacing: 0.12em; text-transform: uppercase;
  }
  .activity-stack {
    max-width: 64ch;
    display: flex; flex-direction: column; gap: 14px;
  }
  .activity-card {
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 26px 28px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px 32px;
    align-items: center;
    transition: border-color 200ms, opacity 200ms;
  }
  .activity-card:hover {
    border-color: var(--line-2);
  }
  .activity-card.muted {
    opacity: 0.62;
  }
  .activity-card.muted .ac-title { color: var(--ink-2); }
  .activity-card .ac-body { min-width: 0; }
  .activity-card .ac-eyebrow {
    font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.18em;
    text-transform: uppercase; color: var(--ink-3); font-weight: 600;
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 10px;
  }
  .activity-card .ac-eyebrow::before {
    content: ''; width: 22px; height: 1px; background: var(--grad-h);
  }
  .activity-card .ac-title {
    font-family: var(--font-display); font-size: 22px; font-weight: 700;
    letter-spacing: -0.018em; line-height: 1.25;
    margin: 0; color: var(--ink);
  }
  .activity-card .ac-title-row {
    display: flex; align-items: baseline; gap: 12px;
  }
  .activity-card .ac-chev {
    font-family: var(--font-display); font-size: 22px;
    color: var(--ink-4); line-height: 1;
    transition: transform 220ms, color 200ms;
    display: inline-block;
  }
  .activity-card .ac-collapse {
    margin: 0; padding: 0; border: none; background: none;
  }
  .activity-card .ac-collapse > summary {
    list-style: none;
    cursor: pointer;
    display: block;
    padding: 0; margin: 0;
    user-select: none;
  }
  .activity-card .ac-collapse > summary::-webkit-details-marker { display: none; }
  .activity-card .ac-collapse > summary::marker { content: ''; }
  .activity-card .ac-collapse > summary:hover .ac-chev {
    color: var(--pink);
  }
  .activity-card .ac-collapse > summary:hover .ac-eyebrow {
    color: var(--ink-2);
  }
  .activity-card .ac-collapse > summary:hover .ac-title {
    background: var(--grad-h);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  }
  .activity-card .ac-collapse[open] .ac-chev {
    transform: rotate(90deg);
    color: var(--pink);
  }
  .activity-card .ac-desc {
    font-family: var(--font-serif); font-size: 15.5px; line-height: 1.55;
    color: var(--ink-2); margin: 14px 0 0; max-width: 56ch;
  }
  .activity-card .ac-action { display: flex; align-items: center; }
  .activity-card .ac-collapse > summary:focus-visible {
    outline: 2px solid var(--pink);
    outline-offset: 6px;
    border-radius: 4px;
  }
  .applet-disclosure summary:focus-visible {
    outline: 2px solid var(--pink);
    outline-offset: 4px;
    border-radius: 4px;
  }

  /* Disabled button (used on Targeted Practice when no diagnostic taken) */
  .btn.disabled, .btn[disabled] {
    background: var(--bg-2);
    color: var(--ink-4);
    border: 1px solid var(--line);
    box-shadow: none;
    cursor: not-allowed;
    pointer-events: none;
  }

  /* ============== MOBILE ============== */
  @media (max-width: 640px) {
    main { padding: 22px 18px 60px; }
    .topbar { padding: 14px 18px; }
    .topnav { gap: 18px; font-size: 13px; }
    .wordmark .brand-text { display: none; }
    h1 { font-size: clamp(28px, 8vw, 38px); letter-spacing: -0.025em; line-height: 1.05; }
    .activity-card {
      grid-template-columns: 1fr;
      align-items: stretch;
      padding: 22px 22px;
      gap: 18px;
    }
    .activity-card .ac-action { justify-content: stretch; }
    .activity-card .ac-action .btn {
      width: 100%; justify-content: center;
    }
    .ad-eyebrow::before, .ad-eyebrow::after { width: 36px; }
    .applet-disclosure summary:hover .ad-eyebrow::before,
    .applet-disclosure summary:hover .ad-eyebrow::after { width: 48px; }
    .indicator-row { flex-wrap: wrap; gap: 10px; }
  }


/* ============== SANDBOX PAGE OVERRIDES ============== */
  main.sandbox-main {
    flex: 1;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 18px 24px 0;
  }
  main.sandbox-main .crumb {
    max-width: 1280px;
    margin: 0 auto 14px;
  }
  main.sandbox-main #walk-the-line-mount {
    margin: 0;
    min-height: 600px;  /* reserve space so the chrome does not jump on mount */
  }
  /* Visible diagnostic if React or the script never finishes loading */
  main.sandbox-main #walk-the-line-mount:empty::before {
    content: 'Applet booting...';
    display: block;
    padding: 32px;
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }
