/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --accent: #6d3fc0;
  --accent-strong: #55279f;
  --accent-soft: #efe8fb;
  --on-accent: #ffffff;
  --bg: #f7f6f9;
  --surface: #ffffff;
  --surface-2: #f1eff4;
  --text: #1b1820;
  --muted: #5e5868;
  --border: #e3dfe8;
  --flag: #8a4b00;
  --flag-bg: #fff3e0;
  --danger: #b3261e;
  --star: #6d3fc0;
  --shadow: 0 1px 2px rgba(20, 10, 40, .06), 0 2px 8px rgba(20, 10, 40, .06);
  --radius: 14px;
  --tap: 48px;
  font-size: 100%;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --accent: #b79cff; --accent-strong: #cdb9ff; --accent-soft: #2c2340; --on-accent: #1a1228;
    --bg: #141218; --surface: #1e1b24; --surface-2: #27232f; --text: #ece8f2; --muted: #a9a2b5;
    --border: #34303c; --flag: #f0b45a; --flag-bg: #33270f; --danger: #ffb4ab; --star: #b79cff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #b79cff; --accent-strong: #cdb9ff; --accent-soft: #2c2340; --on-accent: #1a1228;
  --bg: #141218; --surface: #1e1b24; --surface-2: #27232f; --text: #ece8f2; --muted: #a9a2b5;
  --border: #34303c; --flag: #f0b45a; --flag-bg: #33270f; --danger: #ffb4ab; --star: #b79cff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
:root[data-contrast="high"] { --muted: var(--text); --border: #6b6475; --accent: #4a1d96; --accent-strong: #3a1478; }
@media (prefers-color-scheme: dark) {
  :root[data-contrast="high"]:not([data-theme="light"]) { --border: #8c8499; --accent: #d9ccff; --accent-strong: #ece4ff; --text: #ffffff; --muted: #ffffff; }
}
:root[data-theme="dark"][data-contrast="high"] { --border: #8c8499; --accent: #d9ccff; --accent-strong: #ece4ff; --text: #ffffff; --muted: #ffffff; }
:root[data-text="large"] { font-size: 118.75%; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .75rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .5rem 16px; padding-top: max(.5rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.15rem; min-height: var(--tap); }
.env-badge { background: #c62828; color: #fff; border-radius: 6px; padding: .1rem .5rem; font-size: .8rem; font-weight: 800; letter-spacing: .05em; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border-radius: 50%;
  border: 0; background: transparent; color: var(--text); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 26px; height: 26px; fill: currentColor; }

main { max-width: 960px; margin: 0 auto; padding: 16px 16px 4rem; }
main:focus { outline: none; }
.loading, .empty { color: var(--muted); text-align: center; padding: 3rem 1rem; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: 0 1.15rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field > span { font-weight: 600; font-size: .95rem; }
.field small { color: var(--muted); }
input[type="text"], input[type="url"], input[type="search"], input[type="password"], input[type="number"], textarea, select {
  width: 100%; min-height: var(--tap); padding: .65rem .9rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
textarea { min-height: 8rem; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 0; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
@media (max-width: 420px) { .row-3 { grid-template-columns: 1fr 1fr; } }

/* ---------- home ---------- */
.add-bar {
  display: flex; gap: .5rem; padding: .5rem; border-radius: 999px; background: var(--surface);
  border: 2px solid var(--accent); box-shadow: var(--shadow); margin-bottom: .75rem;
}
.add-bar input { border: 0; min-height: var(--tap); background: transparent; border-radius: 999px; padding-left: 1rem; }
.add-bar input:focus { outline: none; }
.add-bar:focus-within { outline: 3px solid var(--accent-soft); }
.add-hint { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .9rem; margin: 0 .5rem 1.25rem; }
.add-hint a { white-space: nowrap; }
.search { margin-bottom: .75rem; }
.chips { display: flex; gap: .5rem; overflow-x: auto; padding: .25rem 0 .75rem; scrollbar-width: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 1rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.section-title { font-size: 1.05rem; margin: 1rem 0 .6rem; color: var(--muted); font-weight: 600; }
.fav-row { display: grid; grid-auto-flow: column; grid-auto-columns: 44%; gap: .75rem; overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x mandatory; }
@media (min-width: 700px) { .fav-row { grid-auto-columns: 23%; } }
.fav-row .card { scroll-snap-align: start; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.card .photo { aspect-ratio: 4 / 3; background: var(--accent-soft); object-fit: cover; width: 100%; }
.card .photo.none { display: grid; place-items: center; color: var(--accent); font-size: 2rem; }
.card .body { padding: .6rem .75rem .75rem; display: grid; gap: .2rem; }
.card .title { font-weight: 650; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .sub { color: var(--muted); font-size: .85rem; }
.card .fav { color: var(--star); }

/* ---------- recipe page ---------- */
.hero { margin: -16px -16px 1rem; }
.hero img { width: 100%; max-height: 52vh; object-fit: cover; }
@media (min-width: 700px) { .hero { margin: 0 0 1rem; } .hero img { border-radius: var(--radius); } }
.recipe-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.recipe-head h1 { font-size: 1.65rem; padding-top: .35rem; }
.fav-toggle svg { width: 30px; height: 30px; fill: none; stroke: var(--star); stroke-width: 2; }
.fav-toggle[aria-pressed="true"] svg { fill: var(--star); }
.meta { display: flex; flex-wrap: wrap; gap: .4rem 1rem; color: var(--muted); margin: .5rem 0; }
.meta b { color: var(--text); }
.stars { display: flex; gap: .1rem; margin: .25rem 0 .5rem -.5rem; }
.stars button { width: var(--tap); height: var(--tap); border: 0; background: none; cursor: pointer; padding: 0; display: grid; place-items: center; }
.stars svg { width: 30px; height: 30px; fill: none; stroke: var(--star); stroke-width: 1.8; }
.stars button[data-on="true"] svg { fill: var(--star); }
.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.tag { background: var(--accent-soft); color: var(--accent-strong); border-radius: 999px; padding: .2rem .75rem; font-size: .9rem; font-weight: 500; text-decoration: none; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.panel h2 { font-size: 1.2rem; margin-bottom: .75rem; }
.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-list li { display: grid; grid-template-columns: 5.5rem 1fr; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--border); align-items: baseline; }
.ing-list li:first-child { border-top: 0; }
.ing-list .g { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.ing-list .orig { color: var(--text); }
.ing-list .orig small { display: block; color: var(--muted); font-size: .85rem; }
.ing-list li.heading { display: block; font-weight: 700; padding-top: 1rem; color: var(--accent-strong); }
.ing-list li.flagged .g { color: var(--flag); font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.flag-note { color: var(--flag); }
.steps { margin: 0; padding-left: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: .5rem 0 .75rem 2.75rem; line-height: 1.55; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: .45rem; width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; font-weight: 700;
}
.steps li.step-heading { counter-increment: none; padding-left: 0; font-weight: 700; color: var(--accent-strong); }
.steps li.step-heading::before { display: none; }
.notes { white-space: pre-wrap; }
.source { word-break: break-all; }

/* ---------- editor ---------- */
.issues { background: var(--flag-bg); color: var(--text); border-left: 4px solid var(--flag); border-radius: 10px; padding: .75rem 1rem; margin-bottom: 1rem; }
.issues ul { margin: .25rem 0 0; padding-left: 1.25rem; }
.preview { list-style: none; margin: .5rem 0 0; padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.preview li { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; padding: .5rem .75rem; border-top: 1px solid var(--border); background: var(--surface); }
.preview li:first-child { border-top: 0; }
.preview .pg { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.preview li.flagged { background: var(--flag-bg); }
.preview li.flagged .why { color: var(--flag); font-size: .85rem; display: block; }
.preview .manual { display: flex; align-items: center; gap: .3rem; }
.preview .manual input { width: 6rem; min-height: 40px; padding: .3rem .5rem; }
.photo-edit { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.photo-edit img { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; }
.check { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); }
.check input { width: 24px; height: 24px; accent-color: var(--accent); }

/* ---------- settings ---------- */
.seg { display: flex; flex-wrap: wrap; gap: .5rem; }
.conv-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.conv-list li { border-top: 1px solid var(--border); padding: .6rem 0; display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; }
.conv-list .vals { color: var(--muted); font-size: .9rem; }
.conv-form { display: grid; gap: .5rem; padding: .75rem; background: var(--surface-2); border-radius: 12px; margin: .5rem 0; }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 3rem auto; }
.login h1 { font-size: 1.6rem; margin-bottom: .25rem; }
.login p { color: var(--muted); margin-top: 0; }
.error { color: var(--danger); font-weight: 600; }

/* ---------- dialog & toast ---------- */
dialog { border: 0; border-radius: 18px; padding: 1.25rem; background: var(--surface); color: var(--text); max-width: min(92vw, 420px); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 5, 20, .5); }
dialog h2 { font-size: 1.2rem; margin-bottom: .5rem; }
#toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(150%);
  background: var(--text); color: var(--bg); padding: .8rem 1.2rem; border-radius: 12px; font-weight: 600;
  transition: transform .2s ease, visibility .2s; visibility: hidden; max-width: calc(100vw - 32px); z-index: 20; pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
.spinner { width: 1.1em; height: 1.1em; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
