:root {
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, .09);
  --danger: #d03b3b;
  --danger-wash: rgba(208, 59, 59, .07);
  --img-bg: #ffffff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05);
  --shadow-lg: 0 8px 28px rgba(11, 11, 11, .12);
  --font-display: 'IBM Plex Sans', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --line-strong: #383835;
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, .16);
  --danger: #e66767;
  --danger-wash: rgba(230, 103, 103, .10);
  --img-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

/* ---- Sidebar ---------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1.35rem 1.1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.brand-block {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--accent-wash);
}
.brand-mark i { border-radius: 2px; background: var(--accent); opacity: .35; }
.brand-mark i:nth-child(1),
.brand-mark i:nth-child(4) { opacity: 1; }
.brand-text { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.brand-title {
  font-family: var(--font-display);
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.15;
}
.brand-stage {
  font-family: var(--font-mono);
  font-size: .64rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.side-group-title {
  display: block;
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .55rem;
}

/* Result-set tabs (vertical list) */
.tab-bar { display: flex; flex-direction: column; gap: 2px; }
.tab-bar button {
  font-family: inherit;
  font-size: .84rem;
  font-weight: 500;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem .65rem;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background-color .12s, color .12s;
}
.tab-bar button:hover { background: var(--surface-2); color: var(--ink); }
.tab-bar button.active {
  background: var(--accent-wash);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
.tab-bar button .tab-count {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tab-bar button.active .tab-count { color: var(--accent-ink); }

/* Sidebar selector groups */
.side-group { display: flex; flex-direction: column; }
.side-group label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .6rem;
}
.side-group select,
.rev-select,
.gif-slot select {
  font-family: inherit;
  font-size: .84rem;
  font-weight: 500;
  width: 100%;
  padding: .42rem 1.9rem .42rem .65rem;
  color: var(--ink);
  background-color: var(--surface);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.side-group select:hover,
.rev-select:hover,
.gif-slot select:hover { border-color: var(--accent); }
.side-group select:focus,
.rev-select:focus,
.gif-slot select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

/* Section nav */
.section-nav { display: flex; flex-direction: column; gap: 2px; }
.section-nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .65rem;
  font-size: .84rem;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background-color .12s, color .12s;
}
.section-nav a:hover { background: var(--surface-2); color: var(--ink); }
.section-nav a.active {
  background: var(--accent-wash);
  color: var(--accent-ink);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-idx {
  font-family: var(--font-mono);
  font-size: .66rem;
  color: var(--muted);
  width: 1em;
  flex: 0 0 auto;
}
.section-nav a.active .nav-idx { color: var(--accent-ink); }

/* Sidebar footer */
.side-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.theme-toggle {
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .65rem;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: background-color .15s, color .15s, border-color .15s;
  align-self: flex-start;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--ink); }
.theme-icon { line-height: 1; }
:root[data-theme="dark"] .theme-icon-light { display: none; }
:root:not([data-theme="dark"]) .theme-icon-dark { display: none; }
.side-stats {
  font-family: var(--font-mono);
  font-size: .68rem;
  line-height: 1.6;
  color: var(--muted);
  overflow-wrap: anywhere;
}
kbd {
  font-family: var(--font-mono);
  font-size: .64rem;
  font-weight: 500;
  padding: .08rem .32rem;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-2);
}
.kbd-hints {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .75rem;
  font-size: .68rem;
  color: var(--muted);
}

/* ---- Main ------------------------------------------------------------- */
main {
  padding: 1.5rem 2rem 4rem;
  max-width: 1280px;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  transition: opacity .2s ease, transform .2s ease;
}
main.tab-switching { opacity: 0; transform: translateY(5px); pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  main { transition: none; }
  main.tab-switching { opacity: 1; transform: none; }
}

.context-bar { display: flex; align-items: center; }
.status {
  font-family: var(--font-mono);
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  padding: .38rem .8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.status:empty { display: none; }

/* ---- Panels ------------------------------------------------------------ */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.6rem 1.6rem;
  box-shadow: var(--shadow);
  scroll-margin-top: 1rem;
}
.panel h2 {
  margin: 0 0 1.1rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -.01em;
  display: flex;
  align-items: baseline;
  gap: .65rem;
  padding-bottom: .8rem;
  border-bottom: 1px solid var(--line);
}
.sec-idx {
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: .04em;
}
.h2-sub { font-family: var(--font-body); font-weight: 400; color: var(--muted); font-size: .8rem; }
.panel h3 {
  margin: .85rem 0 .5rem;
  font-size: .68rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
}
.sub { margin-top: 1rem; }
.hint { font-size: .82rem; color: var(--muted); margin: 0 0 .7rem; }

/* Revision selector (model tabs) */
.rev-select-wrap { margin: 0 0 .75rem; }
.rev-select-label {
  font-size: .68rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.rev-select { width: auto; }

/* Aggregate row */
.agg-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.agg-row img {
  max-width: 100%;
  max-height: 320px;
  width: auto;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--img-bg);
  display: block;
}

/* Layer tabs (segmented control) */
.layer-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-bottom: .85rem;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  width: fit-content;
  max-width: 100%;
}
.layer-tabs button {
  font-family: var(--font-mono);
  font-size: .74rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  padding: .28rem .6rem;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  border-radius: 4px;
  transition: background-color .12s, color .12s;
}
.layer-tabs button:hover { background: var(--surface); color: var(--ink); }
.layer-tabs button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* Detail viewer */
.detail {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 240px;
}
.detail img {
  max-width: 100%;
  max-height: 440px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  background: var(--img-bg);
  box-shadow: var(--shadow);
}
#saturation-content img {
  max-width: 100%;
  max-height: 400px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--img-bg);
}
#gif-agg img {
  max-width: 100%;
  max-height: 360px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}
main img { cursor: zoom-in; }

/* Horizontal scroll strip */
.hscroll {
  display: flex;
  gap: .65rem;
  overflow-x: auto;
  padding: .75rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.hscroll::-webkit-scrollbar { height: 8px; }
.hscroll::-webkit-scrollbar-track { background: transparent; }
.hscroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
.hscroll figure {
  flex: 0 0 auto;
  margin: 0;
  text-align: center;
  scroll-snap-align: start;
}
.hscroll img {
  height: 220px;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: block;
  background: var(--img-bg);
}
.hscroll figcaption {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--muted);
  margin-top: .35rem;
  font-variant-numeric: tabular-nums;
}

/* GIF compare */
.gif-compare {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .85rem;
}
.gif-controls {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  padding: .55rem .75rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: .25rem;
}
.gif-controls .step-btn {
  font-family: inherit;
  font-size: .88rem;
  font-weight: 500;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .12s, border-color .12s, color .12s;
}
.gif-controls .step-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.gif-controls .step-btn:disabled { opacity: .4; cursor: not-allowed; }
.gif-controls .play-btn { width: auto; padding: 0 .85rem; gap: .35rem; }
.gif-controls input[type=range] {
  flex: 1;
  min-width: 140px;
  accent-color: var(--accent);
}
.gif-controls .frame-count {
  font-family: var(--font-mono);
  font-size: .76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 70px;
  text-align: right;
}
.gif-controls .speed-sel {
  font-family: inherit;
  font-size: .76rem;
  padding: .25rem .4rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}
.gif-slot {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .75rem;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.gif-slot img,
.gif-slot canvas {
  width: 100%;
  max-width: 100%;
  max-height: 320px;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--img-bg);
  display: block;
}
.gif-slot .slot-status {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  min-height: 1em;
}

/* Details / summary */
details {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
details[open] { background: var(--surface); }
details summary {
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  color: var(--ink-2);
  padding: .65rem .85rem;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .45rem;
}
details summary:hover { color: var(--ink); }
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: '▸';
  font-size: .7rem;
  transition: transform .15s;
  color: var(--muted);
}
details[open] summary::before { transform: rotate(90deg); }
details > *:not(summary) { padding: 0 .85rem .85rem; }

/* Raw links */
#raw-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
#raw-links li { margin: 0; }
#raw-links a {
  display: inline-block;
  padding: .35rem .75rem;
  font-family: var(--font-mono);
  font-size: .76rem;
  color: var(--accent-ink);
  background: var(--accent-wash);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: border-color .12s;
}
#raw-links a:hover { border-color: var(--accent); }

/* Missing state */
.missing {
  color: var(--danger);
  font-size: .8rem;
  padding: .5rem .75rem;
  background: var(--danger-wash);
  border: 1px dashed var(--danger);
  border-radius: var(--radius-sm);
  display: inline-block;
}

/* ---- Lightbox ----------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(11, 11, 11, .8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox figure {
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
}
.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 7.5rem);
  border-radius: 6px;
  background: var(--img-bg);
  box-shadow: var(--shadow-lg);
}
.lightbox figcaption {
  font-family: var(--font-mono);
  font-size: .74rem;
  color: rgba(255, 255, 255, .8);
}

/* ---- Responsive ----------------------------------------------------------- */
@media (max-width: 1100px) {
  .gif-compare { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side-footer { margin-top: 0; }
  .agg-row { grid-template-columns: 1fr; }
  main { padding: 1.25rem 1rem 3rem; }
}
