/* Expiry : design system.
   Graphite dark palette, sage accent, system type, 4/8 spacing scale,
   restrained radii, tabular countdown numerals, 120-200ms motion. */

:root {
  --bg: #101312;
  --surface: #1B201D;
  --surface-2: #232925;
  --surface-3: #2A312C;
  --line: #2C332E;
  --line-strong: #3A423C;

  --text: #F3F1E9;
  --muted: #A9AEA2;
  --faint: #8A9186; /* ≥4.5:1 on surfaces : checked by scripts/check-contrast.mjs */

  --sage: #BED7BC;
  --sage-strong: #A6C5A4;
  --sage-ink: #101312;

  --amber: #E5B459;
  --amber-ink: #101312;
  --red: #E58B7B;
  --red-strong: #C96F60;
  --red-ink: #101312;

  --focus: #BED7BC;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px;

  --tab-h: 62px;

  font-size: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- primitives ---------- */

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--sage-strong); }
button, input, select, textarea { font: inherit; color: inherit; }

.num, .count {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.ic { width: 20px; height: 20px; flex: none; display: block; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 var(--s4);
  border-radius: var(--r);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 560;
  cursor: pointer;
  text-decoration: none;
  -webkit-user-select: none; user-select: none;
  transition: background 150ms ease, border-color 150ms ease, transform 100ms ease;
}
.btn:active { transform: scale(0.985); }
.btn:hover { background: var(--surface-3); }
.btn-primary {
  background: var(--sage); color: var(--sage-ink); border-color: var(--sage);
  font-weight: 650;
}
.btn-primary:hover { background: var(--sage-strong); }
.btn-danger { color: var(--red); border-color: rgba(229, 139, 123, 0.45); }
.btn-danger:hover { border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon { min-width: 44px; width: 44px; padding: 0; }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: 14px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* chips & badges */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 520;
  line-height: 1.6;
  white-space: nowrap;
}
.chip.sage { color: var(--sage); border-color: rgba(190, 215, 188, 0.35); background: rgba(190, 215, 188, 0.08); }
.chip.amber { color: var(--amber); border-color: rgba(229, 180, 89, 0.4); background: rgba(229, 180, 89, 0.08); }
.chip.red { color: var(--red); border-color: rgba(229, 139, 123, 0.4); background: rgba(229, 139, 123, 0.09); }

.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

/* urgency text colours (always paired with words/date, never colour alone) */
.u-red { color: var(--red); }
.u-amber { color: var(--amber); }
.u-calm { color: var(--sage); }
.u-muted { color: var(--muted); }

/* ---------- app frame ---------- */

.app {
  /* vh, not dvh: the dynamic unit tracks iOS Safari's collapsing URL bar and
     makes the page reflow mid-fling, which read as "fast scroll jumps to
     top". A fixed viewport unit keeps layout stable during momentum scroll. */
  min-height: 100vh;
  display: flex;
}

.side {
  display: none;
  width: 236px;
  flex: none;
  border-right: 1px solid var(--line);
  padding: var(--s6) var(--s4) var(--s6);
  flex-direction: column;
  gap: var(--s2);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: var(--s2) var(--s3) var(--s6); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--sage); color: var(--sage-ink);
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.01em; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 var(--s3);
  border-radius: var(--r);
  color: var(--muted);
  text-decoration: none;
  font-weight: 540;
  transition: background 150ms ease, color 150ms ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active .ic { color: var(--sage); }

.side .btn { margin-top: var(--s3); }
.side-foot { margin-top: auto; padding: var(--s3); color: var(--faint); font-size: 12.5px; line-height: 1.6; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3);
  padding: calc(env(safe-area-inset-top) + var(--s4)) var(--s4) var(--s3);
  max-width: 1280px; width: 100%; margin: 0 auto;
}
.topbar h1 { font-size: 24px; letter-spacing: -0.02em; }
.topbar .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

#view {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--s2) var(--s4) var(--s8);
  flex: 1;
}

/* mobile tab bar */
.tabbar {
  display: flex;
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  /* Solid fill: backdrop-filter blurs make iOS Safari scroll janky. */
  background: #121614;
  border-top: 1px solid var(--line);
  z-index: 40;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--faint);
  text-decoration: none;
  min-height: 44px;
  font-size: 11px;
  font-weight: 540;
  letter-spacing: 0.02em;
}
.tab .ic { width: 22px; height: 22px; }
.tab.active { color: var(--sage); }
.sr-only-tab {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}
.tab-add { color: var(--sage-ink); }
.tab-add .fab {
  width: 48px; height: 48px; margin-top: -16px;
  border-radius: 14px;
  background: var(--sage);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}
.tab-add .ic { width: 24px; height: 24px; }

/* ---------- wallet ---------- */

.wallet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap;
}

.search {
  position: relative; flex: 1; min-width: 180px; max-width: 420px;
}
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--s4) 0 40px;
  border-radius: var(--r);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}
.search input::placeholder { color: var(--faint); }

.seg {
  display: flex; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 3px;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  min-height: 38px; padding: 0 var(--s3);
  border-radius: var(--r-sm);
  font-weight: 540; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.seg button.active { background: var(--surface-3); color: var(--text); }

.list { display: flex; flex-direction: column; gap: var(--s2); }

.row {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: inherit; text-decoration: none;
  min-height: 64px;
  transition: border-color 150ms ease, background 150ms ease;
}
.row:hover { border-color: var(--line-strong); background: var(--surface-2); }
.row:active { background: var(--surface-2); }
.row.overdue { border-left: 3px solid var(--red); }

.row-ic {
  width: 42px; height: 42px; flex: none;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.row-ic .ic { width: 22px; height: 22px; }

.row-body { flex: 1; min-width: 0; }
.row-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 15.5px;
  min-height: 24px;
}
.row-title .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-sub {
  display: block; /* inline elements ignore overflow/text-overflow */
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.row-sub .ref { color: var(--faint); }

.row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.row-count { font-weight: 650; font-size: 16px; letter-spacing: 0.01em; }
.row-count small { font-size: 11.5px; font-weight: 560; margin-left: 1px; }
.row-when { color: var(--faint); font-size: 11.5px; white-space: nowrap; }

/* featured urgent item */
.featured {
  border: 1px solid var(--line);
  border-left: 4px solid var(--red);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  padding: var(--s4) var(--s4) var(--s3);
  display: flex; gap: var(--s3); align-items: center;
  color: inherit; text-decoration: none;
  margin-bottom: var(--s2);
}
.featured .fx-body { flex: 1; min-width: 0; }
.featured .fx-action { font-size: 17px; font-weight: 650; margin-top: 4px; }
.featured .fx-date { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.featured-actions { display: flex; gap: var(--s2); margin-top: var(--s3); }
.featured-actions .btn { min-height: 38px; }

/* empty / no results */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--s4);
  padding: var(--s16) var(--s6);
  color: var(--muted);
}
.empty .ec {
  width: 64px; height: 64px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; color: var(--sage);
}
.empty .ec .ic { width: 30px; height: 30px; }
.empty h2 { color: var(--text); font-size: 19px; letter-spacing: -0.01em; }
.empty p { max-width: 300px; font-size: 14.5px; line-height: 1.55; }

/* upcoming */
.day-label {
  color: var(--faint); font-size: 12.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: var(--s6) 0 var(--s2);
  display: flex; align-items: center; gap: 8px;
}
.day-label .chip { text-transform: none; letter-spacing: 0; }

/* ---------- detail ---------- */

.detail { display: flex; flex-direction: column; gap: var(--s4); animation: view-in 160ms ease; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.detail-head { display: flex; align-items: flex-start; gap: var(--s3); }
.detail-head .row-ic { width: 52px; height: 52px; }
.detail-head .row-ic .ic { width: 26px; height: 26px; }
.detail-head h2 { font-size: 22px; letter-spacing: -0.01em; line-height: 1.25; }
.detail-head .sub { color: var(--muted); font-size: 14px; margin-top: 3px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4);
}
.panel + .panel { margin-top: var(--s3); }
.panel h3 {
  font-size: 13px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--faint);
  margin-bottom: var(--s3);
}
.panel .hint { color: var(--faint); font-size: 13px; margin-top: var(--s2); line-height: 1.55; }

.action-callout { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.action-callout .big { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.action-callout .right { margin-left: auto; text-align: right; }

.kv { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: var(--s2) var(--s4); font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 540; }
.kv .deriv { color: var(--faint); font-size: 13px; font-weight: 400; margin-top: 2px; }

.actions-grid { display: flex; flex-wrap: wrap; gap: var(--s2); }
.actions-grid .btn { flex: 1 1 auto; min-width: 150px; }

.photos {
  display: flex; gap: var(--s3);
}
.thumb {
  position: relative;
  width: 96px; height: 76px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  overflow: hidden;
  color: var(--faint);
  padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .side-label {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(16, 19, 18, 0.82);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 10.5px; font-weight: 600;
  padding: 1px 6px; border-radius: 6px;
}

.hist { list-style: none; margin: 0; padding: 0; }
.hist li {
  display: flex; gap: var(--s3); align-items: baseline;
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.hist li:last-child { border-bottom: 0; }
.hist .h-type { color: var(--text); font-weight: 560; }
.hist .h-at { color: var(--faint); font-size: 12.5px; margin-left: auto; white-space: nowrap; }

.danger-zone { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------- forms (add/edit) ---------- */

.form { display: flex; flex-direction: column; gap: var(--s4); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.field .help { font-size: 12.5px; color: var(--faint); }
.field input[type="text"], .field input[type="search"], .field input[type="date"],
.field input[type="number"], .field input[type="time"], .field select, .field textarea {
  min-height: 46px;
  padding: 10px var(--s3);
  border-radius: var(--r);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* 16px prevents iOS auto-zoom */
  width: 100%;
}
.field textarea { min-height: 92px; resize: vertical; }
.field input.invalid, .field select.invalid { border-color: var(--red); }
.field .err { color: var(--red); font-size: 13px; min-height: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--s3); }

.date-badge {
  display: flex; align-items: center; gap: 10px;
  padding: var(--s3) var(--s4);
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
}
.date-badge .db-main { font-size: 17px; font-weight: 650; }
.date-badge .db-sub { color: var(--muted); font-size: 13px; }
.date-badge.warn { border-color: rgba(229, 180, 89, 0.5); }
.date-badge.bad { border-color: var(--red); }

/* method tabs */
.methods {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: var(--s2);
}
.method {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px;
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.method .ic { color: var(--sage); }
.method small { display: block; color: var(--faint); font-size: 12px; font-weight: 400; }
.method.on { border-color: var(--sage); }

/* template picker */
.tpl-groups { display: flex; flex-direction: column; gap: var(--s5); }
.tpl-group h4 {
  margin: 0 0 var(--s2);
  font-size: 12.5px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--faint);
}
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s2); }
.tpl {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  padding: var(--s3) var(--s3);
  text-align: left;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.tpl .tpl-name { font-weight: 600; font-size: 14px; }
.tpl .tpl-desc { color: var(--faint); font-size: 12px; }
.tpl.on { border-color: var(--sage); background: rgba(190, 215, 188, 0.06); }

.interpret {
  border-left: 3px solid var(--sage);
  padding: var(--s3) var(--s4);
  background: rgba(190, 215, 188, 0.05);
  border-radius: 0 var(--r) var(--r) 0;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 14px;
}
.interpret .i-warn { border-color: var(--amber); background: rgba(229, 180, 89, 0.05); }
.interpret .li { color: var(--muted); }
.interpret b { color: var(--text); font-weight: 600; }
.interpret .warn { color: var(--amber); font-weight: 540; }

.choice-row { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s2); }
.choice {
  min-height: 40px; padding: 6px var(--s3);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 14px; cursor: pointer;
}
.choice.on { border-color: var(--sage); color: var(--sage); }

/* ---------- photo capture ---------- */

.capture {
  display: flex; flex-direction: column; gap: var(--s3);
  align-items: stretch;
}
.preview-wrap {
  position: relative;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  background: #0C0E0D;
  min-height: 220px;
  display: flex; align-items: center; justify-content: center;
}
.preview-wrap canvas, .preview-wrap img { max-width: 100%; max-height: 60vh; display: block; }
.preview-wrap .ph-fallback { color: var(--faint); padding: var(--s10); text-align: center; }

.corner-handle {
  position: absolute;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  border: 0; padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}
.corner-handle::before {
  content: "";
  position: absolute; inset: 9px;
  border-radius: 50%;
  background: var(--sage);
  border: 2px solid #101312;
  box-shadow: 0 0 0 1.5px var(--sage);
}

.capture-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.capture-actions .btn { flex: 1 1 auto; min-width: 110px; }

.progress-line { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: 14px; }
.progress-line .pct { color: var(--sage); font-variant-numeric: tabular-nums; margin-left: auto; }

/* OCR candidates */
.ocr-cand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3);
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface);
  margin-bottom: var(--s2);
  width: 100%; text-align: left; color: var(--text);
  cursor: pointer;
}
.ocr-cand .c-date { font-weight: 650; font-size: 15px; white-space: nowrap; }
.ocr-cand .c-snip { color: var(--faint); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ocr-cand .c-rank { color: var(--sage); display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 11.5px; }
.ocr-cand.on { border-color: var(--sage); background: rgba(190, 215, 188, 0.06); }

/* voice */
.voice-box {
  display: flex; flex-direction: column; align-items: center; gap: var(--s4);
  padding: var(--s8) var(--s4);
  text-align: center;
}
.voice-box .mic-big {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--sage); color: var(--sage-ink);
  display: flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer;
}
.voice-box .mic-big.listening { animation: pulse 1.4s ease infinite; }
@keyframes pulse { 50% { transform: scale(1.08); box-shadow: 0 0 0 14px rgba(190, 215, 188, 0.12); } }
.voice-transcript { min-height: 30px; font-size: 16px; font-weight: 540; }

/* ---------- dialogs & toasts ---------- */

dialog {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
  max-height: min(80vh, 720px);
}
dialog::backdrop { background: rgba(8, 10, 9, 0.72); }
.dialog-body { padding: var(--s5) var(--s5) var(--s4); overflow-y: auto; max-height: 72vh; }
.dialog-body h2 { font-size: 19px; margin-bottom: var(--s3); }
.dialog-body p { color: var(--muted); font-size: 14.5px; margin-bottom: var(--s3); line-height: 1.55; }
.dialog-body p:last-child { margin-bottom: 0; }
.dialog-actions {
  display: flex; gap: var(--s2); flex-wrap: wrap;
  padding: var(--s3) var(--s5) calc(var(--s4) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.dialog-actions .btn { flex: 1 1 auto; min-width: 120px; }

#toasts {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  display: flex; flex-direction: column; gap: var(--s2);
  z-index: 60;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--r);
  padding: var(--s3) var(--s4);
  font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toast-in 160ms ease;
}
.toast .ic { margin-top: 1px; color: var(--sage); }
.toast.warn { border-color: rgba(229, 180, 89, 0.5); }
.toast.warn .ic { color: var(--amber); }
.toast.err { border-color: rgba(229, 139, 123, 0.5); }
.toast.err .ic { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* photo viewer */
.viewer { background: #0C0E0D; }
.viewer .viewer-img {
  max-width: 100%; max-height: 100%;
  display: block; margin: 0 auto;
  object-fit: contain;
}
.viewer .viewer-tools {
  display: flex; justify-content: center; gap: var(--s2);
  padding: var(--s3);
  position: sticky; bottom: 0;
  background: rgba(12, 14, 13, 0.9);
}

/* misc */
.center-box { max-width: 520px; margin: var(--s8) auto 0; width: 100%; }
.list-title { font-size: 13px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); margin: var(--s6) 0 var(--s2); }
.link-foot { color: var(--faint); font-size: 13px; }
.row-click { cursor: pointer; }

.banner {
  display: flex; align-items: center; gap: var(--s3);
  background: rgba(190, 215, 188, 0.07);
  border: 1px solid rgba(190, 215, 188, 0.3);
  color: var(--sage);
  border-radius: var(--r);
  padding: var(--s3) var(--s4);
  font-size: 14px;
  margin-bottom: var(--s4);
}
.banner .btn { margin-left: auto; }

.update-banner {
  background: rgba(229, 180, 89, 0.08);
  border-color: rgba(229, 180, 89, 0.45);
  color: var(--amber);
}

.demobar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px dashed var(--line-strong);
  color: var(--muted);
  border-radius: var(--r);
  padding: var(--s2) var(--s4);
  font-size: 13.5px;
  margin-bottom: var(--s4);
}
.demobar b { color: var(--amber); }

.noscript { padding: var(--s16); text-align: center; }

/* ---------- responsive ---------- */

@media (min-width: 780px) {
  .side { display: flex; }
  .tabbar { display: none; }
  .main { padding-bottom: var(--s8); }
  #toasts { bottom: 24px; }
  .search { max-width: 320px; }
  .methods { grid-template-columns: repeat(3, 1fr); }
  .tpl-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}

@media (min-width: 1120px) {
  .main-detail { display: flex; gap: var(--s6); align-items: flex-start; }
  .main-detail > .list-pane { flex: 1 1 46%; min-width: 0; }
  .main-detail > .detail-pane { flex: 1 1 54%; min-width: 0; position: sticky; top: var(--s4); }
}

@media (max-width: 430px) {
  .row-count { font-size: 15px; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .featured-actions .btn { flex: 1; }
}

/* Consistent affordance: interactive cards answer to hover and touch. */
.tpl:hover, .method:hover, .ocr-cand:hover, .featured:hover, .choice:hover { border-color: var(--line-strong); }
.tpl:active, .method:active, .ocr-cand:active, .featured:active { background: var(--surface-2); }
.thumb:hover { border-color: var(--line-strong); }
.thumb:active { border-color: var(--sage); }

/* Touch devices: every interactive control meets the 44px minimum target
   size, even the compact variants used on desktop. */
@media (pointer: coarse) {
  .btn-sm { min-height: 44px; padding: 0 var(--s4); }
  .btn-icon { min-width: 44px; width: 44px; }
  .seg button { min-height: 44px; }
  .choice { min-height: 44px; padding: 8px var(--s4); }
  .thumb { width: 104px; height: 84px; }
  .tab { min-height: 48px; }
  .corner-handle { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .corner-handle::before { inset: 14px; }
  .ocr-cand { min-height: 56px; }
}

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