/* ============================================================================
   Curio — instrument kit
   ----------------------------------------------------------------------------
   The shared "instrument" shell every stage-based Curio uses: a fixed control
   panel beside a full-bleed canvas stage, with glass overlays floating on top.
   Pairs with tokens.css (import that first for tokens + fonts).

   Two hard rules, enforced here:
   - Chrome (panel, buttons, sliders, borders, text) is INK + BRASS only.
   - Data marks on the stage use the data spectrum — set on the <canvas>, not here.

   Derived from the design system's explorer UI kit; generalized so both the
   Ellipse Explorer and Whispering Gallery (and future curios) share one skin.
   ========================================================================== */

html, body { margin: 0; height: 100%; }
body.curio-instrument {
  background: var(--bg);
  color: var(--fg-1);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
*, *::before, *::after { box-sizing: border-box; }

.instrument { display: flex; height: 100vh; }

/* ---- Control panel (the fixed left rail) ------------------------------- */
.panel {
  width: 340px; min-width: 340px; height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px 18px 48px;
}
.panel::-webkit-scrollbar { width: 9px; }
.panel::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 9px; border: 2px solid var(--surface); }

/* Back affordance — explicit breadcrumb + the brand mark doubles as a home link */
.panel-back {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-ui);
  text-transform: uppercase; letter-spacing: 0.085em;
  font-size: 11px; font-weight: 600;
  color: var(--fg-3); text-decoration: none;
  white-space: nowrap;
  margin-bottom: 16px;
  transition: color 0.15s ease;
}
.panel-back .chev { display: inline-block; transition: transform 0.15s ease; }
.panel-back:hover { color: var(--brass-bright); }
.panel-back:hover .chev { transform: translateX(-3px); }
.panel-back:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 3px; border-radius: var(--r-xs); }

.panel-head { display: flex; align-items: flex-start; gap: 11px; margin-bottom: 6px; }
.panel-mark { display: inline-flex; margin-top: -3px; border-radius: 8px; transition: filter 0.15s ease, transform 0.15s ease; }
.panel-mark:hover { filter: drop-shadow(var(--glow-brass)); transform: translateY(-1px); }
.panel-mark:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 3px; }
.panel-head img { width: 30px; height: 30px; display: block; }
.panel-title { font-family: var(--font-display); font-weight: 600; font-size: 23px; letter-spacing: -0.01em; line-height: 1.1; color: var(--fg-1); }
.panel-sub { font-family: var(--font-display); font-style: italic; font-size: 14px; line-height: 1.4; color: var(--fg-2); margin: 4px 0 18px; }

/* ---- Control group ----------------------------------------------------- */
.group { margin-bottom: 16px; padding: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.group-eyebrow { font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-3); margin-bottom: 11px; }
.group-eyebrow .accent { color: var(--brass); }

/* Prose caption inside a group (instructions, asides) — sans, not mono. */
.caption { font-family: var(--font-ui); font-weight: 400; font-size: 11.5px; line-height: 1.45; color: var(--fg-3); margin: 8px 0 0; }
.caption b { color: var(--fg-2); font-weight: 600; }

/* ---- Mode / shape selector grid ---------------------------------------- */
.modegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.modegrid.one { grid-template-columns: 1fr; }
.cell {
  text-align: left; background: var(--surface-3); color: var(--fg-1);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 11px; cursor: pointer; line-height: 1.25;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 500;
}
.cell small { display: block; color: var(--fg-3); font-size: 10px; margin-top: 2px; font-weight: 400; }
.cell:hover { border-color: var(--line-strong); }
.cell:active { transform: scale(0.985); }
.cell.active { background: var(--brass-wash); border-color: var(--brass-line); color: var(--brass-bright); }
.cell.active small { color: var(--brass); }
.cell.disabled { opacity: 0.4; filter: grayscale(0.5); cursor: not-allowed; }
.cell:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 2px; }

/* ---- Buttons ----------------------------------------------------------- */
.btnrow { display: flex; gap: 7px; flex-wrap: wrap; }
.btn {
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 500;
  background: var(--surface-3); color: var(--fg-1);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 12px; cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { border-color: var(--line-strong); color: #fff; }
.btn:active { transform: scale(0.985); }
.btn:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 2px; }
.btn.primary { background: var(--brass); border-color: var(--brass-deep); color: var(--brass-ink); font-weight: 600; }
.btn.primary:hover { background: var(--brass-bright); color: var(--brass-ink); }
.btn.primary.playing { box-shadow: var(--glow-brass); }
.btn.ghost { background: transparent; }
/* Engaged toggle (e.g. "Ray paths" on, "Pause" active) — brass wash, like a selected cell. */
.btn.active { background: var(--brass-wash); border-color: var(--brass-line); color: var(--brass-bright); }

/* ---- Slider ------------------------------------------------------------ */
.field { margin: 4px 0 2px; }
.field + .field { margin-top: 12px; }
.field-lab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.field-lab .name { font-size: 12.5px; color: var(--fg-2); }
.field-lab .val { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--fg-1); font-variant-numeric: tabular-nums; }
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 5px; border-radius: var(--r-full); background: var(--surface-3); outline: none; cursor: pointer; }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: var(--r-full); background: var(--brass); border: 2px solid var(--surface); box-shadow: var(--glow-brass); cursor: pointer; transition: background var(--t-fast); }
.range::-webkit-slider-thumb:hover { background: var(--brass-bright); }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: var(--r-full); background: var(--brass); border: 2px solid var(--surface); cursor: pointer; }
.range:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 3px; }
.field-sub { font-family: var(--font-mono); font-size: 10.5px; color: var(--fg-3); margin-top: 9px; }

/* ---- Preset list ------------------------------------------------------- */
.presets { display: flex; flex-direction: column; gap: 7px; }
.preset { text-align: left; background: var(--surface-3); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; cursor: pointer; color: var(--fg-1); transition: border-color var(--t-fast) var(--ease); font-family: var(--font-ui); }
.preset .n { font-size: 12.5px; font-weight: 600; color: var(--fg-1); }
.preset .m { display: block; font-size: 10.5px; color: var(--fg-3); margin-top: 2px; }
.preset:hover { border-color: var(--brass-line); }
.preset:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 2px; }

/* ---- Readout block ----------------------------------------------------- */
.readout-block { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 11px 13px; }
.readout-block .row { display: flex; justify-content: space-between; padding: 2.5px 0; font-family: var(--font-mono); font-size: 12px; }
.readout-block .k { color: var(--fg-3); }
.readout-block .v { color: var(--fg-1); font-variant-numeric: tabular-nums; }

/* ---- Degenerate / honesty note (in panel; toggled via .show) ----------- */
.note { display: none; margin-top: 10px; font-size: 11.5px; line-height: 1.4; color: #ffd9a0; background: rgba(217,164,65,0.08); border: 1px solid var(--brass-line); border-radius: var(--r-sm); padding: 8px 10px; }
.note.show { display: block; }

/* ---- Stage ------------------------------------------------------------- */
.stage { flex: 1; position: relative; min-width: 0;
  background-color: var(--stage);
  /* The design system's signature stage: a near-invisible --line-faint grid
     under a faint warm radial glow (the --stage-grid token). */
  background-image: var(--stage-grid);
  background-size: auto, var(--grid-size) var(--grid-size), var(--grid-size) var(--grid-size);
}
.stage canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

/* ---- Floating overlays ------------------------------------------------- */
.glass { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-3); }

/* HUD meter cluster (top-left). */
.hud { position: absolute; top: 16px; left: 16px; display: flex; gap: 12px; flex-wrap: wrap; pointer-events: none; }
.hud .card { padding: 13px 15px; pointer-events: auto; }
.hud .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--fg-3); }
.hud .big { font-family: var(--font-mono); font-weight: 600; font-size: 26px; color: var(--fg-1); font-variant-numeric: tabular-nums; line-height: 1; margin: 6px 0; }
.hud .big .unit { font-size: 13px; color: var(--fg-3); font-weight: 500; }
.hud .bar { height: 8px; border-radius: var(--r-full); background: rgba(0,0,0,0.35); overflow: hidden; margin-top: 4px; }
.hud .bar > i { display: block; height: 100%; width: 0; border-radius: var(--r-full); transition: width var(--t-base) var(--ease); }
.hud .verdict { font-weight: 600; font-size: 12.5px; margin-top: 8px; }
.hud .legendline { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 11px; color: var(--fg-3); margin-top: 9px; }
.hud .legendline .dot { width: 8px; height: 8px; border-radius: var(--r-full); display: inline-block; margin-right: 5px; vertical-align: middle; }

/* Legend (top-right): color keys. */
.legend { position: absolute; top: 16px; right: 16px; padding: 11px 13px; pointer-events: none; }
.legend .li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 11.5px; color: var(--fg-2); }
.legend i.line { width: 13px; height: 3px; border-radius: 2px; }
.legend i.dot { width: 9px; height: 9px; border-radius: var(--r-full); }

/* Explain card (bottom-left): eyebrow tag + serif prose. Collapsible — the
   toggle hides the prose while keeping the tag visible; defaults to open. */
.explain { position: absolute; left: 16px; bottom: 16px; max-width: 480px; padding: 15px 17px; }
.explain.collapsed { max-width: max-content; padding-bottom: 13px; }
.explain-head { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }
.explain.collapsed .explain-head { margin-bottom: 0; }
.explain .tag { display: inline-block; white-space: nowrap; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brass); border: 1px solid var(--brass-line); border-radius: var(--r-xs); padding: 3px 8px; margin: 0; }
.explain-toggle { margin-left: auto; flex: none; width: 22px; height: 22px; display: grid; place-items: center; font-family: var(--font-mono); font-size: 15px; line-height: 1; color: var(--brass); background: transparent; border: 1px solid var(--brass-line); border-radius: var(--r-xs); cursor: pointer; transition: background var(--t-base) var(--ease), color var(--t-base) var(--ease); }
.explain-toggle:hover { background: rgba(217,164,65,0.12); color: var(--brass-bright); }
.explain .prose { font-family: var(--font-display); font-size: 15px; line-height: 1.56; color: #c9d2df; margin: 0; }
.explain.collapsed .prose { display: none; }
.explain .prose em, .explain .prose i { font-style: italic; color: var(--fg-1); }
.explain .prose b { font-weight: 600; color: #fff; }

/* Hint line (bottom-right). */
.hint { position: absolute; right: 16px; bottom: 16px; font-size: 11px; color: var(--fg-3); padding: 7px 11px; max-width: 320px; text-align: right; pointer-events: none; }
.hint b { color: var(--brass-bright); }

/* ---- Responsive: the one break the system needs ------------------------ */
@media (max-width: 880px) {
  body.curio-instrument { overflow: auto; }
  .instrument { flex-direction: column; height: auto; }
  .panel { width: 100%; min-width: 0; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .stage { height: 64vh; }
  .explain { position: static; max-width: none; margin: 12px 16px 24px; }
}

/* ============================================================================
   DEEP-DIVE ENTRY POINTS (optional) — the three triggers + the reader modal.
   Use any subset on a curio; none are required. Mirrors the explorer kit's
   DeepDive components (design/system/ui_kits/explorer/DeepDive.jsx).
   ========================================================================== */

/* ---- TRIGGER: explain-card "read the full story" link ------------------ */
.read-more {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  margin-top: 11px;
  font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  color: var(--brass); text-decoration: none;
  border: 0; background: transparent; padding: 0; cursor: pointer;
  transition: color var(--t-fast) var(--ease), gap var(--t-fast) var(--ease);
}
.read-more .arr { transition: transform var(--t-fast) var(--ease); }
.read-more:hover { color: var(--brass-bright); gap: 8px; }
.read-more:hover .arr { transform: translateX(2px); }
.read-more:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 3px; border-radius: var(--r-xs); }

/* ---- TRIGGER: info glyph on a control-group eyebrow -------------------- */
.group-eyebrow.has-info { display: flex; align-items: center; gap: 8px; }
.info-glyph {
  margin-left: auto; flex: none;
  width: 18px; height: 18px; display: grid; place-items: center;
  font-family: var(--font-display); font-style: italic; font-weight: 600; font-size: 12px; line-height: 1;
  color: var(--fg-3);
  background: transparent; border: 1px solid var(--line); border-radius: var(--r-full);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.info-glyph:hover { color: var(--brass-bright); border-color: var(--brass-line); background: var(--brass-wash); }
.info-glyph:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 2px; }

/* ---- TRIGGER: "About this curio" ghost link, foot of the rail ---------- */
.about-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; margin-top: 14px; padding: 11px 13px;
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 500;
  color: var(--fg-2); text-align: left;
  background: transparent; border: 1px dashed var(--line-strong); border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.about-link .arr { color: var(--fg-3); transition: transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.about-link:hover { color: var(--fg-1); border-color: var(--brass-line); background: var(--surface-2); }
.about-link:hover .arr { color: var(--brass-bright); transform: translateX(3px); }
.about-link:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 2px; }

/* ---- THE READER MODAL -------------------------------------------------- */
.m-scrim {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 4vh 24px;
  background: rgba(7,10,14,0.62);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: m-fade var(--t-base) var(--ease-out) both;
}
.m-scrim[hidden] { display: none; }
.m-panel {
  position: relative; width: min(820px, 100%); max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3), var(--hairline-top); overflow: hidden;
  animation: m-rise var(--t-slow) var(--ease-out) both;
}
.m-head { position: relative; flex: none; padding: 26px 30px 20px; border-bottom: 1px solid var(--line); }
.m-eyebrow {
  display: inline-block; white-space: nowrap;
  font-family: var(--font-ui); font-size: 10px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--brass); border: 1px solid var(--brass-line); border-radius: var(--r-xs);
  padding: 4px 9px; margin-bottom: 14px;
}
.m-title { font-family: var(--font-display); font-weight: 600; font-size: 30px; line-height: 1.12; letter-spacing: -0.01em; color: var(--fg-1); margin: 0; max-width: 30ch; text-wrap: pretty; }
.m-dek { font-family: var(--font-display); font-style: italic; font-size: 16px; line-height: 1.45; color: var(--fg-2); margin: 10px 0 0; max-width: 56ch; }
.m-close {
  position: absolute; top: 20px; right: 22px; width: 34px; height: 34px; flex: none;
  display: grid; place-items: center; font-family: var(--font-ui); font-size: 19px; line-height: 1;
  color: var(--fg-3); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.m-close:hover { color: var(--fg-1); border-color: var(--line-strong); background: var(--surface-3); }
.m-close:focus-visible { outline: 2px solid var(--brass-line); outline-offset: 2px; }

.m-body { overflow-y: auto; padding: 24px 30px 30px; }
.m-body::-webkit-scrollbar { width: 10px; }
.m-body::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--surface); }

/* Reader body blocks */
.m-prose-p { font-family: var(--font-display); font-size: 17px; line-height: 1.64; color: #c6cfdc; margin: 0 0 16px; max-width: 64ch; text-wrap: pretty; }
.m-prose-p:last-child { margin-bottom: 0; }
.m-prose-p em { font-style: italic; color: var(--fg-1); }
.m-prose-p b, .m-prose-p strong { font-weight: 600; color: #fff; }
.m-lead { font-size: 19px; line-height: 1.5; color: var(--fg-1); margin-bottom: 22px; }

.m-figure { margin: 22px 0; }
.m-figslot {
  height: 220px; border-radius: var(--r-md); border: 1px solid var(--line);
  background: repeating-linear-gradient(135deg, rgba(159,170,187,0.05) 0 10px, transparent 10px 20px), var(--stage);
  display: grid; place-items: center;
}
.m-figslot span { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-3); letter-spacing: 0.02em; }
/* Site extension: a slot holding a real plate instead of the striped
   placeholder ("drop a real diagram in later" — DeepDive.jsx). */
.m-figslot.has-img { height: auto; display: block; overflow: hidden; }
.m-figslot.has-img img { display: block; width: 100%; height: auto; }
.m-figcap { margin-top: 9px; font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); }

.m-quote { margin: 24px 0; padding: 4px 0 4px 20px; border-left: 2px solid var(--brass-line); font-family: var(--font-display); font-style: italic; font-size: 20px; line-height: 1.4; color: var(--fg-1); max-width: 50ch; }

.m-terms { margin: 26px 0 4px; }
.m-termlist { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.m-term { display: grid; grid-template-columns: 150px 1fr; gap: 16px; padding: 12px 15px; background: var(--surface-2); }
.m-term dt { font-family: var(--font-display); font-style: italic; font-size: 15px; color: var(--brass-bright); }
.m-term dd { margin: 0; font-family: var(--font-ui); font-size: 13px; line-height: 1.5; color: var(--fg-2); }

.m-read { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.m-reads { display: flex; flex-direction: column; gap: 8px; }
.m-readitem { display: flex; align-items: baseline; gap: 10px; padding: 9px 0; font-family: var(--font-ui); font-size: 13.5px; color: var(--fg-1); text-decoration: none; border-bottom: 1px solid var(--line); }
.m-reads .m-readitem:last-child { border-bottom: 0; }
.m-readitem .src { font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); margin-left: auto; white-space: nowrap; }
.m-readitem .ext { color: var(--brass); flex: none; }
.m-readitem:hover, .m-readitem:hover .ext { color: var(--brass-bright); }

.m-h { font-family: var(--font-ui); font-weight: 600; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-3); margin: 0 0 12px; }

@keyframes m-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes m-rise { from { opacity: 0; transform: translateY(14px) scale(0.99); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .m-scrim, .m-panel { animation: none; } }
