/* ============================================================================
   Canonical design-system tokens (shared across all Chroma sites, light + dark).
   Pasted verbatim from playground/_shared/THEME_CONTRACT.md §2. Dark is default;
   :root[data-theme="light"] overrides. Every app-specific alias below re-points
   to these --c-* tokens so the whole app is theme-aware at once.
   ============================================================================ */
:root{
  color-scheme: dark;
  /* Surfaces */
  --c-bg:#0A0B0D; --c-surface-1:#101216; --c-surface-2:#16181D; --c-surface-3:#1D2026; --c-inset:#07080A;
  --c-line:rgba(255,255,255,0.08); --c-line-strong:rgba(255,255,255,0.15);
  /* Text */
  --c-text:#F3F5F8; --c-text-2:#A9B1BD; --c-text-3:#7F8999;
  /* Brand accent (gold) */
  --c-accent:#E8A860; --c-accent-fill:#E8A860; --c-accent-2:#F3BE7C; --c-accent-soft:rgba(232,168,96,0.12); --c-on-accent:#1A130A;
  /* Data-encoding palette (charts, tiers) — consistent meaning everywhere */
  --c-gold:#E8A860;   /* positive / gold-tier / supported / OUR MODEL */
  --c-teal:#5CC7BE;   /* secondary series */
  --c-steel:#7FA0B7;  /* neutral / diagnostic */
  --c-coral:#E06B6B;  /* negative / rejected / refuse / fail */
  --c-mint:#86D6A8;   /* alt positive / pass */
  --c-amber:#E0B14E;  /* warn */
  --c-shadow:rgba(0,0,0,0.55); --c-backdrop:rgba(5,6,8,0.72);
  /* Type */
  --c-sans:"Inter",system-ui,-apple-system,"Segoe UI",sans-serif;
  --c-mono:"JetBrains Mono",ui-monospace,"SF Mono",Menlo,monospace;
}
:root[data-theme="light"]{
  color-scheme: light;
  --c-bg:#F3EFE7; --c-surface-1:#FBFAF5; --c-surface-2:#FFFFFF; --c-surface-3:#EFEBE1; --c-inset:#ECE7DB;
  --c-line:rgba(23,27,27,0.12); --c-line-strong:rgba(23,27,27,0.24);
  --c-text:#171B1B; --c-text-2:#4A524F; --c-text-3:#6E7572;
  --c-accent:#9A6512; --c-accent-fill:#C98A2E; --c-accent-2:#B4791F; --c-accent-soft:rgba(154,101,18,0.12); --c-on-accent:#1A130A;
  --c-gold:#9A6512; --c-teal:#2E8F86; --c-steel:#4E7288; --c-coral:#C0504A; --c-mint:#357D59; --c-amber:#B9832A;
  --c-shadow:rgba(32,36,32,0.16); --c-backdrop:rgba(40,40,35,0.35);
}

:root {
  /* App aliases — VALUES re-pointed to canonical --c-* per THEME_CONTRACT §3a.
     Names are unchanged so all component CSS below stays untouched. */
  --bg-0: var(--c-bg);
  --bg-1: var(--c-surface-1);
  --surface: var(--c-surface-2);
  --surface-2: var(--c-surface-3);
  --surface-3: color-mix(in srgb, var(--c-surface-3) 80%, var(--c-text) 7%);
  --surface-inset: var(--c-inset);

  --border: var(--c-line-strong);
  --border-strong: var(--c-line-strong);
  --border-subtle: var(--c-line);
  --transparent: transparent;

  --text-primary: var(--c-text);
  --text-secondary: var(--c-text-2);
  --text-tertiary: var(--c-text-3);
  --text-disabled: color-mix(in srgb, var(--c-text-3) 52%, var(--c-bg));

  --accent: var(--c-accent);
  --accent-hover: var(--c-accent-2);
  --accent-press: var(--c-accent);
  --accent-contrast: var(--c-on-accent);
  --accent-wash: var(--c-accent-soft);
  --accent-glow: color-mix(in srgb, var(--c-accent) 30%, transparent);

  --teal: var(--c-teal);
  --teal-wash: color-mix(in srgb, var(--c-teal) 14%, transparent);
  --success: var(--c-mint);
  --success-wash: color-mix(in srgb, var(--c-mint) 14%, transparent);
  --warn: var(--c-amber);
  --warn-wash: color-mix(in srgb, var(--c-amber) 14%, transparent);
  --error: var(--c-coral);
  --error-wash: color-mix(in srgb, var(--c-coral) 14%, transparent);
  --backdrop: var(--c-backdrop);
  --image-well: var(--c-inset);
  --shadow-color: var(--c-shadow);

  --panel-bg: var(--bg-1);
  --card-bg: var(--surface);
  --input-bg: var(--surface-2);

  --font-sans: var(--c-sans);
  --font-mono: var(--c-mono);
  --fs-display: 2.25rem;
  --fs-h1: 1.5rem;
  --fs-h2: 1.125rem;
  --fs-body: 0.9375rem;
  --fs-label: 0.8125rem;
  --fs-small: 0.75rem;
  --fs-mono: 0.8125rem;
  --fs-icon: 1.25rem;
  --fs-icon-lg: 1.75rem;
  --fs-spinner: 1rem;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --lh-tight: 1.1;
  --lh-heading: 1.25;
  --lh-body: 1.6;
  --lh-label: 1.4;
  --ls-display: -0.02em;
  --ls-heading: -0.01em;
  --ls-label: 0.01em;
  --ls-eyebrow: 0.09em;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --page-pad: clamp(16px, 4vw, 48px);
  --panel-pad: var(--space-6);
  --stack: var(--space-4);
  --term-label-min: 8rem;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 999px;
  --border-w: 1px;
  --border-w-strong: 2px;

  --shadow-sm: 0 1px 2px var(--c-shadow);
  --shadow-md: 0 4px 16px var(--c-shadow);
  --shadow-lg: 0 16px 48px var(--c-shadow);
  --shadow-pop: 0 12px 32px var(--c-shadow);
  --ring: 0 0 0 2px var(--bg-0), 0 0 0 4px var(--accent-glow);

  --dur-fast: 120ms;
  --dur-med: 180ms;
  --dur-slow: 260ms;
  --dur-shimmer: 1.4s;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --content-max: 1120px;
  --header-h: 64px;
  --control-h: 44px;
  --touch-min: 44px;
  --upload-min: 220px;
  --textarea-min: 132px;
  --textarea-max: 288px;
  --thumb-size: 72px;
  --hero-max-h: 620px;
  --popover-max: 320px;
  --drawer-w: 460px;
  --drawer-max: 92vw;
  --toast-max: 360px;
  --icon-size: 20px;
  --icon-size-lg: 28px;
  --handle-size: 34px;
  --handle-dot: 4px;
  --scrollbar-size: 8px;
  --blur: 10px;
  --rise: 6px;
  --hover-lift: -2px;
  --z-header: 20;
  --z-popover: 40;
  --z-drawer: 50;
  --z-toast: 60;
}

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

html {
  min-width: 0;
  scroll-behavior: smooth;
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% -12%, var(--accent-wash), var(--transparent) 29%),
    radial-gradient(circle at 88% 18%, var(--teal-wash), var(--transparent) 22%),
    var(--bg-0);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button,
textarea,
input,
a,
[tabindex] {
  -webkit-tap-highlight-color: var(--transparent);
}

button {
  color: inherit;
}

button:not(:disabled),
label[for],
input[type="range"] {
  cursor: pointer;
}

img,
svg {
  display: block;
}

img {
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: var(--text-primary);
  font-size: var(--fs-h1);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-heading);
  line-height: var(--lh-heading);
}

h2,
h3 {
  color: var(--text-primary);
  font-size: var(--fs-h2);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-heading);
  line-height: var(--lh-heading);
}

:focus-visible {
  border-color: var(--accent) !important;
  box-shadow: var(--ring);
  outline: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: var(--border-w) !important;
  height: var(--border-w) !important;
  padding: 0 !important;
  margin: calc(var(--border-w) * -1) !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.icon--large {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
}

.eyebrow {
  color: var(--text-tertiary);
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-eyebrow);
  line-height: var(--lh-label);
  text-transform: uppercase;
}

.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  border-bottom: var(--border-w) solid var(--border);
  background: color-mix(in srgb, var(--bg-0) 84%, var(--transparent));
  backdrop-filter: blur(var(--blur));
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, var(--content-max));
  height: 100%;
  margin: 0 auto;
  padding-inline: var(--page-pad);
}

.brand,
.header__actions {
  display: flex;
  align-items: center;
}

.brand {
  min-height: var(--touch-min);
  gap: var(--space-3);
  border-radius: var(--r-sm);
}

.brand__mark {
  width: var(--space-5);
  height: var(--space-5);
  color: var(--accent);
}

.brand__name {
  color: var(--text-primary);
  font-size: var(--fs-h2);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-heading);
}

.brand__tagline {
  display: flex;
  gap: var(--space-3);
  color: var(--text-tertiary);
  font-size: var(--fs-label);
  letter-spacing: var(--ls-label);
}

.header__actions {
  gap: var(--space-2);
}

.mode-badge,
.status-badge,
.quality-badge,
.glossary-badge {
  display: inline-flex;
  align-items: center;
  min-height: var(--space-6);
  padding-inline: var(--space-3);
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: var(--lh-label);
}

.mode-badge {
  border-color: var(--teal);
  background: var(--teal-wash);
  color: var(--teal);
}

.page {
  width: min(100%, var(--content-max));
  margin: 0 auto;
  padding: var(--space-7) var(--page-pad) var(--space-6);
}

.panel {
  min-width: 0;
  padding: var(--panel-pad);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-lg);
  background: var(--panel-bg);
  box-shadow: var(--shadow-sm);
}

.panel + .panel {
  margin-top: var(--space-5);
}

.section-heading,
.result-heading,
.idle__header,
.hero-toolbar,
.reference-heading,
.feedback__header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
}

.section-heading > div,
.result-heading > div,
.idle__header > div,
.reference-heading > div,
.feedback__header > div {
  display: grid;
  gap: var(--space-2);
}

.section-heading__note,
.idle__header > p,
.reference-heading > p {
  max-width: 46ch;
  color: var(--text-tertiary);
  font-size: var(--fs-label);
  line-height: var(--lh-label);
  text-align: right;
}

.input-grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: var(--space-5);
  margin-top: var(--space-6);
}

.upload-wrap {
  position: relative;
  min-width: 0;
}

.upload {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--upload-min);
  padding: var(--space-5);
  overflow: hidden;
  border: var(--border-w-strong) dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
  transition:
    border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.upload:hover,
.upload:focus-visible,
.upload.is-dragover {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.upload.is-dragover {
  border-style: solid;
  transform: scale(1.005);
}

.upload__empty {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: var(--space-2);
  text-align: center;
}

.upload__icon {
  display: grid;
  width: var(--space-8);
  height: var(--space-8);
  margin-bottom: var(--space-2);
  place-items: center;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-tertiary);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.upload:hover .upload__icon,
.upload:focus-visible .upload__icon,
.upload.is-dragover .upload__icon {
  border-color: var(--accent);
  color: var(--accent);
}

.upload__title {
  color: var(--text-primary);
  font-weight: var(--fw-medium);
}

.upload__action {
  color: var(--text-secondary);
  font-size: var(--fs-label);
}

.upload__hint,
.upload__meta,
.upload__replace,
.input-error {
  font-size: var(--fs-small);
  line-height: var(--lh-label);
}

.upload__hint,
.upload__meta {
  color: var(--text-tertiary);
}

.upload__hint {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
}

.upload__filled {
  display: grid;
  align-items: center;
  width: 100%;
  grid-template-columns: var(--thumb-size) minmax(0, 1fr);
  gap: var(--space-4);
}

.upload__thumb {
  width: var(--thumb-size);
  height: var(--thumb-size);
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--image-well);
  object-fit: cover;
}

.upload__details {
  display: grid;
  min-width: 0;
  gap: var(--space-1);
}

.upload__filename {
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  line-height: var(--lh-label);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload__replace {
  margin-top: var(--space-2);
  color: var(--accent);
}

.upload__clear {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
}

.upload__sample {
  margin-top: var(--space-2);
}

.input-error {
  margin-top: var(--space-2);
  color: var(--error);
}

.prompt-block {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.prompt-block__label-row,
.prompt-block__action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.prompt-block__label-row label {
  color: var(--text-secondary);
  font-size: var(--fs-label);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label);
}

.prompt-block__count {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
}

#prompt-text {
  width: 100%;
  min-height: var(--textarea-min);
  max-height: var(--textarea-max);
  margin-top: var(--space-2);
  padding: var(--space-4);
  resize: none;
  overflow-y: auto;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-md);
  outline: none;
  background: var(--input-bg);
  color: var(--text-primary);
  line-height: var(--lh-body);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

#prompt-text::placeholder,
.search-field input::placeholder {
  color: var(--text-tertiary);
}

.prompt-block__help {
  max-width: 62ch;
  margin-top: var(--space-2);
  color: var(--text-tertiary);
  font-size: var(--fs-small);
  line-height: var(--lh-label);
}

.prompt-block__action {
  justify-content: flex-end;
  margin-top: auto;
  padding-top: var(--space-4);
}

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-h);
  border: var(--border-w) solid var(--transparent);
  border-radius: var(--r-md);
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-label);
  transition:
    color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.btn {
  gap: var(--space-2);
  padding-inline: var(--space-4);
}

.btn--primary {
  min-width: calc(var(--space-8) * 2.5);
  /* Use the canonical FILL token (identical to --c-accent in dark; a lighter gold
     in light) so the dark on-accent label keeps >=4.5:1 contrast in both modes. */
  background: var(--c-accent-fill);
  color: var(--accent-contrast);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 0 var(--space-1) var(--accent-glow);
}

.btn--primary:active:not(:disabled) {
  background: var(--accent-press);
  transform: translateY(var(--border-w));
}

.btn--secondary,
.btn--ghost {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
}

.btn--ghost {
  border-color: var(--transparent);
  background: var(--transparent);
  color: var(--text-secondary);
}

.btn--secondary:hover:not(:disabled),
.btn--ghost:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn:disabled {
  background: var(--surface-2);
  color: var(--text-disabled);
  cursor: not-allowed;
}

.icon-btn {
  width: var(--control-h);
  min-width: var(--control-h);
  padding: 0;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-secondary);
}

.spinner {
  width: var(--fs-spinner);
  height: var(--fs-spinner);
  border: var(--border-w-strong) solid var(--accent-contrast);
  border-right-color: var(--transparent);
  border-radius: var(--r-full);
  animation: spin var(--dur-slow) linear infinite;
}

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

.results {
  min-height: calc(var(--upload-min) + var(--space-8));
}

.state {
  min-width: 0;
  animation: state-in var(--dur-slow) var(--ease-out) both;
}

@keyframes state-in {
  from { opacity: 0; transform: translateY(var(--rise)); }
  to { opacity: 1; transform: translateY(0); }
}

.idle__hero {
  position: relative;
  display: grid;
  min-height: var(--upload-min);
  margin-top: var(--space-6);
  overflow: hidden;
  place-items: center;
  border: var(--border-w) dashed var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
}

.idle__grid,
.skeleton-grid,
.reference-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.idle__grid span {
  aspect-ratio: 4 / 3;
  border: var(--border-w) dashed var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}

.skeleton {
  overflow: hidden;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer var(--dur-shimmer) linear infinite;
}

.skeleton--hero {
  aspect-ratio: 16 / 9;
  margin-top: var(--space-5);
  border-radius: var(--r-lg);
}

.skeleton--card {
  aspect-ratio: 4 / 3;
}

.skeleton--line {
  width: 58%;
  height: var(--space-3);
  margin-top: var(--space-5);
}

.skeleton--line-short {
  width: 34%;
  margin-top: var(--space-2);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.result-heading {
  align-items: center;
}

.result-heading__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.status-badge {
  border-color: var(--success);
  background: var(--success-wash);
  color: var(--success);
}

.hero {
  margin-top: var(--space-5);
}

.hero-toolbar {
  align-items: center;
  margin-bottom: var(--space-3);
}

.hero-toolbar__label {
  display: grid;
  gap: var(--space-1);
}

.hero-toolbar__label span:first-child {
  color: var(--text-primary);
  font-weight: var(--fw-medium);
}

.hero-toolbar__label span:last-child,
.download__filename {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: var(--lh-label);
}

.download-wrap {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: var(--space-1);
}

.compare {
  --split: 50%;
  position: relative;
  width: 100%;
  max-height: min(70vh, var(--hero-max-h));
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--image-well);
  box-shadow: var(--shadow-md);
  isolation: isolate;
}

.compare__image,
.compare__before-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.compare__image {
  object-fit: contain;
}

.compare__before-layer {
  z-index: 1;
  clip-path: inset(0 calc(100% - var(--split)) 0 0);
}

.compare__range {
  position: absolute;
  z-index: 4;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
}

.compare__range:focus-visible {
  border: 0 !important;
  box-shadow: none;
}

.compare__divider {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  left: var(--split);
  width: var(--border-w-strong);
  background: var(--accent);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  transform: translateX(-50%);
}

.compare__handle {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: var(--handle-size);
  height: var(--handle-size);
  place-items: center;
  border: var(--border-w-strong) solid var(--accent);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -50%);
  transition: box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.compare__handle::before,
.compare__handle::after {
  width: var(--handle-dot);
  height: var(--handle-dot);
  border: solid var(--text-secondary);
  border-width: 0 0 var(--border-w) var(--border-w);
  content: "";
}

.compare__handle::before {
  transform: rotate(45deg);
}

.compare__handle::after {
  transform: rotate(225deg);
}

.compare__range:focus-visible + .compare__divider .compare__handle {
  box-shadow: var(--ring), var(--shadow-md);
}

.compare__label {
  position: absolute;
  z-index: 2;
  top: var(--space-3);
  padding: var(--space-1) var(--space-2);
  border: var(--border-w) solid var(--border-subtle);
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface) 82%, var(--transparent));
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: var(--lh-label);
  backdrop-filter: blur(var(--blur));
}

.compare__label--before { left: var(--space-3); }
.compare__label--after { right: var(--space-3); }

.spec {
  margin-top: var(--space-3);
  border-top: var(--border-w) solid var(--border);
}

.spec summary,
.error-detail summary {
  width: fit-content;
  padding-block: var(--space-3);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: var(--fs-small);
}

.spec summary:hover,
.error-detail summary:hover {
  color: var(--text-secondary);
}

.spec code,
.error-detail code {
  display: block;
  padding: var(--space-3);
  overflow-wrap: anywhere;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: var(--lh-body);
}

.reference-section {
  margin-top: var(--space-7);
}

.reference-heading {
  align-items: end;
}

.ref-card {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-lg);
  background: var(--card-bg);
  color: var(--text-secondary);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition:
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.ref-card:hover,
.ref-card:focus-visible {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(var(--hover-lift));
}

.ref-card__image-well {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--image-well);
}

.ref-card__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--dur-fast) var(--ease);
}

.ref-card__original {
  opacity: 0;
}

.ref-card:hover .ref-card__original,
.ref-card.is-before .ref-card__original {
  opacity: 1;
}

.ref-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--control-h);
  padding-inline: var(--space-3);
  border-top: var(--border-w) solid var(--border);
}

.ref-card__name {
  color: var(--text-secondary);
  font-size: var(--fs-label);
  font-weight: var(--fw-medium);
}

.ref-card__mode {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
}

.ref-card:hover .ref-card__mode,
.ref-card.is-before .ref-card__mode {
  color: var(--accent);
}

/* Gallery of saved grades -------------------------------------------------- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.gallery-empty {
  grid-column: 1 / -1;
  padding: var(--space-6);
  color: var(--text-tertiary);
  text-align: center;
}

.gallery-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-lg);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  transition:
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.gallery-card:hover,
.gallery-card:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(var(--hover-lift));
}

.gallery-card__well {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 0;
  background: var(--image-well);
  cursor: pointer;
}

.gallery-card__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--dur-fast) var(--ease);
}

.gallery-card__original {
  opacity: 0;
}

.gallery-card__well:hover .gallery-card__original,
.gallery-card.is-before .gallery-card__original {
  opacity: 1;
}

.gallery-card__mode {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  padding: 2px var(--space-2);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--bg-0) 66%, var(--transparent));
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
}

.gallery-card__badge {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  padding: 2px var(--space-2);
  border: var(--border-w) solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--accent-wash);
  color: var(--accent);
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
}

.gallery-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: var(--border-w) solid var(--border);
}

.gallery-card__prompt {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--fs-label);
  line-height: var(--lh-label);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.gallery-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
}

.gallery-card__actions .btn {
  flex: 1 1 auto;
}

.feedback {
  margin-top: var(--space-7);
  padding: var(--space-5);
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.feedback__header {
  align-items: start;
}

.feedback__assessment {
  max-width: 62ch;
  color: var(--text-secondary);
}

.feedback__hint {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: var(--space-2);
  color: var(--text-tertiary);
  font-size: var(--fs-small);
}

.feedback__groups {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.term-group {
  display: grid;
  grid-template-columns: minmax(var(--term-label-min), 0.24fr) minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: var(--border-w) solid var(--border);
}

.term-group__title {
  padding-top: var(--space-2);
  color: var(--text-tertiary);
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label);
  line-height: var(--lh-label);
  text-transform: uppercase;
}

.term-group--magnitude .term-group__title { color: var(--teal); }
.term-group--direction .term-group__title { color: var(--accent); }

.term-group__chips,
.scope-card__terms {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--space-7);
  gap: var(--space-2);
  padding-inline: var(--space-3);
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  line-height: var(--lh-label);
  transition:
    color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.chip--magnitude { border-color: color-mix(in srgb, var(--teal) 50%, var(--border)); }
.chip--direction { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }

.chip--magnitude:hover,
.chip--magnitude:focus-visible {
  border-color: var(--teal);
  background: var(--teal-wash);
}

.chip--direction:hover,
.chip--direction:focus-visible {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.chip--style:hover,
.chip--style:focus-visible {
  border-color: var(--text-tertiary);
  background: var(--surface-3);
}

.chip.is-copied {
  border-color: var(--success);
  background: var(--success-wash);
  color: var(--success);
}

.chip--prominent {
  min-height: var(--control-h);
  padding-inline: var(--space-4);
}

.popover {
  position: fixed;
  z-index: var(--z-popover);
  width: min(var(--popover-max), calc(100vw - (var(--space-4) * 2)));
  padding: var(--space-4);
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  animation: tooltip-in var(--dur-fast) var(--ease-out) both;
  pointer-events: none;
}

@keyframes tooltip-in {
  from { opacity: 0; transform: translateY(var(--space-1)); }
  to { opacity: 1; transform: translateY(0); }
}

.popover__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: var(--border-w) solid var(--border);
}

.popover__term {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  font-weight: var(--fw-medium);
}

.popover__category {
  color: var(--text-tertiary);
  font-size: var(--fs-small);
  letter-spacing: var(--ls-eyebrow);
  text-align: right;
  text-transform: uppercase;
}

.popover__definition {
  margin-top: var(--space-3);
  color: var(--text-secondary);
  font-size: var(--fs-label);
  line-height: var(--lh-body);
}

.popover__axis,
.popover__example {
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: var(--lh-body);
}

.popover__axis { color: var(--text-tertiary); }
.popover__example { color: var(--accent); }

.route-card,
.error-card {
  position: relative;
  min-height: var(--upload-min);
  padding: var(--space-6);
  overflow: hidden;
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.route-card::before,
.error-card::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--space-1);
  background: var(--accent);
  content: "";
}

.route-card--clarify {
  background: linear-gradient(145deg, var(--accent-wash), var(--surface) 42%);
}

.route-card--refuse {
  background: linear-gradient(145deg, var(--warn-wash), var(--surface) 42%);
}

.route-card--refuse::before { background: var(--warn); }
.error-card::before { background: var(--error); }

.route-card__icon,
.error-card__icon {
  display: grid;
  width: var(--space-8);
  height: var(--space-8);
  place-items: center;
  border: var(--border-w) solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--accent-wash);
  color: var(--accent);
}

.route-card--refuse .route-card__icon {
  background: var(--warn-wash);
  color: var(--warn);
}

.error-card__icon {
  background: var(--error-wash);
  color: var(--error);
}

.route-card h2,
.error-card h2 {
  margin-top: var(--space-5);
  font-size: var(--fs-h1);
}

.route-card__message,
.error-card__message {
  max-width: 62ch;
  margin-top: var(--space-3);
  color: var(--text-secondary);
}

.route-card__coach {
  margin-top: var(--space-6);
  color: var(--text-tertiary);
  font-size: var(--fs-label);
}

.route-card .feedback__groups,
.scope-card__terms {
  margin-top: var(--space-3);
}

.route-card__hint {
  margin-top: var(--space-5);
  color: var(--accent);
  font-size: var(--fs-small);
}

.error-card {
  background: linear-gradient(145deg, var(--error-wash), var(--surface) 42%);
}

.error-detail {
  max-width: 62ch;
  margin-top: var(--space-3);
}

.error-card .btn {
  margin-top: var(--space-5);
}

.drawer-shell {
  position: fixed;
  z-index: var(--z-drawer);
  inset: 0;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: var(--backdrop);
  cursor: default;
  animation: fade-in var(--dur-med) var(--ease) both;
}

.drawer {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  width: min(var(--drawer-w), var(--drawer-max));
  height: 100%;
  padding: var(--space-6);
  overflow-y: auto;
  flex-direction: column;
  border-left: var(--border-w) solid var(--border-strong);
  background: var(--bg-1);
  box-shadow: var(--shadow-lg);
  animation: drawer-in var(--dur-slow) var(--ease-out) both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes drawer-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.drawer__header > div {
  display: grid;
  gap: var(--space-2);
}

.drawer__intro {
  max-width: 58ch;
  margin-top: var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--fs-label);
}

.search-field {
  display: flex;
  align-items: center;
  min-height: var(--control-h);
  gap: var(--space-2);
  margin-top: var(--space-5);
  padding-inline: var(--space-3);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-md);
  background: var(--input-bg);
  color: var(--text-tertiary);
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: var(--transparent);
  color: var(--text-primary);
  font-size: var(--fs-label);
}

.search-field input:focus-visible {
  border: 0 !important;
  box-shadow: none;
}

.drawer__count {
  margin-top: var(--space-3);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
}

.glossary {
  display: grid;
  gap: var(--space-6);
  margin-top: var(--space-5);
  padding-bottom: var(--space-8);
}

.glossary__group {
  display: grid;
  gap: var(--space-2);
}

.glossary__group-title {
  position: sticky;
  top: calc(var(--space-6) * -1);
  z-index: 1;
  padding-block: var(--space-2);
  border-bottom: var(--border-w) solid var(--border);
  background: var(--bg-1);
  color: var(--text-tertiary);
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
}

.glossary-row {
  padding: var(--space-4);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}

.glossary-row__top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-3);
}

.glossary-row__term {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  font-weight: var(--fw-medium);
}

.glossary-badge {
  min-height: var(--space-5);
  padding-inline: var(--space-2);
}

.glossary-badge--grounded {
  border-color: color-mix(in srgb, var(--success) 50%, var(--border));
  color: var(--success);
}

.glossary-row__definition {
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--fs-label);
  line-height: var(--lh-body);
}

.glossary-row__axis,
.glossary-row__example {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: var(--lh-body);
}

.glossary-row__axis { color: var(--text-tertiary); }
.glossary-row__example { color: var(--accent); }

.glossary-empty {
  padding: var(--space-6);
  border: var(--border-w) dashed var(--border);
  border-radius: var(--r-md);
  color: var(--text-tertiary);
  text-align: center;
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  right: var(--space-5);
  bottom: var(--space-5);
  max-width: min(var(--toast-max), calc(100vw - (var(--space-5) * 2)));
  padding: var(--space-3) var(--space-4);
  border: var(--border-w) solid var(--success);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--fs-label);
  box-shadow: var(--shadow-pop);
  animation: state-in var(--dur-med) var(--ease-out) both;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-top: var(--space-6);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
}

.noscript {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  left: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-4);
  border: var(--border-w) solid var(--error);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-primary);
  text-align: center;
}

.input-panel.is-loading {
  opacity: 0.78;
  pointer-events: none;
}

body.is-drawer-open {
  overflow: hidden;
}

::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}

::-webkit-scrollbar-track {
  background: var(--bg-1);
}

::-webkit-scrollbar-thumb {
  border-radius: var(--r-full);
  background: var(--border-strong);
}

@media (max-width: 1023px) {
  .reference-grid,
  .skeleton-grid,
  .idle__grid,
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 859px) {
  :root {
    --panel-pad: var(--space-5);
  }

  .input-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .prompt-block__action {
    margin-top: var(--space-4);
  }
}

@media (max-width: 639px) {
  :root {
    --panel-pad: var(--space-4);
  }

  .brand__tagline,
  .section-heading__note,
  .idle__header > p,
  .reference-heading > p,
  .feedback__hint {
    display: none;
  }

  .page {
    padding-top: var(--space-5);
  }

  .panel {
    border-radius: var(--r-md);
  }

  .section-heading,
  .result-heading,
  .idle__header,
  .hero-toolbar,
  .reference-heading,
  .feedback__header {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-toolbar {
    align-items: stretch;
  }

  .download-wrap,
  .download-wrap .btn {
    align-items: center;
    width: 100%;
  }

  .compare {
    aspect-ratio: 4 / 3;
  }

  .reference-grid,
  .skeleton-grid,
  .idle__grid,
  .gallery-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .reference-section,
  .feedback {
    margin-top: var(--space-6);
  }

  .term-group {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }

  .term-group__title {
    padding-top: 0;
  }

  .route-card,
  .error-card {
    padding: var(--space-5);
  }

  .drawer {
    width: 100%;
    max-width: 100%;
    padding: var(--space-5);
  }

  .toast {
    right: var(--space-3);
    bottom: var(--space-3);
    left: var(--space-3);
    max-width: none;
  }

  .btn,
  .icon-btn,
  .chip,
  .search-field {
    min-height: var(--touch-min);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .skeleton {
    background: var(--surface-2);
  }

  .ref-card:hover,
  .ref-card:focus-visible,
  .gallery-card:hover,
  .gallery-card:focus-within,
  .upload.is-dragover {
    transform: none;
  }
}

/* ============================================================================
   Shared cross-site nav links + theme toggle (THEME_CONTRACT §4). Integrated
   into the app's existing .header__actions rather than a foreign .xnav, so the
   tool keeps its own header UX while sharing the same links, toggle, and tokens
   as the other Chroma sites. All values are canonical --c-* tokens.
   ============================================================================ */
.xnav-links { display: flex; align-items: center; gap: 30px; }
.xnav-links a { font: 500 13.5px/1 var(--c-sans); color: var(--c-text-2); text-decoration: none; transition: color .18s; }
.xnav-links a:hover { color: var(--c-text); }
.xnav-links a[aria-current="page"] { color: var(--c-accent); }

.xtheme {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--c-line-strong);
  background: var(--c-surface-2);
  color: var(--c-text-2);
  cursor: pointer;
  transition: color .18s, border-color .18s;
}
.xtheme:hover { color: var(--c-accent); border-color: var(--c-accent); }
.xtheme-sun { display: none; }
:root[data-theme="light"] .xtheme-moon { display: none; }
:root[data-theme="light"] .xtheme-sun { display: block; }

/* Footer cross-links (keeps the app's mono fact row, adds token-based links). */
.footer__facts,
.footer__links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-4);
}
.footer__links {
  font-family: var(--font-sans);
}
.footer__links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
.footer__links a:hover {
  color: var(--accent);
}

/* App-specific light-mode refinement: deepen the pressed accent (THEME_CONTRACT
   §3a "--accent-press [light: deepen]") using tokens only. */
:root[data-theme="light"] {
  --accent-press: color-mix(in srgb, var(--c-accent) 84%, var(--c-on-accent));
}

@media (max-width: 720px) {
  .xnav-links { gap: 18px; }
  .xnav-links a { font-size: 12.5px; }
  .header .xnav-links a[href="/dataset.html"],
  .header .xnav-links a[href="/eval.html"],
  .header .xnav-links a[href="https://github.com/ericrcwu001/SLM"] { display: none; }
}

@media (max-width: 639px) {
  .footer {
    justify-content: center;
  }
}
