/* Purley — design system
   Deep forest green, cream type, sage accent. Dark is the default theme; [data-theme="light"] swaps to cream.

   0.6 rules, so the UI stays consistent as it grows:
   - Spacing comes only from the --s-* scale (4 px base). Related things sit closer than unrelated ones.
   - Type comes only from the --t-* scale. Hierarchy is built with weight and colour before size.
   - Radius comes from --r-*; an element nested in another uses the next size down.
   - The accent colour marks the main action, links, focus and selected states. Everything else is neutral.
   - Motion uses the --dur-* / --ease-* tokens: things enter with ease-out and leave faster than they came. */

:root {
  --s-0: 2px;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-md: 1rem;
  --t-lg: 1.125rem;
  --t-xl: 1.5rem;
  --t-2xl: 2rem;
  --t-h1: clamp(2rem, 3.4vw, 2.5rem);
  --t-display: clamp(2.5rem, 5vw, 3.75rem);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 999px;
  --radius: var(--r-lg);

  --dur-fast: 120ms;
  --dur: 180ms;
  --dur-slow: 240ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  /* Bottom sheets travel the height of the screen, so they get a longer duration and a softer landing. */
  --dur-sheet: 320ms;
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);

  --font-serif: "Playfair Display", "Iowan Old Style", "Palatino Linotype", Georgia, "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif KR", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Hiragino Sans", "Noto Sans JP", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1a13;
  --bg-elev: #122017;
  --card: #15261c;
  --card-2: #1a2f22;
  --line: #233a2b;
  --line-strong: #31503f;
  --text: #e6e4d8;
  --text-strong: #f7f5ec;
  --muted: #9faea3;
  --accent: #8fc3a0;
  --accent-ink: #0e1a13;
  --accent-soft: rgba(143, 195, 160, 0.12);
  --btn: #7fb591;
  --btn-hover: #93c6a4;
  --none-bg: rgba(143, 195, 160, 0.16);
  --none-ink: #a9dbb8;
  --low-bg: rgba(214, 224, 140, 0.16);
  --low-ink: #dbe4a0;
  --moderate-bg: rgba(240, 196, 110, 0.18);
  --moderate-ink: #f0c46e;
  --high-bg: rgba(235, 120, 110, 0.2);
  --high-ink: #f3a097;
  --unknown-bg: rgba(255, 255, 255, 0.07);
  --unknown-ink: #b9c4bc;
  --shadow-sm: 0 1px 1px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.18), 0 6px 16px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.2), 0 16px 32px rgba(0, 0, 0, 0.26), 0 32px 64px rgba(0, 0, 0, 0.3);
  --backdrop: rgba(5, 12, 8, 0.6);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f1e8;
  --bg-elev: #ecebe0;
  --card: #fbfaf5;
  --card-2: #f1f0e6;
  --line: #e0dfd2;
  --line-strong: #c9cbbc;
  --text: #1c2b22;
  --text-strong: #0e1a13;
  --muted: #5a695f;
  --accent: #2f6d4c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47, 109, 76, 0.1);
  --btn: #2f6d4c;
  --btn-hover: #3a7f5a;
  --none-bg: #e2f0e6;
  --none-ink: #1f5a3a;
  --low-bg: #eef2d4;
  --low-ink: #5a6a14;
  --moderate-bg: #fbefd1;
  --moderate-ink: #8a5a0a;
  --high-bg: #fbe1dc;
  --high-ink: #a3302a;
  --unknown-bg: #e8e8df;
  --unknown-ink: #4b5a50;
  --shadow-sm: 0 1px 1px rgba(30, 40, 30, 0.04), 0 1px 3px rgba(30, 40, 30, 0.06);
  --shadow-md: 0 1px 2px rgba(30, 40, 30, 0.05), 0 6px 16px rgba(30, 40, 30, 0.07);
  --shadow-lg: 0 2px 6px rgba(30, 40, 30, 0.06), 0 16px 32px rgba(30, 40, 30, 0.1), 0 32px 64px rgba(30, 40, 30, 0.12);
  --backdrop: rgba(14, 26, 19, 0.35);
}

* { box-sizing: border-box; }
/* Installed / in-app use: no rubber-band pull-to-refresh over the scanner, no grey tap flashes. */
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; overscroll-behavior-y: none; }
a, button, .btn, .toggle, .ing-card { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: var(--t-md);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-underline-offset: 0.15em; }
h1, h2, h3 { font-family: var(--font-serif); font-weight: 500; line-height: 1.15; margin: 0 0 var(--s-3); color: var(--text-strong); letter-spacing: -0.01em; }
h1 { font-size: var(--t-h1); letter-spacing: -0.015em; }
h2 { font-size: var(--t-xl); }
h3 { font-size: var(--t-lg); }
p { margin: 0 0 var(--s-3); }
small, .muted { color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--card-2); padding: 0 var(--s-1); border-radius: var(--r-sm); }
/* Emphasis in headings stays in the text colour: the accent is reserved for actions. */
em.accent, .accent-italic { font-style: italic; color: inherit; }
.eyebrow { display: inline-block; font-size: var(--t-xs); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.serif { font-family: var(--font-serif); }
[hidden] { display: none !important; }
/* Korean wraps between words, not inside them; a name too long for its box still breaks. */
:lang(ko) { word-break: keep-all; overflow-wrap: break-word; }
.hero-facts span[lang] { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------------------------------------------------------- header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
/* Safe-area insets keep the bar clear of notches / status bars when the page runs edge-to-edge (standalone PWA, app WebView). */
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: calc(var(--s-3) + env(safe-area-inset-top, 0px)) calc(var(--s-5) + env(safe-area-inset-right, 0px)) var(--s-3) calc(var(--s-5) + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  gap: var(--s-5);
}
.brand { display: flex; align-items: center; gap: var(--s-2); text-decoration: none; color: var(--text-strong); }
.brand .mark { width: 32px; height: 32px; flex: none; color: var(--accent); }
.brand .word { font-family: var(--font-serif); font-weight: 700; font-size: var(--t-xl); letter-spacing: -0.02em; line-height: 1; }
.nav { display: flex; gap: var(--s-1); }
.nav a { text-decoration: none; color: var(--muted); padding: var(--s-2) var(--s-3); border-radius: var(--r-md); font-size: var(--t-sm); font-weight: 500; line-height: 1.2; white-space: nowrap; transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
.nav a:hover { color: var(--text-strong); background: var(--card-2); }
.nav a.active { color: var(--text-strong); font-weight: 600; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }
.lang-pick { display: inline-flex; align-items: center; gap: var(--s-1); border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: var(--s-1) var(--s-2) var(--s-1) var(--s-3); background: var(--card); color: var(--text); }
.lang-pick svg { width: 18px; height: 18px; color: var(--muted); }
.lang-pick select { border: 0; background: transparent; color: var(--text); font: inherit; font-size: var(--t-sm); padding: var(--s-1) 0; width: auto; }
.lang-pick select:focus { outline: none; }
.icon-btn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: var(--r-md); background: transparent; color: var(--muted); cursor: pointer; transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
.icon-btn:hover { background: var(--card-2); color: var(--text-strong); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: none; }
/* The header's scan button repeats the main action of the home and scan pages, so it only shows elsewhere. */
body[data-page="index"] .topbar-tools .cta,
body[data-page="scan"] .topbar-tools .cta { display: none; }
@media (max-width: 1180px) {
  .topbar-tools .cta .lbl { display: none; }
  .topbar-tools .cta { padding: 0 var(--s-3); }
}
@media (max-width: 1024px) {
  .lang-pick { display: none; }
}
@media (max-width: 900px) {
  .nav { display: none; }
  .topbar.open .nav,
  .topbar.closing .nav {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    flex-direction: column;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--line);
    padding: var(--s-2) var(--s-4) var(--s-4);
    gap: var(--s-1);
    box-shadow: var(--shadow-md);
    transform-origin: top right;
  }
  /* The menu grows out of the menu button (top right) and leaves faster than it arrives. */
  .topbar.open .nav { animation: menu-in var(--dur) var(--ease-out); }
  .topbar.closing .nav { animation: menu-out var(--dur-fast) var(--ease-in) forwards; }
  .topbar.open .nav a, .topbar.closing .nav a { padding: var(--s-3); font-size: var(--t-md); }
  .menu-btn { display: inline-flex; }
  .topbar-tools .cta { display: none; }
  .lang-pick { display: none; }
  .topbar.open .lang-pick { display: inline-flex; position: absolute; right: var(--s-4); top: calc(100% + var(--s-2)); z-index: 2; animation: menu-in var(--dur) var(--ease-out); }
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px) scale(0.98); } }
@keyframes menu-out { to { opacity: 0; transform: translateY(-4px) scale(0.99); } }

/* ---------------------------------------------------------------- layout */
main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--s-5) calc(var(--s-5) + env(safe-area-inset-right, 0px)) calc(var(--s-5) + env(safe-area-inset-bottom, 0px)) calc(var(--s-5) + env(safe-area-inset-left, 0px));
}
main.narrow { max-width: 880px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin-bottom: var(--s-4);
  box-shadow: var(--shadow-sm);
}
.card.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.page-head { padding: var(--s-6) 0 var(--s-5); }
.page-head h1 { margin-bottom: var(--s-2); }
.page-head p { color: var(--muted); max-width: 60ch; margin: 0; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--text-strong);
  font: inherit;
  font-weight: 600;
  font-size: var(--t-sm);
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--card-2); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--btn); color: var(--accent-ink); border-color: var(--btn); }
.btn.primary:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
/* Secondary action that should not compete with the primary one. */
.btn.quiet { background: transparent; border-color: transparent; color: var(--text); padding-left: var(--s-3); padding-right: var(--s-3); }
.btn.quiet:hover { background: var(--card-2); color: var(--text-strong); }
.btn.small { padding: var(--s-1) var(--s-3); min-height: 32px; font-weight: 500; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn input[type="file"] { display: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin: var(--s-3) 0; }
.actions .btn { flex: 1 1 170px; }

/* ---------------------------------------------------------------- forms */
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s-3); margin: var(--s-3) 0; }
label.field { display: flex; flex-direction: column; gap: var(--s-1); font-size: var(--t-xs); color: var(--muted); font-weight: 500; letter-spacing: 0.02em; }
select, input[type="text"], input[type="search"], input[type="email"], input[type="password"], textarea {
  font: inherit;
  font-size: var(--t-md);
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: var(--s-3);
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease-out);
}
textarea { min-height: 160px; resize: vertical; font-size: var(--t-sm); line-height: 1.5; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------------- home: hero */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-7); align-items: center; padding: var(--s-7) 0 var(--s-6); }
.hero h1 { font-size: var(--t-display); font-weight: 500; line-height: 1.05; margin: 0 0 var(--s-4); letter-spacing: -0.025em; }
.hero h1 em { font-style: italic; }
.hero .lede { font-size: var(--t-lg); color: var(--muted); max-width: 44ch; margin: 0 0 var(--s-5); }
.hero .actions { margin: 0 0 var(--s-5); }
.hero .actions .btn { flex: 0 0 auto; }
.hero-facts { font-size: var(--t-sm); color: var(--muted); margin: 0; font-variant-numeric: tabular-nums; }
.hero-facts strong { color: var(--text-strong); font-weight: 600; }
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: var(--s-6); padding: var(--s-5) 0; }
}

/* A real result from a real label, in place of a decorative illustration. */
.example { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-xl); padding: var(--s-5); box-shadow: var(--shadow-md); margin: 0; }
.example-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); flex-wrap: wrap; }
.example-kicker { font-size: var(--t-xs); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.example-meta { font-size: var(--t-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.example-title { font-family: var(--font-serif); font-size: var(--t-xl); color: var(--text-strong); margin: var(--s-1) 0 var(--s-4); line-height: 1.2; }
.example-verdicts { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); margin: 0 0 var(--s-4); }
.example-verdicts > div { background: var(--card-2); border-radius: var(--r-md); padding: var(--s-3); display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-2); }
.example-verdicts .lbl { font-size: var(--t-xs); color: var(--muted); font-weight: 500; }
.example-list { list-style: none; margin: 0; padding: 0; }
.example-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; padding: var(--s-2) 0; border-top: 1px solid var(--line); font-size: var(--t-sm); }
.example-list .src { color: var(--text-strong); font-weight: 500; overflow-wrap: anywhere; }
.example-list .dst { color: var(--muted); overflow-wrap: anywhere; }
.example-foot { font-size: var(--t-xs); color: var(--muted); margin: var(--s-3) 0 0; }
@media (max-width: 420px) {
  .example-verdicts { grid-template-columns: 1fr; }
  .example-verdicts > div { flex-direction: row; justify-content: space-between; align-items: center; }
  .example-list li { grid-template-columns: minmax(0, 1fr) auto; }
  .example-list .dst { grid-column: 1; grid-row: 2; }
  .example-list .chip { grid-column: 2; grid-row: 1 / span 2; }
}

/* ---------------------------------------------------------------- home: sections */
.section { padding: var(--s-6) 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-5); }
.section-head h2 { margin: 0; }
.section-head p { color: var(--muted); margin: 0; max-width: 56ch; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-4); }
.feature { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); }
.feature .num { font-size: var(--t-xs); font-weight: 600; letter-spacing: 0.12em; color: var(--muted); margin-bottom: var(--s-3); font-variant-numeric: tabular-nums; }
.feature h3 { margin-bottom: var(--s-2); }
.feature p { color: var(--muted); font-size: var(--t-sm); margin: 0; }
.quick { display: grid; grid-template-columns: 1.2fr 1fr; gap: var(--s-5); align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); }
.quick h2 { margin-bottom: var(--s-2); }
.quick p { margin: 0; }
.quick textarea { min-height: 120px; }
@media (max-width: 800px) { .quick { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- scanner */
.preview { margin-top: var(--s-4); }
.preview canvas { width: 100%; height: auto; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: #000; display: block; }
.crop-stage canvas { border-radius: 0; border: 0; }
.preview-tools { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3); align-items: center; }
.crop-stage { position: relative; line-height: 0; overflow: hidden; border-radius: var(--r-md); }
.crop-layer { position: absolute; inset: 0; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.crop-box { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.5); cursor: move; box-sizing: border-box; }
.crop-box .h { position: absolute; width: 32px; height: 32px; margin: -16px; }
.crop-box .h::after { content: ""; position: absolute; inset: 9px; background: var(--accent); border: 2px solid var(--bg); border-radius: var(--r-sm); }
.crop-box .h[data-handle="nw"] { top: 0; left: 0; cursor: nwse-resize; }
.crop-box .h[data-handle="n"] { top: 0; left: 50%; cursor: ns-resize; }
.crop-box .h[data-handle="ne"] { top: 0; left: 100%; cursor: nesw-resize; }
.crop-box .h[data-handle="e"] { top: 50%; left: 100%; cursor: ew-resize; }
.crop-box .h[data-handle="se"] { top: 100%; left: 100%; cursor: nwse-resize; }
.crop-box .h[data-handle="s"] { top: 100%; left: 50%; cursor: ns-resize; }
.crop-box .h[data-handle="sw"] { top: 100%; left: 0; cursor: nesw-resize; }
.crop-box .h[data-handle="w"] { top: 50%; left: 0; cursor: ew-resize; }
.crop-label { position: absolute; top: -1.5rem; left: -2px; font-size: var(--t-xs); letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; background: var(--accent); color: var(--accent-ink); padding: var(--s-0) var(--s-2); border-radius: var(--r-sm) var(--r-sm) 0 0; line-height: 1.3; white-space: nowrap; }
.crop-box.full .crop-label { display: none; }
.crop-hint { font-size: var(--t-sm); margin: var(--s-2) 0 0; line-height: 1.4; }
.progress { height: 6px; background: var(--line); border-radius: var(--r-full); overflow: hidden; margin-top: var(--s-3); }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width var(--dur) var(--ease-out); }
.status { font-size: var(--t-sm); color: var(--muted); margin-top: var(--s-2); min-height: 1.2em; }
.status.error { color: var(--high-ink); }
.tips { font-size: var(--t-sm); color: var(--muted); margin: var(--s-3) 0 0; }
.step-label { font-size: var(--t-xs); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: var(--s-1); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: var(--s-0) var(--s-2);
  border-radius: var(--r-full);
  font-size: var(--t-xs);
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.5;
  border: 1px solid transparent;
}
.chip-none { background: var(--none-bg); color: var(--none-ink); }
.chip-low { background: var(--low-bg); color: var(--low-ink); }
.chip-moderate { background: var(--moderate-bg); color: var(--moderate-ink); }
.chip-high { background: var(--high-bg); color: var(--high-ink); }
.chip-unknown { background: var(--unknown-bg); color: var(--unknown-ink); }
.chip-tag { background: var(--unknown-bg); color: var(--unknown-ink); font-weight: 500; }

.profile { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.profile .toggle { border: 1px solid var(--line-strong); background: transparent; border-radius: var(--r-full); padding: var(--s-2) var(--s-4); font: inherit; font-size: var(--t-sm); cursor: pointer; color: var(--text); transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out); }
.profile .toggle:hover { background: var(--card-2); }
.profile .toggle[aria-pressed="true"] { background: var(--btn); color: var(--accent-ink); border-color: var(--btn); }

/* Results enter from below once, when they first appear. */
#results:not([hidden]) { animation: rise-in var(--dur-slow) var(--ease-out); }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--s-3); margin-bottom: var(--s-4); }
.verdict-card { border-left: 4px solid var(--unknown-ink); }
.verdict-card.v-none { border-left-color: var(--none-ink); }
.verdict-card.v-low { border-left-color: var(--low-ink); }
.verdict-card.v-moderate { border-left-color: var(--moderate-ink); }
.verdict-card.v-high { border-left-color: var(--high-ink); }
.verdict-card h3 { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); font-family: var(--font-sans); font-weight: 700; font-size: var(--t-md); }
.verdict-card .msg { font-size: var(--t-sm); }
.verdict-card ul { margin: var(--s-2) 0 0; padding-left: var(--s-4); font-size: var(--t-sm); }
.verdict-card li { margin-bottom: var(--s-1); }
/* A long name wraps inside its button, which lines up by its last line; top alignment keeps the bullet
   next to the first line ("Hamamelis Virginiana (Witch Hazel) Extract" on a phone). */
.verdict-card li > .linklike { vertical-align: top; }
.linklike { all: unset; cursor: pointer; color: var(--accent); font-weight: 600; }
.linklike:hover { text-decoration: underline; }

.notes { list-style: none; margin: 0; padding: 0; }
.notes li { padding: var(--s-2) var(--s-3); border-radius: var(--r-md); margin-bottom: var(--s-2); font-size: var(--t-sm); }
.notes li.warn { background: var(--moderate-bg); color: var(--moderate-ink); }
.notes li.info { background: var(--unknown-bg); color: var(--unknown-ink); }
.notes li.good { background: var(--none-bg); color: var(--none-ink); }

.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-row { display: grid; grid-template-columns: var(--s-6) 1fr auto; gap: var(--s-3); align-items: start; padding: var(--s-3) 0; border-top: 1px solid var(--line); }
.ing-row:first-child { border-top: 0; }
.ing-row .pos { color: var(--muted); font-size: var(--t-xs); padding-top: var(--s-0); font-variant-numeric: tabular-nums; }
.ing-row .name { font-weight: 600; }
.ing-row .name button { all: unset; cursor: pointer; color: var(--accent); font-weight: 600; }
.ing-row .name button:hover { text-decoration: underline; }
.ing-row .sub { font-size: var(--t-xs); color: var(--muted); }
.ing-row .chips { display: flex; flex-wrap: wrap; gap: var(--s-1); justify-content: flex-end; max-width: 200px; }
.ing-row.unmatched .name { color: var(--muted); font-weight: 500; }
.ing-row.duplicate { opacity: 0.6; }
.suggest { display: flex; flex-wrap: wrap; gap: var(--s-1); margin-top: var(--s-2); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-5); font-size: var(--t-xs); color: var(--muted); margin-top: var(--s-3); }
.disclaimer { font-size: var(--t-xs); color: var(--muted); border-top: 1px solid var(--line); padding-top: var(--s-3); }

/* ---------------------------------------------------------------- library */
.searchbar { display: grid; grid-template-columns: 1fr; gap: var(--s-3); }
@media (min-width: 680px) { .searchbar { grid-template-columns: 2fr 1fr 1fr; } }
.result-count { font-size: var(--t-sm); color: var(--muted); margin: var(--s-3) 0; }
.ing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s-3); }
.ing-card { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); cursor: pointer; font: inherit; color: var(--text); transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
.ing-card:hover { border-color: var(--line-strong); background: var(--card-2); }
.ing-card .t { font-weight: 600; display: flex; justify-content: space-between; gap: var(--s-2); flex-wrap: wrap; color: var(--text-strong); }
.ing-card .t .cat { font-weight: 500; color: var(--muted); font-size: var(--t-xs); }
.ing-card .names { display: block; font-size: var(--t-xs); color: var(--muted); margin: var(--s-1) 0 var(--s-2); }
.ing-card .chips { display: flex; gap: var(--s-1); flex-wrap: wrap; }

.product-card { display: block; text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4); transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
.product-card:hover { border-color: var(--line-strong); background: var(--card-2); }
.product-card .brand-l { font-size: var(--t-xs); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.product-card .pname { font-family: var(--font-serif); font-size: var(--t-lg); color: var(--text-strong); margin: var(--s-1) 0 var(--s-2); }
.product-card .meta { font-size: var(--t-xs); color: var(--muted); }
.empty { text-align: center; padding: var(--s-7) var(--s-4); color: var(--muted); }
.empty .big { font-family: var(--font-serif); font-size: var(--t-xl); color: var(--text-strong); margin-bottom: var(--s-2); }

/* ---------------------------------------------------------------- modal */
dialog.modal { border: 1px solid var(--line); border-radius: var(--r-xl); padding: 0; max-width: 660px; width: calc(100% - var(--s-6)); background: var(--card); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
/* Opens with a short ease-out rise; closes faster (common.js adds .closing before calling close()). */
dialog.modal[open] { animation: modal-in var(--dur-slow) var(--ease-out); }
dialog.modal[open]::backdrop { animation: fade-in var(--dur-slow) var(--ease-out); }
dialog.modal.closing { animation: modal-out var(--dur-fast) var(--ease-in) forwards; }
dialog.modal.closing::backdrop { animation: fade-out var(--dur-fast) var(--ease-in) forwards; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(4px) scale(0.98); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.modal-body { padding: var(--s-5) var(--s-5) var(--s-6); max-height: 85vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-4); }
.modal-head h2 { margin: 0; }
.modal .close { all: unset; cursor: pointer; font-size: var(--t-xl); line-height: 1; padding: var(--s-1) var(--s-2); border-radius: var(--r-sm); color: var(--muted); transition: background-color var(--dur-fast) var(--ease-out); }
.modal .close:hover { background: var(--card-2); color: var(--text-strong); }

/* Phones: the dialog becomes a bottom sheet. It slides up from the bottom edge and follows a finger dragged down
   from the handle, or from the content once that is scrolled to the top; let go past a quarter of its height or
   with a quick flick and it closes, otherwise it springs back. common.js sets --drag (px) and --drag-progress (0-1)
   while the finger is down and adds .settling for the spring back. */
.sheet-handle { display: none; }
@media (max-width: 640px) {
  dialog.modal {
    width: 100%;
    max-width: none;
    max-height: 92vh;
    max-height: 92dvh;
    margin: auto 0 0;
    overflow: hidden;
    border-bottom: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    transform: translateY(var(--drag, 0px));
  }
  dialog.modal[open] { display: flex; flex-direction: column; animation: sheet-in var(--dur-sheet) var(--ease-sheet); }
  dialog.modal[open]::backdrop { animation: fade-in var(--dur-sheet) var(--ease-sheet); }
  dialog.modal.closing { animation: sheet-out var(--dur-slow) var(--ease-in) forwards; }
  dialog.modal.closing::backdrop { animation: fade-out var(--dur-slow) var(--ease-in) forwards; }
  dialog.modal.settling { transition: transform var(--dur-slow) var(--ease-sheet); }
  dialog.modal.dragging { user-select: none; -webkit-user-select: none; }
  /* Where ::backdrop inherits from its dialog, it fades as the sheet is pulled away. */
  dialog.modal.dragging::backdrop { opacity: calc(1 - var(--drag-progress, 0)); }
  .sheet-handle { display: block; flex: none; position: relative; height: var(--s-5); cursor: grab; touch-action: none; }
  .sheet-handle::before { content: ""; position: absolute; top: var(--s-2); left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: var(--r-full); background: var(--muted); opacity: 0.45; }
  dialog.modal.dragging .sheet-handle { cursor: grabbing; }
  .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding-top: 0;
    padding-bottom: calc(var(--s-6) + env(safe-area-inset-bottom, 0px));
    overscroll-behavior: contain;
  }
}
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-1) var(--s-4); font-size: var(--t-sm); margin: var(--s-3) 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.ratings { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); margin: var(--s-4) 0; }
.rating { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3); text-align: center; }
.rating .lbl { font-size: var(--t-xs); color: inherit; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.08em; }
.rating .val { font-weight: 700; font-size: var(--t-md); margin-top: var(--s-1); }
.rating.r-none { background: var(--none-bg); color: var(--none-ink); }
.rating.r-low { background: var(--low-bg); color: var(--low-ink); }
.rating.r-moderate { background: var(--moderate-bg); color: var(--moderate-ink); }
.rating.r-high { background: var(--high-bg); color: var(--high-ink); }
.rating.r-unknown { background: var(--unknown-bg); color: var(--unknown-ink); }
.tags { display: flex; flex-wrap: wrap; gap: var(--s-1); margin-top: var(--s-3); }
.modal-foot { margin: var(--s-5) 0 0; padding-top: var(--s-4); border-top: 1px solid var(--line); font-size: var(--t-sm); }

/* ---------------------------------------------------------------- feedback (feedback.js, admin-feedback.js) */
.fb-form, .fb-done { display: grid; gap: var(--s-4); }
.fb-form h2, .fb-done h2 { margin: 0; }
.fb-done p { margin: 0; }
.fb-form textarea { min-height: 120px; }
.fb-form .status { margin: 0; min-height: 0; }
.fb-about { margin: calc(var(--s-2) * -1) 0 0; color: var(--muted); }
.fb-about strong { color: var(--text-strong); }
.fb-optional { text-transform: none; letter-spacing: 0; font-weight: 400; }
.fb-check { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-sm); }
.fb-check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.fb-preview { margin-top: calc(var(--s-2) * -1); }
.fb-preview summary, .fb-item summary { cursor: pointer; font-size: var(--t-sm); color: var(--muted); }
.fb-preview pre, .fb-item pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow: auto; font-size: var(--t-xs); line-height: 1.5; background: var(--card-2); padding: var(--s-3); border-radius: var(--r-md); margin: var(--s-2) 0; }
.fb-note { margin: 0; }
/* Hidden from people and screen readers; bots that fill every field give themselves away. */
.fb-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.report-line { margin-top: var(--s-4); font-size: var(--t-sm); color: var(--muted); text-align: center; }
.fb-page { margin-bottom: var(--s-7); }
body[data-no-feedback] [data-feedback], body[data-no-feedback] .report-line { display: none; }

.admin-bar { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end; margin-bottom: var(--s-2); }
.admin-bar label.field { min-width: 200px; }
.admin-login { max-width: 420px; display: grid; gap: var(--s-3); }
.fb-list { display: grid; gap: var(--s-3); margin-bottom: var(--s-5); }
.fb-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-4); display: grid; gap: var(--s-3); }
.fb-item.is-removed { opacity: 0.5; }
.fb-item-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-3); font-size: var(--t-sm); color: var(--muted); }
.fb-item-head strong { color: var(--text-strong); }
.fb-msg { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-strong); }
.fb-meta { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); font-size: var(--t-sm); color: var(--muted); }
.fb-items { margin: var(--s-2) 0 0; padding-left: var(--s-5); font-size: var(--t-xs); color: var(--muted); columns: 2 240px; }
.fb-items .miss { color: var(--high-ink); }
.fb-admin { display: grid; grid-template-columns: 170px 1fr auto auto; gap: var(--s-2) var(--s-3); align-items: end; }
.fb-admin textarea { min-height: 46px; }
.fb-admin .btn { min-height: 46px; }
.fb-item .status { margin: 0; min-height: 0; }
@media (max-width: 640px) {
  .fb-admin { grid-template-columns: 1fr 1fr; }
  .fb-admin label.field { grid-column: 1 / -1; }
}

/* ---------------------------------------------------------------- prose */
.prose h2 { margin-top: var(--s-6); }
/* Linked headings (/privacy#delete-your-data) land below the sticky header, not under it. */
.prose h2[id] { scroll-margin-top: calc(5rem + env(safe-area-inset-top, 0px)); }
.prose table { border-collapse: collapse; width: 100%; font-size: var(--t-sm); margin: var(--s-3) 0 var(--s-5); }
.prose th, .prose td { border: 1px solid var(--line); padding: var(--s-2) var(--s-3); text-align: left; vertical-align: top; }
.prose th { background: var(--bg-elev); font-weight: 600; }
.prose ul, .prose ol { padding-left: var(--s-5); }
.prose li { margin-bottom: var(--s-1); }

/* ---------------------------------------------------------------- footer */
footer.site { border-top: 1px solid var(--line); margin-top: var(--s-6); }
.footer-inner { max-width: 1180px; margin: 0 auto; padding: var(--s-6) var(--s-5) calc(var(--s-7) + env(safe-area-inset-bottom, 0px)); display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-4); font-size: var(--t-xs); color: var(--muted); }
.footer-inner .fbrand { font-family: var(--font-serif); font-weight: 700; color: var(--text-strong); font-size: var(--t-lg); margin-bottom: var(--s-1); }
.footer-inner nav { display: flex; gap: var(--s-4); flex-wrap: wrap; }
.footer-inner nav a { color: var(--muted); text-decoration: none; transition: color var(--dur-fast) var(--ease-out); }
.footer-inner nav a:hover { color: var(--text-strong); }
/* Version label: last line of the footer, bottom right. */
.footer-inner .app-version { flex-basis: 100%; text-align: right; font-size: var(--t-xs); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; opacity: 0.75; }

/* ---------------------------------------------------------------- helpers (no inline styles; the CSP forbids them) */
[data-theme-toggle] .icon-moon { display: none; }
[data-theme="light"] [data-theme-toggle] .icon-sun { display: none; }
[data-theme="light"] [data-theme-toggle] .icon-moon { display: block; }
.mt-sm { margin-top: var(--s-3); }
.flush-top { margin-top: 0; }
.spaced-bottom { margin-bottom: var(--s-5); }
.actions.flush { margin-bottom: 0; }
.actions.center { justify-content: center; margin-top: var(--s-4); }
.actions.center .btn { flex: 0 0 auto; }
.btn.check { gap: var(--s-1); }
.step-label.spaced { margin-top: var(--s-5); }
.results-head { margin-bottom: var(--s-3); }
.results-head:focus { outline: none; }
.count { font-family: var(--font-sans); font-size: var(--t-sm); font-weight: 400; }
.fine-print { font-size: var(--t-sm); }
.unrated-note { font-size: var(--t-xs); margin-top: var(--s-2); }
.searchbar.single { grid-template-columns: 1fr; }
.empty.wide { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
main:focus { outline: none; }

/* Skip link: first Tab stop, visible only when focused. */
.skip-link { position: absolute; left: var(--s-3); top: -3rem; z-index: 50; background: var(--btn); color: var(--accent-ink); padding: var(--s-2) var(--s-4); border-radius: var(--r-md); font-weight: 600; text-decoration: none; }
.skip-link:focus { top: calc(var(--s-2) + env(safe-area-inset-top, 0px)); }

/* Keyboard focus. Several controls use "all: unset", which also removes the browser's focus ring. */
.btn:focus-visible, .icon-btn:focus-visible, .toggle:focus-visible, .ing-card:focus-visible, .product-card:focus-visible,
.linklike:focus-visible, .ing-row .name button:focus-visible, .modal .close:focus-visible, .nav a:focus-visible, .brand:focus-visible,
.footer-inner nav a:focus-visible, .lang-pick:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Phones */
@media (max-width: 560px) {
  .topbar-inner { padding-left: calc(var(--s-4) + env(safe-area-inset-left, 0px)); padding-right: calc(var(--s-4) + env(safe-area-inset-right, 0px)); gap: var(--s-3); }
  main { padding-left: calc(var(--s-4) + env(safe-area-inset-left, 0px)); padding-right: calc(var(--s-4) + env(safe-area-inset-right, 0px)); }
  .card { padding: var(--s-4); }
  .ing-row { grid-template-columns: var(--s-5) 1fr; }
  .ing-row .chips { grid-column: 2; justify-content: flex-start; max-width: none; }
  .ratings { gap: var(--s-2); }
  .rating { padding: var(--s-2) var(--s-1); }
  .kv { grid-template-columns: 1fr; gap: var(--s-0); }
  .kv dd { margin-bottom: var(--s-2); }
  .preview-tools .btn.primary { flex: 1 1 100%; }
  .example { padding: var(--s-4); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
