/* ── Reset & Tokens ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Background layers ── */
  --bg:        #0d1117;
  --surface:   #161b27;
  --surface2:  #1f2535;
  --border:    #2a3050;

  /* ── Accent — Sound Waves (teal) ── */
  --accent:    #2dd4bf;
  --accent-lo: rgba(45,212,191,.22);

  /* ── Semantic colours — DO NOT CHANGE ── */
  --green:     #3ddc84;
  --red:       #ff5555;
  --gold:      #f5c842;

  /* ── Typography ── */
  --text:      #dde3f0;
  --text-dim:  #6b7a99;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Courier New', monospace;

  /* ── Layout ── */
  --radius:    12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  padding: 0 16px;
}

#app { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ── Header ─── */
header { text-align: center; padding: 4px 0; }
header h1 {
  font-size: 1.8rem; font-weight: 700;
  background: linear-gradient(120deg, #60a5fa 0%, #2dd4bf 50%, #e879f9 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 3px; }

/* ── Controls bar ─── */
.controls-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ctrl-group  { display: flex; align-items: center; gap: 8px; }
.ctrl-label  { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); white-space: nowrap; }
.ctrl-value  { font-size: 0.82rem; color: var(--accent); font-weight: 600; min-width: 40px; }

/* ── Pill tabs ─── */
.pill-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.pill {
  padding: 5px 13px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 6px; cursor: pointer; font-size: 0.81rem;
  transition: background .18s, color .18s, box-shadow .18s;
}
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-lo); }
.pill:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* ── Buttons ─── */
.btn { padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.84rem; font-weight: 600; transition: filter .18s, box-shadow .18s, opacity .18s; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.12); box-shadow: 0 0 12px var(--accent-lo); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* ── Sliders ─── */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 120px; height: 6px;
  background: var(--surface2); border-radius: 3px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 6px var(--accent-lo);
}

/* ── Canvas card ─── */
.canvas-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px;
  overflow-x: clip;
}
.canvas-card canvas { display: block; width: 100%; height: auto; touch-action: pan-y; }

/* ── Readout panel ─── */
.readout-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}
.readout-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.readout-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.readout-value { font-size: 1.05rem; font-weight: 700; color: var(--text); font-family: var(--mono); }

/* ── Explore panel ─── */
.explore-tabs {
  display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.concept-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  transition: border-color .2s;
}
.concept-card:hover { border-color: var(--accent); }
.concept-card h3 { font-size: 0.95rem; color: var(--accent); margin-bottom: 4px; }
.concept-card .cc-formula {
  font-family: var(--mono); font-size: 0.82rem;
  background: var(--surface2); padding: 6px 10px; border-radius: 6px;
  margin: 8px 0; color: var(--gold);
}
.concept-card .cc-desc { font-size: 0.82rem; color: var(--text-dim); line-height: 1.45; }
.concept-card .cc-example {
  margin-top: 10px; padding: 10px; background: var(--bg);
  border-radius: 8px; border-left: 3px solid var(--accent);
}
.concept-card .cc-example-title { font-size: 0.72rem; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.concept-card .cc-example p { font-size: 0.8rem; color: var(--text-dim); margin: 2px 0; }

/* ── Practice panel ─── */
.practice-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.practice-prompt { font-size: 0.9rem; flex: 1 1 100%; margin-bottom: 4px; line-height: 1.5; }
.practice-input-group { display: flex; align-items: center; gap: 6px; }
.practice-input-group input {
  width: 120px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.9rem; font-family: var(--mono);
}
.practice-unit { font-size: 0.82rem; color: var(--text-dim); }
.pbar-score { font-size: 0.84rem; color: var(--text-dim); margin-left: auto; }
.pbar-score span { color: var(--text); font-weight: 700; }
.feedback { margin-top: 6px; padding: 0 16px; min-height: 22px; }
.feedback.ok  { color: var(--green); font-size: 0.88rem; font-weight: 600; }
.feedback.err { color: var(--red);   font-size: 0.88rem; font-weight: 600; }
.solution-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  font-size: 0.85rem; line-height: 1.6; color: var(--text-dim);
}
.solution-panel .step { margin: 4px 0; }
.solution-panel .step-num { color: var(--accent); font-weight: 600; }

/* ── Quiz panel ─── */
.quiz-bar {
  padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.quiz-counter { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }
.quiz-prompt { display: block; font-size: 0.95rem; margin: 10px 0; line-height: 1.5; }
.quiz-options { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.quiz-opt {
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 0.88rem; transition: border-color .2s;
  text-align: left;
}
.quiz-opt:hover { border-color: var(--accent); }
.quiz-opt.selected { border-color: var(--accent); background: var(--accent-lo); }
.quiz-opt.correct { border-color: var(--green); background: rgba(61,220,132,.15); }
.quiz-opt.wrong { border-color: var(--red); background: rgba(255,85,85,.15); }
.quiz-input-group { display: flex; align-items: center; gap: 6px; margin: 8px 0; }
.quiz-input-group input {
  width: 140px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.9rem; font-family: var(--mono);
}
.quiz-unit { font-size: 0.82rem; color: var(--text-dim); }
.quiz-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ── Quiz result ─── */
.quiz-result {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
}
.qr-header { text-align: center; margin-bottom: 16px; }
.qr-score { font-size: 2rem; font-weight: 700; }
.qr-score.perfect { color: var(--gold); }
.qr-score.good    { color: var(--green); }
.qr-score.poor    { color: var(--red); }
.qr-stars { font-size: 1.4rem; margin-top: 4px; }
.qr-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.qr-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 8px; background: var(--surface2);
  font-size: 0.84rem;
}
.qr-row.ok  { border-left: 3px solid var(--green); }
.qr-row.err { border-left: 3px solid var(--red); }
.qr-row .qr-q { flex: 1; color: var(--text-dim); }
.qr-row .qr-a { color: var(--text); font-weight: 600; margin: 0 10px; }
.qr-row .qr-icon { font-size: 1rem; }
.qr-retry { text-align: center; margin-top: 14px; }

/* ── SEO article ─── */
.seo-article {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px; line-height: 1.7;
}
.seo-article h2 { font-size: 1.3rem; color: var(--accent); margin-bottom: 12px; }
.seo-article h3 { font-size: 1.05rem; color: var(--text); margin: 18px 0 8px; }
.seo-article p { font-size: 0.92rem; color: var(--text-dim); margin-bottom: 10px; }
.seo-article a { color: var(--accent); text-decoration: none; }
.seo-article a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 768px) {
  .readout-panel { grid-template-columns: repeat(3, 1fr); }
  .controls-bar { gap: 10px; }
  input[type="range"] { width: 90px; }
  .concept-grid { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
  header h1 { font-size: 1.4rem; }
  .subtitle  { font-size: 0.78rem; }
  .controls-bar { padding: 10px 12px; gap: 8px; }
  .pill { padding: 5px 10px; font-size: 0.76rem; }
  .readout-panel { grid-template-columns: repeat(2, 1fr); }
  input[type="range"] { width: 70px; }
  .practice-bar { flex-direction: column; align-items: stretch; }
  .pbar-score { margin-left: 0; }
}

/* INTERLINK-START  header quick-links */
.head-actions{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:wrap;justify-content:flex-end;}
.btn-link{display:inline-flex;align-items:center;gap:7px;padding:5px 12px;border-radius:8px;font-size:.82rem;font-weight:700;text-decoration:none;cursor:pointer;background:var(--surface2,#1f2535);color:var(--text,#dde3f0);border:1.5px solid var(--border,#2a3050);white-space:nowrap;transition:border-color .18s,background .18s,color .18s;}
.btn-link:hover{border-color:var(--accent,#4fc3f7);background:var(--accent-lo,rgba(79,195,247,.18));color:#fff;}
.btn-link img{width:20px;height:20px;border-radius:4px;flex:none;}
.btn-link .lbl{line-height:1;}
@media(max-width:560px){.btn-link .lbl{display:none;}.btn-link{padding:5px 9px;}}
/* With a third quick-link (Gearbox) the row overflowed by ~17 px and
   wrapped under the mode tabs — at every width, since #app caps the bar.
   Share keeps its icon and word; only the trailing "your setup" goes, as
   site.css already does below 640 px. */
.head-actions .btn-share-ext { display: none; }
/* ...and on a 1024-1100 px window it still did not fit, so the quick-links
   go icon-only there (title + aria-label keep the name), as they already
   do below 560 px. Wider than 1100 px the labels return. */
@media (max-width: 1100px) { .btn-link .lbl { display: none; } .btn-link { padding: 5px 9px; } }
/* INTERLINK-END */

/* ── Display Controls — collapsible overlay pinned to the canvas ── */
.canvas-toggles {
  position: absolute; top: 16px; left: 16px; z-index: 4;
  background: rgba(13,17,23,0.88);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  max-width: calc(100% - 32px);
}
.canvas-toggles > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: center; gap: 0;
  padding: 0; white-space: nowrap;
  width: 34px; height: 34px;
  font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text); border-radius: 9px; transition: background .12s, color .12s;
}
.canvas-toggles > summary .cvt-title,
.canvas-toggles > summary .cvt-caret { display: none; }
.canvas-toggles .cvt-ico { width: 17px; height: 17px; }
/* Opened, it earns its caption back — the user has chosen to cover the canvas. */
.canvas-toggles[open] > summary {
  width: auto; height: auto; min-height: 30px;
  padding: 6px 10px; gap: 7px; justify-content: flex-start;
}
.canvas-toggles[open] > summary .cvt-title { display: inline; }
.canvas-toggles[open] > summary .cvt-caret { display: inline; }
.canvas-toggles > summary::-webkit-details-marker { display: none; }
.canvas-toggles > summary::marker { content: ''; }
.canvas-toggles > summary:hover { background: var(--accent-lo); color: var(--accent); }
.canvas-toggles > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.canvas-toggles .cvt-ico { flex-shrink: 0; color: var(--accent); }
.canvas-toggles .cvt-caret {
  margin-left: auto; padding-left: 4px; color: var(--text-dim);
  font-size: 0.7rem; transition: transform .2s;
}
.canvas-toggles[open] > summary .cvt-caret { transform: rotate(180deg); color: var(--accent); }
.canvas-toggles[open] > summary {
  border-bottom: 1px solid var(--border); border-radius: 9px 9px 0 0;
}
.canvas-toggles .cvt-body {
  display: flex; flex-direction: column; gap: 5px;
  padding: 8px 11px 10px; max-height: 60vh; overflow-y: auto;
}
.canvas-toggles .cvt-group {
  font-size: 0.58rem; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--accent);
  margin-top: 4px; padding-bottom: 2px; border-bottom: 1px solid var(--border);
}
.canvas-toggles .cvt-group:first-child { margin-top: 0; }
.canvas-toggles .cvt-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--text-dim); cursor: pointer;
  white-space: nowrap; transition: color .12s;
}
.canvas-toggles .cvt-item:hover { color: var(--text); }
.canvas-toggles .cvt-item input[type="checkbox"] {
  accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; flex-shrink: 0;
}
.canvas-toggles .cvt-reset {
  margin-top: 7px; padding: 5px 9px; min-height: 28px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim); font-size: 0.66rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; cursor: pointer;
  transition: border-color .12s, color .12s;
}
.canvas-toggles .cvt-reset:hover { border-color: var(--accent); color: var(--accent); }
.canvas-toggles .cvt-reset:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ── Calculation modal ── */
.calc-modal {
  display: none; position: fixed; inset: 0; z-index: 1200;
  background: rgba(0,0,0,0.72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto;
}
.calc-modal.open { display: flex; }
.calc-modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 780px; display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  max-height: calc(100vh - 48px); overflow: hidden;
}
.calc-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface2); flex-shrink: 0;
}
.calc-modal-title { font-size: 1rem; font-weight: 800; color: var(--text); }
.calc-modal-close {
  width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text-dim);
  font-size: 1.4rem; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.calc-modal-close:hover { border-color: var(--accent); color: var(--text); background: var(--surface2); }
.calc-modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
/* ── Learning panels ── */
.learn-panels {
  padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.learn-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.learn-head-title { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.learn-head-actions { display: flex; gap: 8px; }
.learn-toggle-all {
  padding: 6px 12px; min-height: 32px;
  background: var(--accent-lo); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px;
  font-family: var(--font); font-size: 0.78rem; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.learn-toggle-all:hover { background: var(--surface2); border-color: var(--accent); }
.learn-toggle-all:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.learn-card {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); margin-bottom: 10px; overflow: hidden;
  transition: border-color .2s;
}
.learn-card:last-child { margin-bottom: 0; }
.learn-card[open] { border-color: var(--accent); }
.learn-card > summary {
  list-style: none; cursor: pointer;
  padding: 11px 14px; min-height: 44px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 0.88rem; font-weight: 700; color: var(--text);
  user-select: none; transition: background .15s;
}
.learn-card > summary::-webkit-details-marker { display: none; }
.learn-card > summary::marker { content: ''; }
.learn-card > summary:hover { background: var(--accent-lo); }
.learn-card > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.learn-card > summary::after {
  content: '\25BE'; margin-left: auto; color: var(--text-dim);
  font-size: 0.78rem; transition: transform .2s;
}
.learn-card[open] > summary::after { transform: rotate(180deg); color: var(--accent); }
.lp-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent-lo); font-size: 0.9rem; flex-shrink: 0;
}
.lp-sub { color: var(--text-dim); font-weight: 500; font-size: 0.78rem; }
.learn-body { padding: 12px 14px 14px; }
.eq-line { margin: 8px 0; overflow-x: auto; overflow-y: hidden; font-size: 0.95rem; }
.lp-note { font-size: 0.8rem; line-height: 1.6; color: var(--text-dim); margin: 10px 0 0; }
.lp-note strong { color: var(--text); }

/* ── Canvas context menu ── */
.ctx-menu {
  position: fixed; z-index: 1300; min-width: 210px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 10px 26px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 2px;
}
.ctx-item {
  text-align: left; padding: 8px 11px; min-height: 38px;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: background .12s;
}
.ctx-item:hover { background: var(--surface2); }
.ctx-item:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 6px; }

/* ═══ Touch: the collapsed chip grows to the 44px minimum. Must stay LAST
   so it wins over the .canvas-toggles rules above. ═══ */
@media (max-width: 768px) {
  .canvas-toggles > summary { width: 44px; height: 44px; }
  .canvas-toggles .cvt-ico { width: 18px; height: 18px; }
  .canvas-toggles[open] > summary { width: auto; height: auto; padding: 7px 10px; }
}


/* ═══ Sound Waves — the lab ═══
   Desktop: experiment strip across the top; canvas + deck (Listen) + presets on the left, a
   sound console on the right whose height tracks the canvas column; readouts, the live
   equation and the challenges run full width underneath. */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
#sim-panel { display: flex; flex-direction: column; gap: 12px; }
.rail-num { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #062a26; font-size: .7rem; font-weight: 800; flex-shrink: 0; }

/* 1 — experiment strip */
.exp-strip { display: flex; flex-direction: column; gap: 8px; }
.strip-head { display: flex; align-items: center; gap: 8px; font-size: .74rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text); }
.scen-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.scen-btn { position: relative; display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; min-height: 58px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); cursor: pointer; font-family: var(--font);
  transition: border-color .15s, background .15s, box-shadow .15s; overflow: hidden; }
.scen-btn::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: transparent; transition: background .15s; }
.scen-ico { flex-shrink: 0; fill: none; stroke: var(--text-dim); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.scen-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.scen-btn strong { font-size: .86rem; line-height: 1.2; }
.scen-btn .scen-txt > span { font-size: .7rem; color: var(--text-dim); line-height: 1.3; }
.scen-btn:hover { border-color: var(--accent); }
.scen-btn.active { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-lo), rgba(45,212,191,.06)); box-shadow: 0 0 18px rgba(45,212,191,.12); }
.scen-btn.active::before { background: var(--accent); }
.scen-btn.active .scen-ico { stroke: var(--accent); }
.scen-btn.active .scen-txt > span { color: var(--text); }
.scen-btn:focus-visible, .pill:focus-visible, .btn:focus-visible, .preset-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* the two columns */
.sim-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.sim-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.canvas-card { position: relative; padding: 0; }
.canvas-card canvas#sw-canvas { display: block; width: 100%; touch-action: pan-y; border-radius: var(--radius); }
.canvas-card canvas#sw-canvas:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* 2 — the deck under the canvas */
.deck { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.deck-tag { display: inline-flex; align-items: center; gap: 7px; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text); padding-right: 2px; }
.btn-big { min-height: 42px; padding: 8px 18px; font-size: .92rem; background: #1f9d55; white-space: nowrap; }
.btn-big.on { background: #b23b3b; }
#btn-play { min-width: 112px; }
.btn-mute { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 7px 12px; white-space: nowrap; }
.btn-mute .mute-x { display: none; }
.btn-mute.muted { border-color: var(--red); color: #ffb0b0; background: rgba(255,85,85,.12); }
.btn-mute.muted .mute-x { display: inline; }
.btn-mute.muted .mute-wave { display: none; }
.db-tag { align-self: flex-end; margin-top: -2px; color: var(--text-dim); font-size: .68rem; font-weight: 600; }
.btn-big[hidden] { display: none; }
.deck .seg { flex-shrink: 0; }
#listen-pills[hidden] { display: none; }
.deck-vol { display: flex; align-items: center; gap: 8px; color: var(--text-dim); flex: 1 1 110px; min-width: 110px; cursor: pointer; }
.deck-vol .sim-slider { flex: 1; min-width: 70px; }
.deck-tools { display: flex; gap: 6px; margin-left: auto; }
.deck-tools .btn { padding: 7px 11px; font-size: .78rem; min-height: 36px; white-space: nowrap; }
.btn-ico { min-width: 38px; font-size: .9rem; }
.btn-ico .ico-lbl { display: none; font-size: .78rem; }

.status-line { font-size: .88rem; line-height: 1.5; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 9px 14px; min-height: 40px; }

/* presets as chips */
.preset-strip { display: flex; align-items: flex-start; gap: 10px; padding: 2px 2px 0; }
.preset-strip[hidden] { display: none; }
.preset-label { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); padding-top: 8px; white-space: nowrap; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-btn { padding: 6px 12px; min-height: 32px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-family: var(--font); font-size: .78rem; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s; }
.preset-btn:hover { border-color: var(--accent); background: var(--accent-lo); }

/* 3 & 4 — the console */
.sim-rail { display: flex; flex-direction: column; gap: 12px; }
.rail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.rail-head { font-size: .74rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text); display: flex; align-items: center; gap: 8px; }
.param-grid { display: flex; flex-direction: column; gap: 10px; }
.wblock { display: flex; flex-direction: column; gap: 9px; padding: 10px 11px 11px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.wblock.wa { border-left: 3px solid #60a5fa; }
.wblock.wb { border-left: 3px solid #f59e0b; }
.wblock.wmed { background: transparent; border-style: dashed; }
.wblock-head { display: flex; align-items: center; gap: 7px; }
.wblock-title { font-size: .82rem; font-weight: 800; color: var(--text); }
.wdot { width: 10px; height: 10px; border-radius: 50%; background: #60a5fa; box-shadow: 0 0 8px rgba(96,165,250,.6); }
.wblock.wb .wdot { background: #f59e0b; box-shadow: 0 0 8px rgba(245,158,11,.6); }
.shape-pills { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface); border-radius: 8px; padding: 3px; }
.shape-pill { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 4px 3px; min-height: 32px; font-size: .68rem; }
.shape-pill svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.wblock.wa .shape-pill.active { background: #60a5fa; color: #0d1117; box-shadow: 0 0 10px rgba(96,165,250,.35); }
.wblock.wb .shape-pill.active { background: #f59e0b; color: #0d1117; box-shadow: 0 0 10px rgba(245,158,11,.35); }
.pill-wrap { flex-wrap: wrap; }
.pill-tabs .pill { min-height: 32px; }
.seg .pill { padding: 5px 11px; white-space: nowrap; }
.prow { display: flex; flex-direction: column; gap: 5px; }
.prow-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.prow-label { font-size: .72rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.prow-num { display: flex; align-items: center; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); height: 30px; }
.prow-num input { width: 60px; height: 28px; padding: 3px 6px; border: none; background: transparent; color: var(--accent); font-family: var(--mono); font-weight: 700; font-size: .85rem; text-align: right; -moz-appearance: textfield; }
.prow-num input::-webkit-outer-spin-button, .prow-num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-btn { width: 28px; height: 28px; border: none; background: var(--surface2); color: var(--text-dim); font-size: 1rem; font-weight: 700; cursor: pointer; flex-shrink: 0; }
.stepper-btn:hover { background: var(--accent-lo); color: var(--text); }
.stepper-btn:active { background: var(--accent); color: #062a26; }
.prow-unit { font-size: .72rem; color: var(--text-dim); min-width: 26px; padding: 0 8px; }
.xrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.xrow .pill-tabs { flex-wrap: wrap; }
.sel { min-height: 32px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-family: var(--font); font-size: .84rem; }
input[type="range"].sim-slider { width: 100%; -webkit-appearance: none; appearance: none; height: 6px; background: rgba(255,255,255,.12); border-radius: 3px; outline: none; border: 1px solid rgba(255,255,255,.1); }
.sim-slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--accent-lo), rgba(255,255,255,.12)); }
.sim-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 0 8px var(--accent-lo); border: 2px solid rgba(255,255,255,.2); }
.sim-slider::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--accent-lo), rgba(255,255,255,.12)); border: none; }
.sim-slider::-moz-range-thumb { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.2); border-radius: 50%; background: var(--accent); cursor: pointer; }
.wblock.wa .sim-slider::-webkit-slider-thumb { background: #60a5fa; }
.wblock.wb .sim-slider::-webkit-slider-thumb { background: #f59e0b; }
.wblock.wa .sim-slider::-moz-range-thumb { background: #60a5fa; }
.wblock.wb .sim-slider::-moz-range-thumb { background: #f59e0b; }

/* readouts, equation, challenges */
.readout-panel { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.readout-value { font-size: .95rem; }
.lab-foot { display: block; }
.sim-rail .tasks { flex: 1 1 auto; }
/* two lines reserved, so a longer sentence never resizes the canvas column while a slider moves */
@media (min-width: 1101px) { .readout-panel { grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr)); } }
@media (min-width: 1101px) { .status-line { min-height: 64px; display: flex; align-items: center; } }
.lab-foot .learn-card { margin: 0; background: var(--surface); }
.task-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.task-list li { display: flex; gap: 8px; align-items: flex-start; font-size: .8rem; line-height: 1.4; color: var(--text-dim); }
.task-list .tk { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--border); flex-shrink: 0; margin-top: 1px; }
.task-list li.done { color: var(--text); }
.task-list li.done .tk { background: var(--green); border-color: var(--green); box-shadow: 0 0 6px rgba(61,220,132,.5); }
.task-list li.now .tk { border-color: var(--green); }
#lp-equations .katex-display { margin: 6px 0; overflow-x: auto; overflow-y: hidden; }
/* until KaTeX's stylesheet arrives its MathML renders inline and wide: keep that inside the card */
#lp-equations .learn-body { overflow-x: auto; min-width: 0; }
.lab-foot { min-width: 0; overflow-x: clip; }

/* Explore */
.concept-card .cc-desc code { font-family: var(--mono); color: var(--gold); }
.cc-note { font-size: .78rem; color: var(--text); margin-top: 8px; line-height: 1.45; border-top: 1px dashed var(--border); padding-top: 8px; }
.explore-tabs .pill { min-height: 34px; }
.practice-topic { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); flex: 1 1 100%; }
.quiz-opt:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.seo-article table { border-collapse: collapse; width: 100%; margin: 10px 0 14px; font-size: .86rem; }
.seo-article th, .seo-article td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; color: var(--text-dim); }
.seo-article th { color: var(--text); background: var(--surface2); }
.seo-article ul { margin: 0 0 12px 20px; color: var(--text-dim); font-size: .92rem; line-height: 1.7; }
.seo-article h4 { font-size: .95rem; color: var(--text); margin: 12px 0 4px; }


@media (max-width: 1240px) {
  .deck-word { display: none; }
  .deck .seg .pill { padding: 5px 8px; }
  .deck-vol { min-width: 80px; }
}

/* Tablet: canvas full width; the console spreads into two columns below it. */
@media (max-width: 1100px) {
  .scen-btn { padding: 9px 10px; gap: 8px; }
  .scen-ico { display: none; }
  .sim-layout { grid-template-columns: minmax(0, 1fr); }
  .sim-rail { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
  .sim-rail .tasks { grid-column: 1 / -1; }
}

/* Phone: one column, the experiments a swipeable row, the essentials first. */
@media (max-width: 768px) {
  .strip-head { display: none; }
  .scen-tabs { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 6px; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .scen-tabs::-webkit-scrollbar { display: none; }
  .scen-btn { flex: 0 0 auto; min-height: 44px; padding: 8px 14px; scroll-snap-align: start; border-radius: 999px; }
  .scen-btn::before { display: none; }
  .scen-btn .scen-txt > span { display: none; }
  .scen-btn strong { white-space: nowrap; font-size: .84rem; }
  .sim-rail { display: flex; }
  .deck { gap: 8px; }
  .deck-tag { display: none; }
  .deck .btn-big { flex: 1 1 auto; min-height: 46px; }
  .deck .btn-mute { flex: 0 0 auto; min-height: 46px; }
  .deck .seg { flex: 1 1 100%; overflow-x: auto; }
  .deck .seg .pill { flex: 1 0 auto; }
  .deck-vol { flex: 1 1 auto; }
  .deck-tools { margin-left: 0; }
  .deck-tools .btn { min-width: 44px; min-height: 44px; }
  .canvas-toggles { top: 6px; left: 6px; }
  .preset-strip { flex-direction: column; align-items: stretch; gap: 6px; }
  .preset-row { min-width: 0; }
  .preset-label { padding-top: 0; }
  .preset-row { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .preset-row::-webkit-scrollbar { display: none; }
  .preset-btn { flex: 0 0 auto; min-height: 40px; }
  .stepper-btn { width: 36px; height: 36px; }
  .prow-num { height: 38px; }
  .prow-num input { height: 36px; }
  .shape-pill { min-height: 44px; }
  /* a 6 px track is too thin to hit with a thumb: the input is 28 px tall, the drawn track stays 6 px */
  input[type="range"].sim-slider { height: 28px; background: transparent; border: none; }
  input[type="range"].sim-slider::-webkit-slider-runnable-track { border: 1px solid rgba(255,255,255,.1); }
}
@media (max-width: 500px) {
  .status-line { font-size: .82rem; }
  .readout-panel { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { .scen-btn { transition: none; } }
.ctx-menu[hidden] { display: none; }
