:root {
  --bg: #0c1424; --panel: #0f1a2e; --border: #2a4a7a; --text: #d8e0ec; --dim: #7f8ba3; --accent: #4aa8ff;
  --warn: #f0a030; --ok: #3ccf7a; --bad: #e5534b; --tok: #f5c542; --steer: #b48cff;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --bg: #f4f6fb; --panel: #ffffff; --border: #9fb3d6; --text: #1b2333; --dim: #5d6880; --accent: #1f6fd1; --warn: #b36b00; --tok: #9a6b00; --steer: #6b3fd1; }
}
:root[data-theme="light"] { --bg: #f4f6fb; --panel: #ffffff; --border: #9fb3d6; --text: #1b2333; --dim: #5d6880; --accent: #1f6fd1; --warn: #b36b00; --tok: #9a6b00; --steer: #6b3fd1; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* .row's display:flex must not un-hide hidden rows */
body { margin: 0; height: 100vh; display: flex; flex-direction: column; overflow-x: hidden; background: var(--bg); color: var(--text); font: 13px/1.45 "JetBrains Mono", ui-monospace, Menlo, monospace; }
button, select, input, textarea { font: inherit; color: var(--text); background: transparent; border: 1px solid var(--border); border-radius: 3px; padding: 3px 8px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.accent { border-color: var(--accent); color: var(--accent); }
button.warn { border-color: var(--warn); color: var(--warn); }
button:disabled { opacity: .45; cursor: default; }
select option { background: var(--panel); }
input[type=number] { width: 72px; }
#featureId { width: 13ch; }
.dim { color: var(--dim); }
select, input { max-width: 100%; }
.row > *, .group > * { min-width: 0; }
.group { max-width: 100%; }
.topbar { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.brand { font-weight: bold; }
.group { display: inline-flex; gap: 6px; align-items: center; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button.on { background: var(--accent); color: var(--bg); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); margin-left: 4px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.status { margin-left: auto; color: var(--dim); flex: 1 1 280px; text-align: right; white-space: normal; overflow-wrap: anywhere; }
.grid { display: grid; grid-template-columns: minmax(300px, 1.1fr) minmax(420px, 2.4fr) minmax(300px, 1.1fr); gap: 10px; padding: 10px; flex: 1; min-height: 0; }
@media (max-width: 1100px) { body { height: auto; min-height: 100vh; } .grid { grid-template-columns: minmax(0, 1fr); flex: none; } }
.panel { position: relative; border: 1px solid var(--border); border-radius: 4px; padding: 16px 0 10px; background: var(--panel); overflow: visible; display: flex; flex-direction: column; min-height: 0; margin-top: 8px; }
.panel > .body { overflow: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 0 12px; }
.panel h2 { position: absolute; top: -10px; left: 10px; margin: 0; padding: 0 6px; font-size: 13px; line-height: 20px; background: var(--panel); z-index: 1; }
.panel h2 sup { color: var(--accent); }
.panel h3 { margin: 6px 0 0; font-size: 12px; color: var(--dim); font-weight: normal; text-transform: lowercase; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.label { color: var(--accent); }
#examples { margin: 0; padding-left: 22px; }
#examples li { margin-bottom: 5px; color: var(--dim); word-break: break-word; }
#examples li b { color: var(--tok); font-weight: normal; background: rgba(245,197,66,.13); }
#examples li .act { color: var(--text); margin-right: 6px; }
#ivList { padding-left: 16px; margin: 0; }
#ivList li { margin: 3px 0; }
#ivList .k-add { color: var(--steer); } #ivList .k-ablate { color: var(--warn); }
#ivList button { padding: 0 5px; margin-left: 6px; }
.columns { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; flex: 1; min-height: 0; }
.column { border: 1px solid var(--border); border-radius: 3px; padding: 8px; overflow: auto; min-height: 0; }
.column h4 { margin: 0 0 6px; font-weight: normal; }
.column.default h4 { color: var(--text); } .column.steered h4 { color: var(--steer); } .column.ablated h4 { color: var(--warn); }
.msg { margin: 6px 0; white-space: pre-wrap; word-break: break-word; }
.msg.user { color: var(--dim); }
.msg.user::before { content: "› "; }
.msg .meta { color: var(--dim); font-size: 11px; }
details.thinking { color: var(--dim); font-size: 12px; }
.composer { display: flex; gap: 6px; }
.composer textarea { flex: 1; resize: vertical; }
.composer .col { display: flex; flex-direction: column; gap: 4px; }
#assistantLog { flex: 1; overflow: auto; min-height: 80px; }
#assistantLog .a { white-space: pre-wrap; margin: 6px 0; }
#assistantLog .u { color: var(--dim); margin: 6px 0; }
#suggestions .chip { display: block; text-align: left; width: 100%; margin: 4px 0; border-color: var(--steer); }
#suggestions .chip .why { color: var(--dim); display: block; font-size: 11px; }
.keys { padding: 4px 14px; color: var(--dim); border-top: 1px solid var(--border); font-size: 12px; }
.keys b { color: var(--accent); font-weight: normal; }
.spin::after { content: " ⠋"; animation: spin 1s steps(4) infinite; }
@keyframes spin { 0% { content: " ⠋"; } 25% { content: " ⠙"; } 50% { content: " ⠸"; } 75% { content: " ⠴"; } }

#aiResult { font-size: 12px; }
#aiResult .score { font-size: 13px; }
#aiResult .score b { color: var(--accent); }
#aiResult ol { margin: 4px 0; padding-left: 22px; }
#aiResult li { margin-bottom: 3px; color: var(--dim); word-break: break-word; }
#aiResult li.ok::marker { color: var(--ok); } #aiResult li.bad::marker { color: var(--bad); }
#aiResult .tag { color: var(--dim); white-space: pre; }

#drawer, #browse { position: fixed; top: 0; right: 0; height: 100vh; width: min(440px, 100vw); background: var(--panel);
  border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgba(0,0,0,.35); transform: translateX(105%);
  transition: transform .2s ease; z-index: 20; display: flex; flex-direction: column; }
#drawer.open, #browse.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.drawer-body { overflow: auto; padding: 4px 14px 16px; }
.drawer-body p, .drawer-body li { margin: 8px 0; }
.drawer-body ol { padding-left: 18px; }
.drawer-body h3 { margin: 14px 0 6px; font-size: 12px; color: var(--dim); font-weight: normal; }
.fcard { display: block; width: 100%; text-align: left; margin: 6px 0; padding: 8px; border-color: var(--border); }
.fcard:hover { border-color: var(--steer); }
.fcard .t { color: var(--steer); }
.fcard .n { display: block; color: var(--dim); font-size: 12px; margin-top: 3px; }
.fcard .p { display: block; font-size: 12px; margin-top: 3px; }
.grid.space { grid-template-columns: minmax(340px, 1.35fr) minmax(460px, 2.4fr); }
@media (max-width: 1100px) { .grid.space { grid-template-columns: minmax(0, 1fr); } }
a { color: var(--accent); }
#aiKeyRow input[type=password] { flex: 1; min-width: 140px; }
#aiKeyRow #aiModel { width: 210px; }
#copyFallback { width: 100%; margin-top: 6px; font: inherit; font-size: 12px; background: var(--bg, #0d1117); color: inherit; border: 1px solid #444; }
.warn { color: var(--warn); }
#aiKeyRow #aiModelOther { width: 210px; }
button.accent.on { background: var(--accent); color: var(--bg); }
button.warn.on { background: var(--warn); color: var(--bg); }
.ai-run + .ai-run { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 6px; }
#community { margin: 6px 0; }
ol.community { margin: 2px 0 4px; padding-left: 22px; }
ol.community li { margin: 2px 0; }
.howscore { margin: 4px 0; font-size: 12px; } .howscore summary { cursor: pointer; }
.col-note { color: var(--warn); font-size: 11px; margin: 0 0 6px; }
.raw-prompt { color: var(--dim); }
#legend, #aiShareNote, #tempHint { font-size: 11px; }
#aiShareNote { flex-basis: 100%; }
#featureInfo .warn.ivmsg { display: block; }
.community .src { font-size: 11px; border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }
.fcard, .composer textarea, #input { max-width: 100%; }
.panel { min-width: 0; }
.topbar { position: relative; }
#tempHint { position: absolute; right: 14px; top: calc(100% + 2px); white-space: nowrap; font-size: 11px; line-height: 14px; pointer-events: none; }   /* sits in the gap under the bar: no reflow */
@media (max-width: 1100px) { #tempHint { position: static; flex-basis: 100%; white-space: normal; pointer-events: auto; } .tempgroup { flex-wrap: wrap; } }
#aiKey::placeholder { font-size: 10.5px; }   /* the HF token hint must fit the field */

#searchResults { margin: 4px 0 8px; max-height: 40vh; overflow-y: auto; }
#searchResults ol { margin: 4px 0; padding-left: 22px; }
#searchResults li { margin: 3px 0; }
#searchResults .hit, .linklike { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
#searchQ { flex: 1 1 200px; }
.msg-used { font-size: 11px; margin: -2px 0 6px; }

/* left column: the feature panel scrolls; the steer / ablate box below it stays in view */
.leftcol { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.leftcol > #featurePanel { flex: 1 1 auto; }
#ivPanel { flex: none; }
#ivPanel > .body { max-height: 38vh; gap: 6px; }
#ivPanel h3 { margin-top: 2px; }
@media (max-width: 1100px) { #ivPanel > .body { max-height: none; } }

/* feature panel: a fixed header (pickers, feature line, best explanation, auto-interp) over scrolling examples */
#featurePanel > .head { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 0 12px 8px; border-bottom: 1px solid var(--border); }
#featurePanel > .body { padding-top: 8px; }
#bestExpl { line-height: 1.45; }
#aiMore { white-space: nowrap; }
#bestExpl, #community, #searchResults { overflow-wrap: anywhere; }
.stats { text-decoration: underline dotted var(--dim); text-underline-offset: 3px; cursor: help; }
/* short desktop windows: the left column scrolls with the page, the compare panel stays in view */
@media (min-width: 1101px) and (max-height: 850px) {
  body { height: auto; min-height: 100vh; }
  .grid { flex: none; align-items: start; }
  .leftcol .panel > .body { overflow: visible; flex: none; }
  #ivPanel > .body { max-height: none; }
  #chatPanel { position: sticky; top: 8px; height: calc(100vh - 60px); }   /* leaves room for the footer at the bottom of the page */
}
#themeBtn { min-width: 34px; }
#browseBtn { font-weight: bold; }
#browseList { padding-left: 22px; }
#browseList li { margin: 6px 0; overflow-wrap: anywhere; }
#browseList .hit { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
.browse-controls { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.browse-controls input { flex: 1 1 160px; }

/* "explored features" shimmers (border and text) until the visitor first opens it; still for reduced-motion users */
#browseBtn.shimmer {
  --rainbow: linear-gradient(90deg, #ff7a7a, #ffb86b, #f2e36b, #6be3a3, #6bb8ff, #b48cff, #ff7a7a);
  border: 1px solid transparent;
  background: linear-gradient(var(--panel), var(--panel)) padding-box, var(--rainbow) border-box;
  background-size: 100% 100%, 300% 100%;
  animation: rainbow-border 6s linear infinite;
}
#browseBtn.shimmer span {
  background: var(--rainbow); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text;
  color: transparent; animation: rainbow-text 6s linear infinite;
}
@keyframes rainbow-border { from { background-position: 0 0, 0% 0; } to { background-position: 0 0, 300% 0; } }
@keyframes rainbow-text { from { background-position: 0% 0; } to { background-position: 300% 0; } }
@media (prefers-reduced-motion: reduce) { #browseBtn.shimmer, #browseBtn.shimmer span { animation: none; } }
#themeBtn { display: inline-flex; align-items: center; justify-content: center; padding: 4px 8px; }
/* light mode: a deeper rainbow so the shimmering text stays readable on white */
:root[data-theme="light"] #browseBtn.shimmer { --rainbow: linear-gradient(90deg, #d93636, #d9761a, #b39200, #1f9e5a, #1f6fd1, #7a45d1, #d93636); }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) #browseBtn.shimmer { --rainbow: linear-gradient(90deg, #d93636, #d9761a, #b39200, #1f9e5a, #1f6fd1, #7a45d1, #d93636); }
}

#shadeRow { margin: 2px 0 6px; font-size: 12px; }
#examples li .tk { color: var(--text); border-radius: 2px; }
#examples li span.tk:not([style]) { color: var(--dim); }
#examples li b.tk { outline: 1px solid rgba(245,197,66,.8); }

/* a newly added steer / ablation gets one sweep: an accent-blue band (solid leading edge, halftone-dot tail) accelerates
   left to right and hits the row's right edge, which flashes and nudges the row; then it looks like any other row.
   Timings match FRESH_MS in space.js (0.6 s). Still for reduced-motion users. */
#ivList li { width: fit-content; max-width: 100%; }
#ivList li.fresh { position: relative; overflow: hidden; isolation: isolate; border-radius: 3px;
  animation: iv-recoil .6s var(--age, 0ms) both; }
#ivList li.fresh::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 75%; z-index: -1; pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0 45%, color-mix(in srgb, var(--accent) 45%, transparent) 80%, color-mix(in srgb, var(--accent) 75%, transparent) 100%),
    radial-gradient(circle, color-mix(in srgb, var(--accent) 80%, transparent) 42%, transparent 48%) 0 0 / 4px 4px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 70%); mask-image: linear-gradient(90deg, transparent 0%, #000 70%);
  animation: iv-scan .6s var(--age, 0ms) both;
}
#ivList li.fresh::after {          /* the impact: a bright edge and a glow spreading back from the right side */
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 45%; z-index: -1; pointer-events: none;
  background: linear-gradient(to left, color-mix(in srgb, var(--accent) 55%, #fff) 0 3px, transparent 3px),
              radial-gradient(ellipse 100% 150% at 100% 50%, color-mix(in srgb, var(--accent) 85%, transparent), transparent 72%);
  box-shadow: inset -6px 0 10px -4px color-mix(in srgb, var(--accent) 70%, #fff);
  transform-origin: right center; opacity: 0;
  animation: iv-impact .6s var(--age, 0ms) both;
}
/* head reaches the right edge at 55% (ease-in: it speeds up into the hit), then the band fades */
@keyframes iv-scan {
  0% { transform: translateX(-100%); opacity: 1; animation-timing-function: cubic-bezier(.5, 0, .9, .6); }
  55% { transform: translateX(33.4%); opacity: 1; animation-timing-function: ease-out; }
  100% { transform: translateX(33.4%); opacity: 0; }
}
@keyframes iv-impact {
  0%, 54% { opacity: 0; transform: scaleX(.25); }
  58% { opacity: 1; transform: scaleX(.6); animation-timing-function: ease-out; }
  100% { opacity: 0; transform: scaleX(1); }
}
@keyframes iv-recoil {
  0%, 55% { transform: translateX(0); }
  63% { transform: translateX(2px); }
  75% { transform: translateX(-1px); }
  100% { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) { #ivList li.fresh { animation: none; } #ivList li.fresh::before, #ivList li.fresh::after { display: none; } }
