:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --surface-2: #f0ebe4;
  --text: #2a241e;
  --muted: #7a6f64;
  --line: #e4dcd2;
  --accent: #d9622b;
  --accent-ink: #ffffff;
  --accent-soft: #fbe6da;
  --ok: #2f8a57;
  --warn: #b7791f;
  --err: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 4px 16px rgb(60 40 20 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --surface: #25221e;
    --surface-2: #2f2b26;
    --text: #f1ebe3;
    --muted: #a99d90;
    --line: #3a352f;
    --accent: #f07a41;
    --accent-ink: #1b1916;
    --accent-soft: #43291c;
    --ok: #5cc28a;
    --warn: #e0a84a;
    --err: #ef6b5b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; }

button, input, textarea, select { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  margin-right: auto;
}

.brand::before { content: "🍳 "; }

.language-select {
  min-height: 36px;
  max-width: 125px;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: .85rem;
  cursor: pointer;
}

.language-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.translation-note { padding: 12px; border-radius: 10px; background: var(--accent-soft); }

@media (max-width: 420px) {
  .topbar { flex-wrap: wrap; gap: 6px; padding-inline: 12px; }
  .brand { font-size: 1rem; }
  .jobs-pill { order: 4; }
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px;
}

/* --- controls --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .92rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.block { width: 100%; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.2rem;
}

.field {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.field:focus, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

textarea.field { min-height: 180px; resize: vertical; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: .88rem;
  cursor: pointer;
  text-decoration: none;
}

.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.muted { color: var(--muted); }
.small-text { font-size: .88rem; }

/* --- list --- */

.search-row { display: flex; gap: 8px; margin-bottom: 10px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 8px;
}

.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);
}

.card .thumb {
  aspect-ratio: 16 / 9;
  background: var(--surface-2) center / cover no-repeat;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
}

.card .body { padding: 12px 14px 14px; }
.card h3 { margin: 0 0 4px; font-size: 1.02rem; line-height: 1.35; }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .84rem; color: var(--muted); }

.filter-note { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; font-weight: 600; }

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.empty .big { font-size: 3rem; }

/* --- add / jobs --- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel h2 { margin: 0 0 4px; font-size: 1.2rem; }
.panel + .panel, .panel + h2, .section-title { margin-top: 20px; }
.stack { display: grid; gap: 10px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; margin: 10px 0; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.jobs { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }

.job {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.job .src { font-weight: 600; word-break: break-all; line-height: 1.35; }
.job .msg { font-size: .86rem; color: var(--muted); margin-top: 2px; }
.job .msg.err { color: var(--err); }
.job .acts { display: flex; gap: 6px; }

.badge {
  display: inline-block;
  font-size: .76rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}

.badge.queued { color: var(--muted); }
.badge.fetching, .badge.extracting { color: var(--warn); }
.badge.done { color: var(--ok); }
.badge.failed { color: var(--err); }

.spin { display: inline-block; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.jobs-pill {
  font-size: .82rem;
  font-weight: 700;
  color: var(--warn);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}

/* --- detail --- */

.hero { border-radius: var(--radius); overflow: hidden; background: var(--surface-2); margin-bottom: 14px; }
.hero img { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.video { position: relative; aspect-ratio: 16 / 9; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.title-row { display: flex; gap: 10px; align-items: flex-start; }
.title-row h1 { margin: 0; font-size: 1.55rem; line-height: 1.3; flex: 1; }

.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.fact {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: .9rem;
}

.fact b { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; }

.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 700; }
.stepper output { min-width: 3.2em; text-align: center; font-weight: 700; }

/* Mobile: the start button is a fixed bottom bar so it never covers the ingredient list. */
.cta {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.cta .btn { width: 100%; min-height: 54px; font-size: 1.08rem; box-shadow: 0 6px 20px rgb(217 98 43 / 30%); }

body.detail main { padding-bottom: 96px; }
body.detail .timer-dock { bottom: calc(84px + env(safe-area-inset-bottom)); }

.section-title { display: flex; align-items: baseline; gap: 8px; font-size: 1.15rem; margin-bottom: 8px; }
.section-title small { font-weight: 400; color: var(--muted); font-size: .85rem; }

.ing-group { margin: 12px 0 4px; font-size: .85rem; font-weight: 700; color: var(--accent); }

.ingredients { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ingredients li + li { border-top: 1px solid var(--line); }

.ingredients label {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px 14px;
  cursor: pointer;
}

.ingredients input { width: 20px; height: 20px; accent-color: var(--accent); }
.ingredients .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.ingredients .note { display: block; font-size: .82rem; color: var(--muted); }
.ingredients input:checked ~ span { opacity: .45; text-decoration: line-through; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.step .num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.step h4 { margin: 4px 0 2px; font-size: 1rem; }
.step p { margin: 4px 0; }
.step .tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.step .used { font-size: .86rem; color: var(--muted); }

.tip { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: .9rem; }
.tip::before { content: "💡 "; }

.tips { padding-left: 1.2em; }

.source-box { margin: 24px 0 80px; font-size: .88rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }

/* --- cook mode --- */

.cook {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

.cook-head { display: flex; align-items: center; gap: 10px; }
.cook-head .t { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); margin: 12px 0; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .25s; }

.cook-body { flex: 1; overflow-y: auto; max-width: 720px; width: 100%; margin: 0 auto; padding: 8px 2px 16px; }
.cook-body .count { color: var(--accent); font-weight: 800; letter-spacing: .02em; }
.cook-body h2 { margin: 4px 0 10px; font-size: 1.4rem; }
.cook-body .instruction { font-size: clamp(1.25rem, 4.6vw, 1.7rem); line-height: 1.6; margin: 0 0 16px; }
.cook-body .need { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.cook-body .need li { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .95rem; }
.cook-body .need b { color: var(--accent); margin-left: 4px; }
.cook-body .tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

.cook-nav { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; max-width: 720px; width: 100%; margin: 0 auto; }
.cook-nav .btn { min-height: 56px; font-size: 1.05rem; }

.finish { text-align: center; padding-top: 12vh; }
.finish .big { font-size: 4rem; }

.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 40%); z-index: 40; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-height: 75vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
}

/* --- timers --- */

.timer-dock {
  position: fixed;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

body.cooking .timer-dock { bottom: calc(86px + env(safe-area-inset-bottom)); }

.timer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
}

.timer.done { background: var(--accent); color: var(--accent-ink); animation: pulse 1s ease-in-out infinite; }
.timer button { border: 0; border-radius: 999px; background: rgb(255 255 255 / 18%); color: inherit; min-width: 32px; height: 32px; cursor: pointer; font-weight: 700; }
.timer .label { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; opacity: .85; font-size: .85rem; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  max-width: calc(100vw - 32px);
}

@media (min-width: 720px) {
  .detail-cols { display: grid; grid-template-columns: minmax(260px, 1fr) 1.6fr; gap: 24px; align-items: start; }
  .cta { position: static; padding: 0; margin: 4px 0 18px; background: none; }
  body.detail main { padding-bottom: 24px; }
  body.detail .timer-dock { bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- tablet & desktop --- */

@media (min-width: 720px) {
  main { padding: 24px; }
  .title-row h1 { font-size: 1.9rem; }
  .quick-add .search-row .field { font-size: 1.02rem; }
  .cook { padding-left: 32px; padding-right: 32px; }
  .cook-body .instruction { font-size: 1.75rem; }
}

@media (min-width: 1024px) {
  main { max-width: 1120px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
  .hero { max-width: 860px; }
  .add-layout { display: grid; grid-template-columns: minmax(360px, 1fr) 1.2fr; gap: 24px; align-items: start; }
  .add-layout .section-title { margin-top: 0; }
  .cook-body, .cook-nav { max-width: 860px; }
  .cook-body .instruction { font-size: 2rem; }
}

@media (hover: hover) {
  .card { transition: transform .15s, box-shadow .15s; }
  .card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgb(60 40 20 / 12%); }
  .chip:hover, .btn:not(.primary):not(:disabled):hover { background: var(--surface-2); }
}

body.cooking .toast { bottom: auto; top: calc(72px + env(safe-area-inset-top)); }
