/*
 * Academiq interactive simulations — shared styles.
 *
 * Scoped under .aq-sim. Light and dark follow the app shell's `html.dark`
 * class. The stage itself is always deep navy: Academiq green is only legible
 * on dark ground (docs/DESIGN.md, the contrast law). Colours and radii are
 * taken from the DESIGN.md scales.
 *
 * Layout (built by ctx.layout() in aq-sims-core.js): a header, then the
 * "bench" — the stage plus a dock with the toolbar and a tabbed panel
 * (Controls / Working / Tasks) — then a folded "About this lab" disclosure.
 * The bench has two arrangements, set on its data-layout attribute:
 *   narrow  stage, then a dock that sticks to the bottom of the screen while
 *           the stage is in view, so controls never scroll away from it;
 *   wide    stage on the left, a sticky dock column on the right.
 */

.aq-sim {
  --aq-navy: #0C1A2E;
  --aq-navy-2: #122440;
  --aq-green: #A4D65E;
  --aq-green-ink: #4F7A1E;
  --aq-ink: #0C1A2E;
  --aq-ink-2: #1A3458;
  --aq-muted: #4B5563;
  --aq-card: #FFFFFF;
  --aq-soft: #F9FAFB;
  --aq-accent-bg: #F6FBEE;
  --aq-border: #E5E7EB;
  --aq-border-strong: #D1D5DB;
  --aq-border-accent: #DCEFBE;
  --aq-primary-bg: #0C1A2E;
  --aq-primary-ink: #FFFFFF;
  --aq-primary-icon: #A4D65E;
  --aq-primary-hover: #1A3458;
  --aq-badge-bg: #0C1A2E;
  --aq-force: #DC2626;
  --aq-motion: #265090;
  --aq-ease: cubic-bezier(0.23, 1, 0.32, 1);
  --aq-radius: 16px;

  container-type: inline-size;
  container-name: aqsim;
  scroll-margin-top: 84px;
  padding: 4px;
  border-radius: var(--aq-radius);
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border), 0 10px 28px -14px rgba(12, 26, 46, 0.28);
  font-family: var(--font-sans-stack, 'Nunito Sans', system-ui, sans-serif);
  color: var(--aq-ink);
  text-align: left;
}

/* Dark: navy fills vanish on a navy card, so the primary fill turns green with
   navy ink (10.3 : 1). */
.dark .aq-sim {
  --aq-green-ink: #A4D65E;
  --aq-ink: #EEF3FB;
  --aq-ink-2: #D9E6F5;
  --aq-muted: #B3CCE8;
  --aq-card: #122440;
  --aq-soft: #0C1A2E;
  --aq-accent-bg: rgba(164, 214, 94, 0.1);
  --aq-border: #1A3458;
  --aq-border-strong: #1F4070;
  --aq-border-accent: rgba(164, 214, 94, 0.3);
  --aq-primary-bg: #A4D65E;
  --aq-primary-ink: #0C1A2E;
  --aq-primary-icon: #0C1A2E;
  --aq-primary-hover: #C2E48F;
  --aq-badge-bg: #1A3458;
  --aq-force: #F98A7A;
  --aq-motion: #7CC5F2;
  box-shadow: inset 0 0 0 1px var(--aq-border), 0 10px 28px -14px rgba(6, 13, 23, 0.7);
}

.aq-sim *,
.aq-sim *::before,
.aq-sim *::after { box-sizing: border-box; }

.aq-sim__core {
  border-radius: 12px;
  background: var(--aq-card);
  box-shadow: inset 0 0 0 1px var(--aq-border);
  /* clip, not hidden: hidden makes this a scroll container, and the dock's
     position: sticky would then never engage. */
  overflow: hidden;
  overflow: clip;
}

/* ------------------------------------------------------------------ header */
.aq-sim__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 12px;
}

.aq-sim__badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--aq-badge-bg);
  color: var(--aq-green);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12);
}

.aq-sim__head-text { min-width: 0; }

.aq-sim .aq-sim__title {
  margin: 0;
  padding: 0;
  border: 0;
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--aq-ink);
}

.aq-sim__lede {
  margin: 2px 0 0;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--aq-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.aq-sim__meta {
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--aq-green-ink);
}

/* ------------------------------------------------- about (goals + examiner) */
.aq-sim__about {
  margin: 0 16px 16px;
  border-radius: 12px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
}

.aq-sim__about > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  list-style: none;
  cursor: pointer;
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--aq-ink-2);
  -webkit-tap-highlight-color: transparent;
}

.aq-sim__about > summary::-webkit-details-marker { display: none; }
.aq-sim__about > summary:focus-visible { outline: 3px solid var(--aq-green); outline-offset: 2px; border-radius: 12px; }
.aq-sim__about > summary svg { flex-shrink: 0; color: var(--aq-green-ink); }
.aq-sim__about > summary .aq-sim__chev { margin-left: auto; color: var(--aq-muted); transition: transform 220ms var(--aq-ease); }
.aq-sim__about[open] > summary .aq-sim__chev { transform: rotate(180deg); }

.aq-sim__about-body {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
}

.aq-sim .aq-sim__about-lede {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--aq-ink);
}

.aq-sim .aq-sim__outcomes-title {
  margin: 0 0 6px;
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--aq-ink-2);
}

.aq-sim .aq-sim__outcomes ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 5px;
}

.aq-sim .aq-sim__outcomes li {
  position: relative;
  margin: 0;
  padding-left: 24px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--aq-ink);
}

.aq-sim .aq-sim__outcomes li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.18em;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--aq-navy) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4L18 8' fill='none' stroke='%23A4D65E' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 11px no-repeat;
}

/* -------------------------------------------------------------- mount area */
.aq-sim__mount {
  position: relative;
  padding: 0 16px 16px;
}

.aq-sim__mount[data-state="idle"] {
  min-height: 220px;
  display: grid;
  place-items: center;
}

.aq-sim__loading {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 320px;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--aq-navy-2), var(--aq-navy));
  color: #B3CCE8;
  font-size: 0.86rem;
  font-weight: 700;
}

.aq-sim__spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid rgba(164, 214, 94, 0.25);
  border-top-color: var(--aq-green);
  animation: aq-spin 0.9s linear infinite;
}

@keyframes aq-spin { to { transform: rotate(360deg); } }

.aq-sim__msg {
  margin: 0;
  padding: 18px;
  border-radius: 12px;
  background: var(--aq-soft);
  color: var(--aq-muted);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------- bench */
.aq-sim__bench {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aq-sim__view {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Narrow: the dock follows the stage and sticks to the bottom of the screen
   until the stage has scrolled past. */
.aq-sim__dock {
  position: sticky;
  bottom: 0;
  z-index: 4;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 -16px -16px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--aq-card);
  box-shadow: 0 -1px 0 var(--aq-border), 0 -14px 24px -16px rgba(12, 26, 46, 0.4);
}

.dark .aq-sim__dock { box-shadow: 0 -1px 0 var(--aq-border), 0 -14px 24px -14px rgba(0, 0, 0, 0.65); }

/* Wide: stage beside a dock column that stays in view. */
.aq-sim__bench[data-layout="wide"] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: 14px;
}

.aq-sim__bench[data-layout="wide"] .aq-sim__dock {
  top: var(--aq-sticky-top, 16px);
  bottom: auto;
  max-height: calc(100vh - var(--aq-sticky-top, 16px) - 16px);
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
}

/* -------------------------------------------------------------------- tabs */
.aq-sim__tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
}

.aq-sim__bench[data-layout="wide"] .aq-sim__tabs { background: var(--aq-card); }

.aq-sim__dock[data-tabs="0"] .aq-sim__tabs,
.aq-sim__dock[data-tabs="0"] .aq-sim__panels { display: none; }

.aq-sim__tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 36px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--aq-muted);
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 180ms var(--aq-ease), color 180ms var(--aq-ease), transform 140ms var(--aq-ease);
  -webkit-tap-highlight-color: transparent;
}

.aq-sim__tab[hidden] { display: none; }
.aq-sim__tab:hover { color: var(--aq-ink); }
.aq-sim__tab:active { transform: scale(0.97); }
.aq-sim__tab:focus-visible,
.aq-sim__fold:focus-visible { outline: 3px solid var(--aq-green); outline-offset: 1px; }

.aq-sim__tab[aria-selected="true"] {
  background: var(--aq-primary-bg);
  color: var(--aq-primary-ink);
  box-shadow: 0 1px 3px rgba(12, 26, 46, 0.3);
}

.aq-sim__tab-count {
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.8;
}

.aq-sim__tab-count:empty { display: none; }

/* A task was ticked off while another tab was open. */
.aq-sim__tab.has-news { color: var(--aq-green-ink); }
.aq-sim__tab.has-news .aq-sim__tab-count { opacity: 1; animation: aq-pop 420ms var(--aq-ease) both; }

.aq-sim__fold {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--aq-muted);
  cursor: pointer;
  transition: transform 220ms var(--aq-ease), color 180ms var(--aq-ease);
  -webkit-tap-highlight-color: transparent;
}

.aq-sim__fold:hover { color: var(--aq-ink); }
.aq-sim__dock[data-folded="true"] .aq-sim__fold { transform: rotate(180deg); }
.aq-sim__bench[data-layout="wide"] .aq-sim__fold { display: none; }

/* Narrow: the panel is as tall as its tallest card (controls and tasks swipe
   sideways, see "narrow bench" below) and never more than 30% of the screen,
   so the stage keeps the rest. */
.aq-sim__panels {
  min-height: 0;
  max-height: min(30vh, 260px);
  max-height: min(30svh, 260px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.aq-sim__dock[data-folded="true"] .aq-sim__panels { display: none; }
.aq-sim__bench[data-layout="wide"] .aq-sim__panels { flex: 1 1 auto; max-height: none; }
.aq-sim__panel[hidden] { display: none; }

/* ------------------------------------------------------------------- stage */
.aq-sim__stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--aq-navy);
  box-shadow: inset 0 0 0 1px rgba(179, 204, 232, 0.08), 0 1px 2px rgba(12, 26, 46, 0.2);
  animation: aq-enter 380ms var(--aq-ease) both;
}

.aq-sim__canvas {
  display: block;
  width: 100%;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.aq-sim__overlay {
  position: absolute;
  inset: auto 10px 10px auto;
  display: flex;
  gap: 6px;
  pointer-events: none;
}

@keyframes aq-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

/* ----------------------------------------------------------------- toolbar */
.aq-sim__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.aq-sim__toolbar:empty { display: none; }

.aq-spacer { flex: 1 1 auto; }

.aq-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border-strong);
  color: var(--aq-ink);
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms var(--aq-ease), background-color 180ms var(--aq-ease), box-shadow 180ms var(--aq-ease);
  -webkit-tap-highlight-color: transparent;
}

.aq-btn:hover { background: var(--aq-accent-bg); box-shadow: inset 0 0 0 1px var(--aq-border-accent); }
.aq-btn:active { transform: scale(0.97); }
.aq-btn:focus-visible { outline: 3px solid var(--aq-green); outline-offset: 2px; }
.aq-btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.aq-btn--primary {
  background: var(--aq-primary-bg);
  color: var(--aq-primary-ink);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12);
}

.aq-btn--primary svg { color: var(--aq-primary-icon); }
.aq-btn--primary:hover { background: var(--aq-primary-hover); box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12); }

.aq-btn--ghost { background: transparent; }

.aq-btn--chip {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 9999px;
}

.aq-btn--chip[aria-pressed="true"] {
  background: var(--aq-primary-bg);
  color: var(--aq-primary-ink);
  box-shadow: inset 0 0 0 1px var(--aq-primary-bg);
}

/* ---------------------------------------------------------------- readouts */
.aq-sim__readouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 6px;
}

.aq-sim__readouts:empty { display: none; }

/* Narrow: one swipeable row on top of the dock, so the panel keeps its room. */
.aq-sim__bench[data-layout="narrow"] .aq-sim__readouts {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 0 16px;
  scroll-padding: 0 16px;
}

.aq-sim__bench[data-layout="narrow"] .aq-sim__readouts::-webkit-scrollbar { display: none; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__readouts:empty { display: none; }
.aq-sim__bench[data-layout="narrow"] .aq-readout { flex: 1 0 auto; min-width: 88px; max-width: 220px; }

.aq-readout {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px 7px;
  border-radius: 8px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
  min-width: 0;
}

.aq-readout__label {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--aq-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.aq-readout__value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  color: var(--aq-ink);
  white-space: nowrap;
}

.aq-readout__num { font-size: 1rem; font-weight: 600; letter-spacing: -0.02em; }
.aq-readout__unit { font-size: 0.76rem; color: var(--aq-muted); }

.aq-readout--accent { background: var(--aq-accent-bg); box-shadow: inset 0 0 0 1px var(--aq-border-accent); }
.aq-readout--force .aq-readout__label { color: var(--aq-force); }
.aq-readout--motion .aq-readout__label { color: var(--aq-motion); }

/* ---------------------------------------------------------------- equation */
.aq-sim__equation {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--aq-navy);
  color: #EEF3FB;
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.88rem;
  line-height: 1.6;
  overflow-x: auto;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}

.aq-sim__equation:empty { display: none; }
.aq-sim__equation var { font-style: italic; color: #C2E48F; font-weight: 600; }
.aq-sim__equation b { color: #A4D65E; font-weight: 700; }
.aq-sim__equation .aq-eq-muted { color: #B3CCE8; }
.aq-sim__equation .aq-eq-sep { display: inline-block; width: 18px; }
.aq-sim__equation .aq-eq-line { display: block; }
.aq-sim__equation .aq-eq-line + .aq-eq-line { margin-top: 2px; }

/* Mathematics notation from ctx.mathHTML: stacked fractions and roots, anywhere in a lab. */
.aq-sim .aq-frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  margin: 0 0.12em;
  font-size: 0.84em;
  line-height: 1.12;
  text-align: center;
}
.aq-sim .aq-frac__n { padding: 0 0.22em 0.08em; border-bottom: 1.5px solid currentColor; }
.aq-sim .aq-frac__d { padding: 0.08em 0.22em 0; }
.aq-sim .aq-root { white-space: nowrap; }
/* Column vector (ctx.mathHTML "col(3; -2)") and a bold named vector (<span class="aq-vec">a</span>). */
.aq-sim .aq-col {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  margin: 0 0.15em;
  padding: 0 0.35em;
  border-left: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  border-radius: 0.5em / 1.2em;
  font-size: 0.9em;
  line-height: 1.12;
  text-align: center;
}
.aq-sim .aq-vec { font-weight: 800; font-style: normal; }
/* Readout labels are upper-cased; a variable in one keeps its case (b² − 4ac, not B² − 4AC). */
.aq-readout__label var { text-transform: none; }
.aq-sim .aq-root__arg { margin-left: 0.04em; padding: 0 0.12em; border-top: 1.5px solid currentColor; }
/* A compact table inside the equation strip (tables of values, frequency tables). */
.aq-sim__equation .aq-eq-table { border-collapse: collapse; margin: 4px 0 2px; font-size: 0.95em; }
.aq-sim__equation .aq-eq-table th,
.aq-sim__equation .aq-eq-table td { padding: 1px 8px; border: 1px solid rgba(179, 204, 232, 0.25); text-align: center; white-space: nowrap; }
.aq-sim__equation .aq-eq-table th { color: #B3CCE8; font-weight: 600; text-align: left; }

/* --------------------------------------- aside (CS), code listings, tables */
/* ctx.layout() `panel`: a region under the stage, in the stage's column, for ctx.code / ctx.table. */
.aq-sim__aside {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  min-width: 0;
}
.aq-sim__aside:empty { display: none; }

/* ctx.code(): a listing on the stage navy in both themes, keywords coloured. */
.aq-code {
  min-width: 0;
  border-radius: 12px;
  background: #0C1A2E;
  box-shadow: inset 0 0 0 1px rgba(179, 204, 232, 0.12);
  color: #EEF3FB;
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.84rem;
  line-height: 1.55;
  overflow: hidden;
}
.aq-code__title {
  padding: 8px 12px 6px;
  border-bottom: 1px solid rgba(179, 204, 232, 0.12);
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #B3CCE8;
}
.aq-sim .aq-code__lines {
  margin: 0;
  padding: 6px 0;
  list-style: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.aq-sim .aq-code__line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: max-content;
  margin: 0;
  padding: 0 12px 0 0;
  border-left: 3px solid transparent;
  white-space: pre;
  transition: background-color 160ms var(--aq-ease), border-color 160ms var(--aq-ease);
}
.aq-code__no {
  flex: 0 0 2.2em;
  text-align: right;
  color: #7AAAD4;
  opacity: 0.7;
  user-select: none;
  -webkit-user-select: none;
}
.aq-code__src { flex: 0 0 auto; }
.aq-code__note { flex: 0 0 auto; color: #F5A04A; font-weight: 600; }
.aq-code__note:empty { display: none; }
.aq-code__line.is-current { background: rgba(164, 214, 94, 0.16); border-left-color: #A4D65E; }
.aq-code__line.is-done { background: rgba(124, 197, 242, 0.1); border-left-color: #7CC5F2; }
.aq-code__line.is-error { background: rgba(249, 138, 122, 0.16); border-left-color: #F98A7A; }
.aq-code__line.is-muted { opacity: 0.45; }
.aq-code__line.is-clickable { cursor: pointer; }
.aq-code__line.is-clickable:hover { background: rgba(217, 230, 245, 0.07); }
.aq-code__line.is-clickable:focus-visible { outline: 2px solid #A4D65E; outline-offset: -2px; }
.aq-tok-kw { color: #7CC5F2; font-weight: 700; }
.aq-tok-fn { color: #C2E48F; }
.aq-tok-type { color: #F98A7A; }
.aq-tok-str { color: #F5A04A; }
.aq-tok-num { color: #C2E48F; }
.aq-tok-com { color: #7AAAD4; font-style: italic; }
.aq-tok-op { color: #A4D65E; font-weight: 700; }
/* Inline code in task text, the equation strip or a readout: codeHTML inside <code class="aq-code-inline">. */
.aq-sim .aq-code-inline {
  padding: 0.05em 0.35em;
  border-radius: 4px;
  background: #0C1A2E;
  color: #EEF3FB;
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.9em;
  white-space: pre-wrap;
}
.aq-sim__equation .aq-code-inline { padding: 0; background: none; }

/* ctx.table(): trace tables, truth tables, database tables and query results. */
.aq-table-wrap {
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--aq-border);
  background: var(--aq-card);
}
.aq-sim .aq-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.84rem;
  color: var(--aq-ink);
}
.aq-table--mono td { font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace); font-variant-numeric: tabular-nums; }
.aq-table__caption {
  padding: 8px 12px 4px;
  caption-side: top;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--aq-muted);
}
.aq-sim .aq-table th,
.aq-sim .aq-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--aq-border);
  text-align: center;
  white-space: nowrap;
  transition: background-color 180ms var(--aq-ease);
}
.aq-sim .aq-table--left th,
.aq-sim .aq-table--left td { text-align: left; }
.aq-sim .aq-table th {
  background: var(--aq-soft);
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--aq-ink-2);
}
.aq-sim .aq-table tr:last-child td { border-bottom: 0; }
.aq-sim .aq-table .is-current { background: var(--aq-accent-bg); box-shadow: inset 3px 0 0 var(--aq-green); }
.aq-sim .aq-table td.is-current { box-shadow: inset 0 0 0 2px var(--aq-green); }
.aq-sim .aq-table .is-new { background: var(--aq-accent-bg); font-weight: 700; }
.aq-sim .aq-table .is-match { background: var(--aq-accent-bg); }
.aq-sim .aq-table .is-error { background: rgba(220, 38, 38, 0.1); color: var(--aq-force); font-weight: 700; }
.aq-sim .aq-table .is-muted { opacity: 0.4; }

/* ---------------------------------------------------------------- controls */
.aq-sim__controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 18px;
  padding: 4px 2px 2px;
}

.aq-sim__bench[data-layout="wide"] .aq-sim__controls { grid-template-columns: 1fr; }

.aq-sim__controls:empty { display: none; }

.aq-ctl { min-width: 0; }
.aq-ctl.is-disabled { opacity: 0.55; }
.aq-ctl--wide { grid-column: 1 / -1; }

.aq-ctl__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}

.aq-ctl__label {
  display: block;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--aq-ink-2);
}

.aq-ctl--seg .aq-ctl__label { margin-bottom: 6px; }

.aq-ctl__value {
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--aq-ink);
  white-space: nowrap;
}

.aq-ctl__hint {
  margin: 2px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--aq-muted);
}

/* Range input with a green fill up to the thumb. */
.aq-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}

.aq-range:focus { outline: none; }

.aq-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 9999px;
  background: linear-gradient(90deg, var(--aq-green) 0 var(--fill), var(--aq-border-strong) var(--fill) 100%);
}

.aq-range::-moz-range-track {
  height: 6px;
  border-radius: 9999px;
  background: var(--aq-border-strong);
}

.aq-range::-moz-range-progress {
  height: 6px;
  border-radius: 9999px;
  background: var(--aq-green);
}

.aq-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--aq-navy);
  border: 3px solid var(--aq-green);
  box-shadow: 0 2px 6px rgba(12, 26, 46, 0.35);
  transition: transform 140ms var(--aq-ease);
}

.aq-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--aq-navy);
  border: 3px solid var(--aq-green);
  box-shadow: 0 2px 6px rgba(12, 26, 46, 0.35);
}

.aq-range:active::-webkit-slider-thumb { transform: scale(1.12); }
.aq-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(164, 214, 94, 0.45); }
.aq-range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(164, 214, 94, 0.45); }
.aq-range:disabled { cursor: not-allowed; }

/* Segmented control. */
.aq-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
}

.aq-sim__bench[data-layout="wide"] .aq-seg { background: var(--aq-card); }

.aq-seg__btn {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--aq-ink-2);
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 180ms var(--aq-ease), color 180ms var(--aq-ease), transform 140ms var(--aq-ease);
  -webkit-tap-highlight-color: transparent;
}

.aq-seg__btn:hover { background: var(--aq-accent-bg); }
.aq-seg__btn:active { transform: scale(0.97); }
.aq-seg__btn:focus-visible { outline: 3px solid var(--aq-green); outline-offset: 1px; }
.aq-seg__btn:disabled { cursor: not-allowed; }
.aq-seg__btn:disabled:hover { background: transparent; }
.aq-seg__btn[aria-checked="true"]:disabled:hover { background: var(--aq-primary-bg); }

.aq-seg__btn[aria-checked="true"] {
  background: var(--aq-primary-bg);
  color: var(--aq-primary-ink);
  box-shadow: 0 1px 3px rgba(12, 26, 46, 0.3);
}

/* Switch. */
.aq-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--aq-ink-2);
}

.aq-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.aq-switch__track {
  position: relative;
  flex-shrink: 0;
  width: 38px;
  height: 22px;
  border-radius: 9999px;
  background: var(--aq-border-strong);
  transition: background-color 200ms var(--aq-ease);
}

.aq-switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(12, 26, 46, 0.35);
  transition: transform 220ms var(--aq-ease);
}

.aq-switch input:checked + .aq-switch__track { background: var(--aq-primary-bg); }
.aq-switch input:checked + .aq-switch__track::after { transform: translateX(16px); background: var(--aq-primary-icon); }
.aq-switch.is-disabled { opacity: 0.55; cursor: not-allowed; }
.aq-switch input:focus-visible + .aq-switch__track { outline: 3px solid var(--aq-green); outline-offset: 2px; }

/* -------------------------------------------------------------- challenges */
.aq-sim__challenges { padding: 4px 2px 2px; }

.aq-sim__challenges:empty { display: none; }

.aq-ch__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.aq-ch__title {
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--aq-ink-2);
}

.aq-ch__count {
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--aq-muted);
}

.aq-ch__bar {
  height: 5px;
  margin: 8px 0 10px;
  border-radius: 9999px;
  background: var(--aq-border);
  overflow: hidden;
}

.aq-ch__fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--aq-green);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 600ms var(--aq-ease);
}

.aq-sim .aq-ch__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.aq-sim .aq-ch__item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
  transition: background-color 300ms var(--aq-ease), box-shadow 300ms var(--aq-ease);
}

.aq-sim__bench[data-layout="wide"] .aq-ch__item { background: var(--aq-card); }

.aq-ch__mark {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--aq-card);
  box-shadow: inset 0 0 0 1.5px var(--aq-border-strong);
  font-family: var(--font-mono-stack, 'Fira Code', ui-monospace, monospace);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--aq-muted);
}

.aq-ch__body { min-width: 0; }

.aq-sim .aq-ch__text {
  margin: 1px 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--aq-ink);
}

.aq-sim .aq-ch__explain {
  display: none;
  margin: 6px 0 1px;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--aq-ink-2);
}

.aq-sim .aq-ch__item.is-done {
  background: var(--aq-accent-bg);
  box-shadow: inset 0 0 0 1px var(--aq-border-accent);
}

.aq-ch__item.is-done .aq-ch__mark {
  background: var(--aq-primary-bg);
  box-shadow: none;
  color: var(--aq-primary-icon);
  animation: aq-pop 420ms var(--aq-ease) both;
}

.aq-sim .aq-ch__item.is-done .aq-ch__explain {
  display: block;
  animation: aq-reveal 380ms var(--aq-ease) both;
}

.aq-sim .aq-ch__explain:empty { display: none !important; }

@keyframes aq-pop {
  from { transform: scale(0.95); opacity: 0.4; }
  60% { transform: scale(1.12); opacity: 1; }
  to { transform: scale(1); }
}

@keyframes aq-reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ----------------------------------------------------------- examiner note */
.aq-sim__examiner {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--aq-card);
  box-shadow: inset 0 0 0 1px var(--aq-border);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--aq-ink);
}

.aq-sim__examiner strong {
  font-family: var(--font-display-stack, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-weight: 800;
  color: var(--aq-ink-2);
}

.aq-sim__examiner svg { flex-shrink: 0; margin-top: 2px; color: var(--aq-green-ink); }

/* ------------------------------------------------------------------ extras */
.aq-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.aq-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--aq-muted);
}

.aq-legend span { display: inline-flex; align-items: center; gap: 6px; }
.aq-legend i { display: inline-block; width: 14px; height: 4px; border-radius: 4px; }

/* ------------------------------------------- narrow bench: a compact dock */
/* On a phone the dock shares the screen with the stage, so every row is one
   line high and the panel swipes sideways instead of growing downwards: one
   control (or task) per card, the next one peeking in. A vertical swipe on the
   dock scrolls the page as usual. */
.aq-sim__bench[data-layout="narrow"] .aq-sim__dock { gap: 6px; padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }

.aq-sim__bench[data-layout="narrow"] .aq-readout {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  max-width: none;
  padding: 4px 9px;
}

.aq-sim__bench[data-layout="narrow"] .aq-readout__label { font-size: 0.62rem; }
.aq-sim__bench[data-layout="narrow"] .aq-readout__num { font-size: 0.9rem; }
.aq-sim__bench[data-layout="narrow"] .aq-readout__unit { font-size: 0.7rem; }

.aq-sim__bench[data-layout="narrow"] .aq-sim__toolbar {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.aq-sim__bench[data-layout="narrow"] .aq-sim__toolbar::-webkit-scrollbar { display: none; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__toolbar > * { flex-shrink: 0; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__toolbar .aq-btn { min-height: 36px; padding: 6px 11px; font-size: 0.8rem; white-space: nowrap; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__toolbar .aq-seg { padding: 3px; flex-wrap: nowrap; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__toolbar .aq-seg__btn { min-height: 30px; padding: 4px 10px; }

.aq-sim__bench[data-layout="narrow"] .aq-sim__tabs { padding: 3px; gap: 2px; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__tab { min-height: 30px; padding: 4px 8px; font-size: 0.76rem; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__fold { width: 30px; height: 30px; }

/* Controls and tasks: a sideways swipe of cards. */
.aq-sim__bench[data-layout="narrow"] .aq-sim__controls,
.aq-sim__bench[data-layout="narrow"] .aq-ch__list {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 0 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.aq-sim__bench[data-layout="narrow"] .aq-sim__controls::-webkit-scrollbar,
.aq-sim__bench[data-layout="narrow"] .aq-ch__list::-webkit-scrollbar { display: none; }

.aq-sim__bench[data-layout="narrow"] .aq-sim__controls > *,
.aq-sim__bench[data-layout="narrow"] .aq-ch__item {
  flex: 0 0 92%;
  min-width: 0;
  scroll-snap-align: start;
}

.aq-sim__bench[data-layout="narrow"] .aq-sim__controls > :only-child,
.aq-sim__bench[data-layout="narrow"] .aq-ch__item:only-child { flex-basis: 100%; }

.aq-sim__bench[data-layout="narrow"] .aq-sim__controls > * {
  padding: 8px 10px 6px;
  border-radius: 10px;
  background: var(--aq-soft);
  box-shadow: inset 0 0 0 1px var(--aq-border);
}

.aq-sim__bench[data-layout="narrow"] .aq-ctl__hint { display: none; }
.aq-sim__bench[data-layout="narrow"] .aq-ctl--seg .aq-ctl__label { margin-bottom: 4px; }
.aq-sim__bench[data-layout="narrow"] .aq-seg { gap: 3px; padding: 3px; background: var(--aq-card); }
.aq-sim__bench[data-layout="narrow"] .aq-seg__btn { flex: 1 0 auto; min-height: 30px; padding: 4px 7px; font-size: 0.72rem; }
.aq-sim__bench[data-layout="narrow"] .aq-ctl__label,
.aq-sim__bench[data-layout="narrow"] .aq-ctl__value { font-size: 0.8rem; }
.aq-sim__bench[data-layout="narrow"] .aq-range { height: 26px; }
.aq-sim__bench[data-layout="narrow"] .aq-switch { min-height: 30px; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__challenges { padding: 2px 0 0; }
.aq-sim__bench[data-layout="narrow"] .aq-ch__bar { margin: 6px 0 6px; }
.aq-sim__bench[data-layout="narrow"] .aq-sim__equation { padding: 8px 12px; font-size: 0.82rem; }

/* ------------------------------------------------------------- responsive */
@container aqsim (max-width: 520px) {
  .aq-sim__lede-text { display: none; }
  .aq-sim__lede { -webkit-line-clamp: 1; line-clamp: 1; }
  .aq-sim__head { padding: 10px 12px 8px; gap: 10px; }
  .aq-sim__badge { width: 32px; height: 32px; border-radius: 8px; }
  .aq-sim .aq-sim__title { font-size: 1rem; }
  .aq-sim__lede { font-size: 0.82rem; }
  .aq-sim__mount { padding: 0 10px 10px; }
  .aq-sim__dock { margin: 0 -10px -10px; padding-left: 10px; padding-right: 10px; }
  .aq-sim__bench[data-layout="narrow"] .aq-sim__readouts { margin: 0 -10px; padding: 0 10px; scroll-padding: 0 10px; }
  .aq-sim__about { margin: 0 10px 12px; }
  .aq-sim__controls { grid-template-columns: 1fr; }
  .aq-btn { padding: 8px 12px; }
  .aq-sim .aq-table th,
  .aq-sim .aq-table td { padding: 4px 6px; }
  .aq-code { font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .aq-sim *,
  .aq-sim *::before,
  .aq-sim *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

@media print {
  .aq-sim { display: none !important; }
}
