:root {
  --bg: #f8f4ee;
  --surface: #ffffff;
  --surface-2: #f2ece3;
  --ink: #1f1a16;
  --ink-2: #4a423b;
  --muted: #7a6f66;
  --line: #e6ddd1;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fde8d7;
  --ok: #2f7d4f;
  --ok-soft: #dff1e5;
  --warn: #9a6400;
  --warn-soft: #fbefd2;
  --info: #2b5fa8;
  --info-soft: #e1ebf8;
  --shadow: 0 1px 2px rgb(60 40 20 / 0.06), 0 6px 20px rgb(60 40 20 / 0.06);
  --radius: 14px;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #15120f;
    --surface: #1e1a16;
    --surface-2: #27221d;
    --ink: #f3ede6;
    --ink-2: #d4cbc1;
    --muted: #a0958a;
    --line: #362f28;
    --accent: #f07a3e;
    --accent-ink: #1a0f08;
    --accent-soft: #3a2316;
    --ok: #7fd09c;
    --ok-soft: #1d3326;
    --warn: #f0c060;
    --warn-soft: #3a2f16;
    --info: #8db8f0;
    --info-soft: #1b2a40;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #15120f; --surface: #1e1a16; --surface-2: #27221d; --ink: #f3ede6; --ink-2: #d4cbc1;
  --muted: #a0958a; --line: #362f28; --accent: #f07a3e; --accent-ink: #1a0f08; --accent-soft: #3a2316;
  --ok: #7fd09c; --ok-soft: #1d3326; --warn: #f0c060; --warn-soft: #3a2f16; --info: #8db8f0; --info-soft: #1b2a40;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font-body);
  overflow-x: hidden;
}
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px max(16px, calc((100vw - 1280px) / 2));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font: 650 20px/1 var(--font-display); text-decoration: none; letter-spacing: -0.01em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8'/%3E%3C/svg%3E");
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; inset: 7px 6px 6px;
  background: var(--accent-ink);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 19'%3E%3Cpath d='M3 12c0-5 3-9 7-9s7 4 7 9z'/%3E%3Crect x='1' y='13' width='18' height='3' rx='1.5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.stats { margin: 0 auto 0 0; color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 500; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }

/* ---------- home layout ---------- */
main { padding: 24px max(16px, calc((100vw - 1280px) / 2)) 64px; outline: none; }
.intro h1 {
  margin: 8px 0 4px; font: 650 clamp(28px, 4vw, 40px)/1.1 var(--font-display); letter-spacing: -0.02em;
}
.intro p { margin: 0 0 24px; color: var(--ink-2); max-width: 60ch; }

.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; }
.filters {
  position: sticky; top: 84px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.filters summary { display: none; }
.filters h2 { font: 600 12px/1 var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 10px; }
.filters h2:first-of-type { margin-top: 4px; }
.search { position: relative; }
.search input {
  width: 100%; min-height: 40px; padding: 0 12px 0 36px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.search svg { position: absolute; left: 11px; top: 12px; width: 16px; height: 16px; stroke: var(--muted); fill: none; stroke-width: 2; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 13px;
}
.chip .count { color: var(--muted); font-size: 11px; }
.chip[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed='true'] .count { color: inherit; opacity: 0.8; }
.chip-toggle { margin-top: 8px; }
.filter-mode { display: flex; gap: 4px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.filter-mode button { flex: 1; min-height: 30px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 13px; color: var(--muted); }
.filter-mode button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.filter-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; font-size: 13px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.section-head h2 { margin: 0; font: 650 22px/1.2 var(--font-display); letter-spacing: -0.01em; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; }
.section + .section { margin-top: 40px; }

/* ---------- recipe cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--muted); }
.thumb { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .play {
  position: absolute; right: 10px; bottom: 10px; width: 34px; height: 34px; border-radius: 50%;
  background: rgb(0 0 0 / 0.6); display: grid; place-items: center;
}
.thumb .play::before { content: ''; margin-left: 3px; border-left: 11px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.thumb .badge { position: absolute; left: 10px; top: 10px; }
.card-body { padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card h3 { margin: 0; font: 600 18px/1.25 var(--font-display); letter-spacing: -0.01em; }
.card .by { font-size: 13px; color: var(--muted); }
.card .ings { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.card .ing {
  font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
}
.card .ing.hit { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.card .meta { margin-top: auto; padding-top: 8px; font-size: 12px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  background: var(--ok-soft); color: var(--ok);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.partial { background: var(--warn-soft); color: var(--warn); }
.badge.queued, .badge.analyzing { background: var(--info-soft); color: var(--info); }
.badge.analyzing::before { animation: pulse 1.4s ease-in-out infinite; }
.badge.done { background: var(--ok-soft); color: var(--ok); }
@keyframes pulse { 50% { opacity: 0.3; } }

.empty {
  padding: 40px 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}

/* ---------- queue ---------- */
.queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.q-item {
  display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 12px; align-items: center;
  padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.q-thumb { width: 72px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.q-thumb img { width: 100%; height: 100%; object-fit: cover; }
.q-title { font-weight: 600; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.q-sub { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.q-note { font-size: 12px; color: var(--ink-2); margin: 0 0 6px; }
.q-actions { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }

/* ---------- detail ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); text-decoration: none; margin-bottom: 16px; }
.back:hover { color: var(--ink); }
.detail { display: grid; grid-template-columns: minmax(260px, 360px) minmax(0, 1fr); gap: 36px; align-items: start; }
.player-col { position: sticky; top: 84px; }
.player {
  aspect-ratio: 9 / 16; width: 100%; border-radius: var(--radius); overflow: hidden;
  background: #000; box-shadow: var(--shadow);
}
.player iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-links { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 13px; }
.player-links a { color: var(--muted); }

.detail h1 { margin: 6px 0 6px; font: 650 clamp(26px, 3.4vw, 38px)/1.12 var(--font-display); letter-spacing: -0.02em; }
.detail .by { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.detail .summary { font-size: 16px; color: var(--ink-2); margin: 0 0 14px; max-width: 65ch; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); }
.facts { display: flex; flex-wrap: wrap; gap: 10px 22px; padding: 12px 0; border-block: 1px solid var(--line); margin-bottom: 24px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.facts div { display: flex; gap: 6px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.panel h2 { margin: 0; font: 650 20px/1.2 var(--font-display); }
.panel h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.panel h3:first-of-type { margin-top: 10px; }

.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-list li { border-bottom: 1px solid var(--line); }
.ing-list li:last-child { border-bottom: 0; }
.ing-list label { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 9px 0; cursor: pointer; }
.ing-list input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.ing-list .name { font-weight: 500; }
.ing-list .note { display: block; font-size: 12px; color: var(--muted); }
.ing-list .amt { text-align: right; font-size: 14px; font-weight: 600; max-width: 18ch; }
.ing-list .amt.unstated { font-weight: 400; font-style: italic; color: var(--muted); font-size: 13px; }
.ing-list input:checked ~ span .name { text-decoration: line-through; color: var(--muted); }
.basis-legend { font-size: 12px; color: var(--muted); margin: 0 0 4px; }

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; }
.steps li {
  counter-increment: step; position: relative;
  display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding: 10px 0;
}
.steps li::before {
  content: counter(step); width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px;
}
.steps p { margin: 3px 0 0; }
.ts {
  display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; padding: 1px 7px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); cursor: pointer;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; vertical-align: 1px;
}
.ts:hover { color: var(--accent); border-color: var(--accent); }
.ts::before { content: ''; border-left: 6px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent; }

.callout { border-radius: 12px; padding: 14px 16px; font-size: 14px; }
.callout + .callout { margin-top: 10px; }
.callout h3 { margin: 0 0 6px !important; color: inherit !important; }
.callout ul { margin: 0; padding-left: 18px; }
.callout li + li { margin-top: 4px; }
.callout.gaps { background: var(--warn-soft); color: var(--ink); }
.callout.gaps h3 { color: var(--warn) !important; }
.callout.notes { background: var(--surface-2); }
.nutrition { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.nutrition div { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.nutrition b { display: block; font: 650 20px/1.1 var(--font-display); }
.nutrition span { font-size: 12px; color: var(--muted); }
.source { font-size: 12px; color: var(--muted); margin-top: 18px; overflow-wrap: anywhere; }
.source code { font-size: 11px; }

/* ---------- dialog / toast ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
dialog::backdrop { background: rgb(20 12 6 / 0.45); backdrop-filter: blur(2px); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 8px; }
dialog h2 { margin: 0; font: 650 22px/1.2 var(--font-display); }
dialog p { margin: 0 0 8px; font-size: 14px; }
dialog label { font-size: 13px; font-weight: 600; margin-top: 6px; }
dialog input, dialog textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); resize: vertical;
}
.field-hint { font-size: 12px; color: var(--muted); min-height: 18px; margin: 0 !important; }
.field-hint.ok { color: var(--ok); }
.form-error { color: #c0262d; font-size: 13px; min-height: 0; margin: 0 !important; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 18px; }
  .filters { position: static; padding: 0; box-shadow: none; }
  .filters summary {
    display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
    cursor: pointer; font-weight: 600; list-style: none;
  }
  .filters summary::-webkit-details-marker { display: none; }
  .filters .filter-body { padding: 0 16px 16px; }
  .detail { grid-template-columns: 1fr; gap: 20px; }
  .player-col { position: static; max-width: 340px; width: 100%; margin: 0 auto; }
}
@media (max-width: 560px) {
  .topbar { gap: 10px; }
  .stats { display: none; }
  .brand { margin-right: auto; }
  .grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card h3 { font-size: 15px; }
  .card .ings { display: none; }
  .card-body { padding: 10px 10px 12px; }
  .panel { padding: 16px; }
  .nutrition { grid-template-columns: repeat(2, 1fr); }
  .queue { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
