/* ==========================================================================
   App House — design system
   ---------------------------------------------------------------------------
   Editorial reference-journal direction: warm ink and paper rather than cool
   slate, a display serif for titles, a grotesque for everything numeric,
   hairline rules instead of heavy borders.

   Two themes. `prefers-color-scheme` sets the default; [data-theme] on <html>
   lets the in-app toggle win in both directions.
   ========================================================================== */

/* ------------------------------------------------------------- fonts ----- */
/* Self-hosted: the CSP allows font-src 'self' only, and webfonts from a CDN
   would be blocked. Both are OFL — see assets/fonts/LICENSE.txt. */

@font-face {
  font-family: 'Fraunces';
  src: url('/assets/fonts/fraunces-var-latin.woff2') format('woff2-variations');
  font-weight: 300 700;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('/assets/fonts/inter-var-latin.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
}

/* ------------------------------------------------------------ tokens ----- */

:root {
  /* Ink (dark) is the default theme. Warm-neutral, never blue-grey. */
  --page:        #14110f;
  --page-2:      #191614;
  --surface:     #1c1917;
  --surface-2:   #221f1c;
  --surface-3:   #2a2622;
  --rule:        rgba(250, 247, 242, 0.10);
  --rule-strong: rgba(250, 247, 242, 0.22);

  --text:   #faf7f2;
  --muted:  #a8a29e;
  --faint:  #7c746e;

  --accent:      #f0a927;   /* saffron */
  --accent-hot:  #ffbb43;
  --on-accent:   #1a1410;
  --accent-soft: rgba(240, 169, 39, 0.14);

  --second:      #d2673a;   /* terracotta */

  /* Status tokens are fixed and shared with the charts, never themed. */
  --good:     #0ca30c;
  --warning:  #fab219;
  --critical: #d03b3b;
  --good-soft:     rgba(12, 163, 12, 0.15);
  --warning-soft:  rgba(250, 178, 25, 0.15);
  --critical-soft: rgba(208, 59, 59, 0.15);

  --ring: rgba(240, 169, 39, 0.5);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 24px -8px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, 0.7);

  --r-xs: 4px;
  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;

  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Fluid type scale */
  --t-hero: clamp(2.5rem, 7vw, 4rem);
  --t-h1:   clamp(1.875rem, 4.6vw, 2.75rem);
  --t-h2:   clamp(1.25rem, 2.4vw, 1.5rem);
  --t-h3:   1.0625rem;
  --t-body: 0.9375rem;
  --t-sm:   0.8125rem;
  --t-xs:   0.6875rem;

  --gutter: max(1.125rem, env(safe-area-inset-left));
  --ease: cubic-bezier(0.32, 0.72, 0, 1);

  color-scheme: dark;
}

/* Paper (light). Declared under both scopes so the OS setting and the toggle
   each win where they should. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --page:        #f4f1ea;
    --page-2:      #efebe2;
    --surface:     #ffffff;
    --surface-2:   #fbf9f4;
    --surface-3:   #f3efe6;
    --rule:        rgba(28, 25, 23, 0.11);
    --rule-strong: rgba(28, 25, 23, 0.26);

    --text:   #1c1917;
    --muted:  #57534e;
    --faint:  #857d76;

    --accent:      #f0a927;
    --accent-hot:  #e09a12;
    --on-accent:   #1a1410;
    --accent-soft: rgba(240, 169, 39, 0.18);
    --second:      #b8501f;

    --good-soft:     rgba(12, 163, 12, 0.12);
    --warning-soft:  rgba(250, 178, 25, 0.2);
    --critical-soft: rgba(208, 59, 59, 0.1);

    --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.07);
    --shadow-md: 0 6px 20px -8px rgba(28, 25, 23, 0.16);
    --shadow-lg: 0 24px 56px -20px rgba(28, 25, 23, 0.22);

    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --page:        #f4f1ea;
  --page-2:      #efebe2;
  --surface:     #ffffff;
  --surface-2:   #fbf9f4;
  --surface-3:   #f3efe6;
  --rule:        rgba(28, 25, 23, 0.11);
  --rule-strong: rgba(28, 25, 23, 0.26);

  --text:   #1c1917;
  --muted:  #57534e;
  --faint:  #857d76;

  --accent:      #f0a927;
  --accent-hot:  #e09a12;
  --on-accent:   #1a1410;
  --accent-soft: rgba(240, 169, 39, 0.18);
  --second:      #b8501f;

  --good-soft:     rgba(12, 163, 12, 0.12);
  --warning-soft:  rgba(250, 178, 25, 0.2);
  --critical-soft: rgba(208, 59, 59, 0.1);

  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.07);
  --shadow-md: 0 6px 20px -8px rgba(28, 25, 23, 0.16);
  --shadow-lg: 0 24px 56px -20px rgba(28, 25, 23, 0.22);

  color-scheme: light;
}

/* ------------------------------------------------------------- reset ----- */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.6;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv05' 1, 'cv08' 1; /* friendlier l and tail-less t */
}

/* Author `display` declarations outrank the UA's [hidden] rule. */
[hidden] { display: none !important; }

img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--accent-soft); color: var(--text); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  left: 0.75rem;
  top: -4rem;
  z-index: 200;
  padding: 0.625rem 1rem;
  font-size: var(--t-sm);
  font-weight: 600;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--r-sm);
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 0.75rem; }

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

/* Paper grain. A fixed, non-interactive film that stops large flat areas from
   looking like plastic. Very low opacity — it should be felt, not seen. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) body::after { opacity: 0.05; }
}
:root[data-theme="light"] body::after { opacity: 0.05; }

/* -------------------------------------------------------- typography ----- */

.display {
  font-family: var(--font-display);
  font-weight: 550;
  letter-spacing: -0.02em;
  line-height: 1.08;
  font-variation-settings: 'opsz' 60;
}

h1.display { font-size: var(--t-h1); }
h2.display { font-size: var(--t-h2); font-variation-settings: 'opsz' 30; }

.hero-type {
  font-family: var(--font-display);
  font-size: var(--t-hero);
  font-weight: 550;
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-variation-settings: 'opsz' 144;
}

/* Small caps-ish section label. */
.eyebrow {
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

.lede { color: var(--muted); }

/* Every number in the UI lines up. */
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ layout ----- */

.shell {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6875rem var(--gutter);
  padding-top: max(0.6875rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--rule);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--page); }
}

.topbar__spacer { flex: 1 1 auto; }
.topbar__actions { display: flex; align-items: center; gap: 0.375rem; }

.main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding: 2rem var(--gutter) calc(4rem + env(safe-area-inset-bottom));
}
.main--wide { max-width: 84rem; }

.page-head { margin-bottom: 2.25rem; max-width: 44rem; }
.page-head .lede { margin-top: 0.5rem; font-size: 1rem; }

.section { margin-top: 2.5rem; }
.section__head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding-bottom: 0.625rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}
.section__head > :last-child:not(:first-child) { margin-left: auto; }

/* --------------------------------------------------------- brand mark --- */

.brand { display: inline-flex; align-items: center; gap: 0.5625rem; }

.brand__mark {
  width: 1.875rem;
  height: 1.875rem;
  flex: 0 0 auto;
  color: var(--accent);
}

.brand__name {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  font-variation-settings: 'opsz' 20;
}

.brand--lg .brand__mark { width: 2.75rem; height: 2.75rem; }
.brand--lg .brand__name { font-size: 1.5rem; }

/* ----------------------------------------------------------- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  min-height: 2.625rem;
  padding: 0.5625rem 1rem;
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease),
              color 0.16s var(--ease), transform 0.08s var(--ease), opacity 0.16s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hot); }

.btn--ghost { border-color: var(--rule-strong); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-3); border-color: var(--rule-strong); }

.btn--quiet { color: var(--muted); }
.btn--quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn--danger { background: var(--critical-soft); color: var(--critical); }
.btn--danger:hover:not(:disabled) { border-color: var(--critical); }

.btn--block { width: 100%; }
.btn--lg { min-height: 3rem; font-size: var(--t-body); padding: 0.75rem 1.25rem; }
.btn--sm { min-height: 2.125rem; padding: 0.3125rem 0.625rem; font-size: var(--t-xs); }

.btn__icon { width: 1.0625rem; height: 1.0625rem; flex: 0 0 auto; }

.btn__spinner {
  width: 0.875rem;
  height: 0.875rem;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn:not([data-loading="true"]) .btn__spinner { display: none; }
.btn[data-loading="true"] .btn__icon { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 1.125rem; height: 1.125rem; }
.icon-btn--sm { width: 1.875rem; height: 1.875rem; }
.icon-btn--sm svg { width: 0.9375rem; height: 0.9375rem; }

/* ------------------------------------------------------------- forms ---- */

.field { margin-bottom: 1.125rem; }

.field > label,
.field__label {
  display: block;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.5rem;
}

.input {
  width: 100%;
  font-size: 1rem; /* >=16px keeps iOS Safari from zooming on focus */
  padding: 0.6875rem 0.8125rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease),
              background-color 0.16s var(--ease);
}
.input::placeholder { color: var(--faint); }
.input:hover { border-color: var(--rule-strong); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}
.input[aria-invalid="true"] { border-color: var(--critical); }

.input--compact {
  width: auto;
  min-width: 4rem;
  padding: 0.4375rem 0.5625rem;
  font-size: var(--t-body);
}
select.input { cursor: pointer; padding-right: 2rem; }

/* The reveal button anchors to this wrapper, not the field, so a hint below
   the input can't push it out of alignment. */
.control { position: relative; }
.control .input { padding-right: 4.25rem; }
.control .reveal {
  position: absolute;
  right: 0.3125rem;
  top: 50%;
  transform: translateY(-50%);
}

.reveal {
  padding: 0.375rem 0.5rem;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
  border-radius: var(--r-xs);
  transition: color 0.16s, background-color 0.16s;
}
.reveal:hover { color: var(--text); background: var(--surface-3); }

.field__hint {
  display: block;
  margin-top: 0.5rem;
  font-size: var(--t-sm);
  color: var(--faint);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.625rem;
  font-size: var(--t-sm);
  color: var(--muted);
  cursor: pointer;
}
.checkbox input {
  width: 1.0625rem;
  height: 1.0625rem;
  accent-color: var(--accent);
}

.search {
  position: relative;
  flex: 1 1 11rem;
  min-width: 0;
}
.search__icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.0625rem;
  height: 1.0625rem;
  color: var(--faint);
  pointer-events: none;
}
.search .input { padding-left: 2.4375rem; }

/* ------------------------------------------------------------ alerts ---- */

.alert {
  display: flex;
  gap: 0.5625rem;
  align-items: flex-start;
  padding: 0.6875rem 0.8125rem;
  margin-bottom: 1.125rem;
  font-size: var(--t-sm);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.alert svg { width: 1.0625rem; height: 1.0625rem; flex: 0 0 auto; margin-top: 0.0625rem; }
.alert--error   { background: var(--critical-soft); color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.alert--success { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }

/* -------------------------------------------------------- auth screens --- */

.auth {
  min-height: 100dvh;
  display: grid;
}

@media (min-width: 60rem) {
  .auth { grid-template-columns: 1.05fr 1fr; }
}

/* Editorial brand panel. Hidden on small screens, where a compact header
   carries the identity instead. */
.auth__aside {
  display: none;
  position: relative;
  overflow: hidden;
  padding: 3rem;
  background: var(--page-2);
  border-right: 1px solid var(--rule);
}
@media (min-width: 60rem) {
  .auth__aside { display: flex; flex-direction: column; justify-content: space-between; }
}

.auth__aside::before {
  content: '';
  position: absolute;
  width: 34rem;
  height: 34rem;
  right: -12rem;
  top: -10rem;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 68%);
  pointer-events: none;
}

.auth__quote {
  position: relative;
  max-width: 22rem;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 450;
  line-height: 1.28;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 48;
}
.auth__quote em { color: var(--accent); font-style: italic; }

.auth__meta { position: relative; font-size: var(--t-sm); color: var(--faint); }

.auth__panel {
  display: grid;
  place-items: center;
  padding: 2rem var(--gutter) calc(2rem + env(safe-area-inset-bottom));
}

.auth__form { width: 100%; max-width: 23rem; }
.auth__form > .brand { margin-bottom: 2rem; }
@media (min-width: 60rem) { .auth__form > .brand { display: none; } }

.auth__form h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 550;
  letter-spacing: -0.025em;
  line-height: 1.1;
  font-variation-settings: 'opsz' 40;
}
.auth__form > .lede { margin: 0.5rem 0 1.75rem; }

.auth__footer {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: var(--t-sm);
  color: var(--faint);
  text-align: center;
}
.auth__footer button { color: var(--accent); font-weight: 600; }
.auth__footer button:hover { text-decoration: underline; }

/* --------------------------------------------------- dashboard index ---- */

.greeting { margin-bottom: 0.375rem; }

.index { border-top: 1px solid var(--rule); }

.index__row {
  position: relative;
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 1.25rem 0.5rem 1.25rem 0.25rem;
  border-bottom: 1px solid var(--rule);
  transition: background-color 0.18s var(--ease), padding-left 0.18s var(--ease);
}

.index__row--live:hover {
  background: var(--surface-2);
  padding-left: 0.75rem;
}
.index__row--soon { opacity: 0.55; }

.index__num {
  font-size: var(--t-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
}
.index__row--live .index__num { color: var(--accent); }

.index__body { min-width: 0; }

.index__name {
  font-family: var(--font-display);
  font-size: clamp(1.125rem, 2.6vw, 1.5rem);
  font-weight: 550;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variation-settings: 'opsz' 32;
}

.index__tagline {
  margin-top: 0.1875rem;
  font-size: var(--t-sm);
  color: var(--muted);
}

.index__end { display: flex; align-items: center; gap: 0.75rem; }

.index__arrow {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--faint);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}
.index__row--live:hover .index__arrow { opacity: 1; transform: translateX(0); }

/* --------------------------------------------------------------- tags --- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  padding: 0.1875rem 0.5rem;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--faint);
  white-space: nowrap;
}
.tag--live { background: var(--accent-soft); color: var(--accent); }
:root[data-theme="light"] .tag--live { color: #8a5f06; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .tag--live { color: #8a5f06; }
}

.tag--dry { background: var(--warning-soft); color: var(--warning); }
:root[data-theme="light"] .tag--dry { color: #7d5504; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .tag--dry { color: #7d5504; }
}

/* ------------------------------------------------------------- cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1.375rem;
}
@media (min-width: 40rem) { .card { padding: 1.625rem; } }

.card + .card { margin-top: 1rem; }

.card__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.125rem;
}
.card__head > :last-child:not(:first-child) { margin-left: auto; }
.card__head h2 { font-size: var(--t-h3); font-family: var(--font-ui); font-weight: 650; letter-spacing: -0.01em; }

.card__title-display {
  font-family: var(--font-display);
  font-size: var(--t-h2);
  font-weight: 550;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 30;
}

.card > .lede { font-size: var(--t-sm); margin-bottom: 1.25rem; }

.empty {
  padding: 1.75rem 1rem;
  text-align: center;
  font-size: var(--t-sm);
  color: var(--faint);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--r-md);
}

.count { font-size: var(--t-sm); color: var(--faint); white-space: nowrap; }

/* ============================================== Protein Dictionary ==== */

/* ------------------------------------------- visualisation tokens ------
   Categorical slots in fixed order from the validated palette; the dark
   column is the same six hues re-stepped for the dark surface. Re-validated
   against THIS theme's chart surfaces (#1c1917 ink / #ffffff paper) — all
   checks pass in both. Light mode reports three slots under 3:1, which
   obliges visible labels: the legend and the table view are that relief. */
:root {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --viz-other: #8a817a;
  --meter-fill: #3987e5;
  --meter-track: #104281;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
    --viz-other: #857d76;
    --meter-fill: #2a78d6;
    --meter-track: #cde2fb;
  }
}
:root[data-theme="light"] {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --viz-other: #857d76;
  --meter-fill: #2a78d6;
  --meter-track: #cde2fb;
}

/* ------------------------------------------------------ two-pane tool --- */

.tool {
  display: grid;
  gap: 1rem;
  /* minmax(0, 1fr), not the implicit `auto`: the category chip row is a nowrap
     flex container, so its min-content is the sum of every chip (~1200px). An
     auto track would honour that and push the whole page into horizontal
     scroll. This lets the track shrink and the chip row scroll instead. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'plate' 'build' 'browse';
}

.tool > * { min-width: 0; }

/* Wide: the plate becomes a sticky rail so the totals stay in view while you
   browse the index. Source order keeps plate-first for small screens. */
@media (min-width: 64rem) {
  .tool {
    grid-template-columns: minmax(0, 1fr) 23rem;
    grid-template-areas:
      'build plate'
      'browse plate';
    align-items: start;
    gap: 1.25rem;
  }
}

.tool__plate { grid-area: plate; }
.tool__build { grid-area: build; }
.tool__browse { grid-area: browse; }

@media (min-width: 64rem) {
  .tool__plate {
    position: sticky;
    top: 4.25rem;
    max-height: calc(100dvh - 5.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* --------------------------------------------------------- the plate --- */

.plate__target {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.125rem;
}

.plate__target-field { flex: 0 0 auto; }
.plate__target-input { display: flex; align-items: baseline; gap: 0.375rem; }
.plate__target-input .input { width: 5.25rem; }

/* Hero figure: the one number this view leads with. Sans, per the data-viz
   rule that a display face on a hero number reads as decoration — and Inter's
   tabular figures line up as the plate changes. */
.plate__hero {
  display: flex;
  align-items: baseline;
  gap: 0.4375rem;
  margin-bottom: 0.25rem;
}

.plate__hero-value {
  font-size: clamp(2.25rem, 6vw, 3rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.035em;
}
.plate__hero-unit { font-size: 1.125rem; font-weight: 600; color: var(--muted); }
.plate__hero-of { font-size: var(--t-sm); color: var(--faint); margin-left: auto; }

.unit { font-size: var(--t-sm); color: var(--faint); }

/* ------------------------------------------------------------- meter --- */

.meter { margin: 0.875rem 0 1.125rem; }

.meter__track {
  display: flex;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--meter-track);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  background: var(--meter-fill);
  border-radius: 999px;
  transition: width 0.25s var(--ease);
}
.meter__over {
  height: 100%;
  background: repeating-linear-gradient(
    135deg,
    var(--warning) 0 4px,
    color-mix(in srgb, var(--warning) 50%, transparent) 4px 8px
  );
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .meter__over { background: var(--warning); }
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5625rem;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  white-space: nowrap;
}
.status svg { width: 0.875rem; height: 0.875rem; }
.status--neutral { background: var(--surface-3); color: var(--muted); }
.status--good    { background: var(--good-soft); color: var(--good); }
.status--warning { background: var(--warning-soft); color: var(--warning); }
:root[data-theme="light"] .status--warning { color: #7d5504; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .status--warning { color: #7d5504; }
}

/* -------------------------------------------------------- stat strip --- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.25rem, 1fr));
  gap: 1px;
  margin: 1.125rem 0;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
}

.stat { padding: 0.625rem 0.75rem; background: var(--surface); }

.stat__label {
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--faint);
}
.stat__value {
  margin-top: 0.125rem;
  font-size: 0.9375rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
  /* Tiles are narrow in the plate rail; a wrapped value reads as two figures. */
  white-space: nowrap;
}

/* ------------------------------------------------------------- chart --- */

.chart { position: relative; margin-top: 0.5rem; }
.chart__plot { width: 100% ; }
.chart__plot svg { display: block; overflow: visible; }

.chart__tooltip {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  transform: translateX(-50%);
  z-index: 20;
  padding: 0.375rem 0.5625rem;
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-xs);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.4375rem;
  margin-top: 0.875rem;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--t-sm);
  min-width: 0;
}
.legend__swatch {
  width: 0.5rem;
  height: 0.5rem;
  flex: 0 0 auto;
  border-radius: 2px;
}
/* Identity comes from the swatch; text stays in ink tokens. */
.legend__label {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend__value {
  margin-left: auto;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* -------------------------------------------------------- table view --- */

.details { margin-top: 1rem; border-top: 1px solid var(--rule); }
.details > summary {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.6875rem 0;
  font-size: var(--t-sm);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.details > summary::-webkit-details-marker { display: none; }
.details > summary:hover { color: var(--text); }
.details > summary svg { width: 0.875rem; height: 0.875rem; transition: transform 0.18s var(--ease); }
.details[open] > summary svg { transform: rotate(90deg); }

.table-scroll { overflow-x: auto; padding-bottom: 0.5rem; }

.data-table {
  width: 100%;
  min-width: 26rem;
  border-collapse: collapse;
  font-size: var(--t-sm);
}
.data-table th, .data-table td {
  padding: 0.4375rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
.data-table th {
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}
.data-table td.num, .data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.data-table tfoot td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--rule-strong); }

/* -------------------------------------------------------- plate rows --- */

.plate-list { display: flex; flex-direction: column; margin-top: 1rem; }

.plate-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem 0.625rem;
  padding: 0.6875rem 0;
  border-top: 1px solid var(--rule);
}

.plate-row__swatch {
  width: 0.1875rem;
  height: 1.75rem;
  border-radius: 999px;
}

.plate-row__label { min-width: 0; }
.plate-row__name {
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.plate-row__sub {
  font-size: var(--t-xs);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.plate-row__controls { display: flex; align-items: center; gap: 0.375rem; }
.plate-row__grams { display: flex; align-items: baseline; gap: 0.25rem; }
.plate-row__grams .input { width: 4.25rem; text-align: right; }
.plate-row__unit { font-size: var(--t-xs); color: var(--faint); }

/* A dry/cooked switch sits under the row on narrow rails so nothing squeezes. */
.plate-row__basis { grid-column: 2 / -1; }

.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-3);
  border-radius: var(--r-sm);
}
.segmented__btn {
  padding: 0.1875rem 0.5rem;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--faint);
  border-radius: var(--r-xs);
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease);
}
.segmented__btn svg { width: 1rem; height: 1rem; }
.segmented__btn:hover { color: var(--text); }
.segmented__btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------- ingredients --- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chips {
  display: flex;
  min-width: 0;
  gap: 0.375rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin-bottom: 1rem;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

/* Fades the right edge so a cut-off chip reads as "scroll me", not "broken". */
@supports (mask-image: linear-gradient(black, black)) {
  .chips {
    mask-image: linear-gradient(to right, black calc(100% - 2rem), transparent);
  }
}

.chip {
  padding: 0.3125rem 0.6875rem;
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 999px;
  white-space: nowrap;
  transition: all 0.16s var(--ease);
}
.chip:hover { border-color: var(--rule-strong); color: var(--text); }
.chip.is-active {
  background: var(--text);
  border-color: var(--text);
  color: var(--page);
}

.food-list { border-top: 1px solid var(--rule); }

.food {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.375rem 0.875rem;
  padding: 0.875rem 0.25rem;
  border-bottom: 1px solid var(--rule);
  transition: background-color 0.16s var(--ease);
}
.food:hover { background: var(--surface-2); }

.food__main { min-width: 0; grid-column: 1; }

.food__title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3125rem 0.5rem;
}
.food__name {
  font-size: var(--t-body);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.food__urdu {
  font-size: var(--t-sm);
  color: var(--muted);
}

.food__meta {
  margin-top: 0.1875rem;
  font-size: var(--t-xs);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.food__cooked {
  margin-top: 0.25rem;
  font-size: var(--t-xs);
  color: var(--muted);
}
.food__cooked strong { color: var(--text); font-weight: 600; }

.food__source {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: var(--t-xs);
  color: var(--faint);
  opacity: 0.75;
  word-break: break-word;
}
.food__source:hover { color: var(--accent); opacity: 1; }

/* Protein is the reason this page exists — give it the most weight. */
.food__protein {
  grid-column: 2;
  text-align: right;
  white-space: nowrap;
}
.food__protein-value {
  display: block;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.food__protein-unit {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.food__add { grid-column: 3; }

/* -------------------------------------------------------- source note --- */

.source-note {
  max-width: 46rem;
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: var(--t-xs);
  line-height: 1.7;
  color: var(--faint);
}

/* -------------------------------------------------------- status page --- */

.status-page { text-align: center; max-width: 26rem; }
.status-page .code {
  font-family: var(--font-display);
  font-size: clamp(4rem, 16vw, 6rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--accent);
  font-variation-settings: 'opsz' 144;
}
.status-page h1 {
  margin: 0.75rem 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 550;
  font-variation-settings: 'opsz' 32;
}
.status-page p { color: var(--muted); margin-bottom: 1.75rem; }
.status-page code {
  font-size: 0.8125em;
  padding: 0.125rem 0.3125rem;
  background: var(--surface-3);
  border-radius: var(--r-xs);
}


/* ------------------------------------------------------------ art ------ */

.food__art {
  width: 2.375rem;
  height: 2.375rem;
  flex: 0 0 auto;
  grid-column: 1;
}
.food__art svg { width: 100%; height: 100%; }

/* The list row gains an art column. */
.food {
  grid-template-columns: 2.375rem minmax(0, 1fr) auto auto;
}
.food__main { grid-column: 2; }
.food__protein { grid-column: 3; }
.food__add { grid-column: 4; }

@media (max-width: 34rem) {
  .food {
    grid-template-columns: 2.375rem minmax(0, 1fr) auto;
    grid-template-areas:
      'art main protein'
      'art add  add';
  }
  .food__art { grid-area: art; }
  .food__main { grid-area: main; }
  .food__protein { grid-area: protein; }
  .food__add { grid-area: add; justify-self: start; padding-top: 0.25rem; }
}

/* ---------------------------------------------------------- card grid --- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: 0.875rem;
}

.food-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  transition: border-color 0.16s var(--ease), transform 0.16s var(--ease),
              box-shadow 0.16s var(--ease);
}
.food-card:hover {
  border-color: var(--rule-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* The square. A photo covers it; an illustration sits centred on a tint. */
.food-card__media {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  border-bottom: 1px solid var(--rule);
  overflow: hidden;
}

.food-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.food-card__media svg {
  width: 76%;
  height: 76%;
}

/* A soft vignette gives the flat illustration tile some depth, and sits
   harmlessly under a photo since the photo covers the whole square. */
.food-card__media::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 38%,
              color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
  pointer-events: none;
}
.food-card__media:has(img)::before { display: none; }

/* Protein sits on the image corner so the number survives any photo. */
.food-card__badge {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.1875rem;
  padding: 0.25rem 0.4375rem;
  border-radius: var(--r-xs);
  background: color-mix(in srgb, var(--page) 78%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--rule);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .food-card__badge { background: var(--page); }
}

.food-card__protein {
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}
.food-card__unit {
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.food-card__dry {
  position: absolute;
  right: 0.5rem;
  top: 0.5rem;
}

.food-card__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.625rem 0.6875rem 0.75rem;
}

.food-card .food__title { gap: 0.25rem 0.375rem; }
.food-card .food__name { font-size: 0.875rem; line-height: 1.3; }
.food-card .food__urdu { font-size: 0.75rem; }
.food-card .food__meta { margin-top: 0; font-size: 0.625rem; line-height: 1.45; }

.food-card__foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}
.food-card__foot .btn { flex: 1 1 auto; }
.food-card__foot .food__source { margin-top: 0; }

@media (max-width: 26rem) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.625rem; }
  /* At ~180px wide the meta line and the provenance link are noise, and the
     link wraps beside the Add button. Both stay available in list view. */
  .food-card .food__meta,
  .food-card .food__cooked,
  .food-card .food__source { display: none; }
  .food-card__foot .btn { flex: 1 1 100%; }
}

/* Photo credit line under the grid — CC BY / BY-SA require attribution. */
.credits {
  margin-top: 1rem;
  font-size: var(--t-xs);
  line-height: 1.6;
  color: var(--faint);
}
.credits a { color: var(--muted); text-decoration: underline; }
