/* Frivy's Recipebook — warm kitchen-notebook look, light & dark. */

:root {
  --bg: #FBF6EE;
  --surface: #FFFFFF;
  --surface-2: #F3EBDF;
  --ink: #2B2118;
  --ink-2: #6E6155;
  --line: #E6DACB;
  --accent: #C2502E;
  --accent-ink: #FFFFFF;
  --accent-soft: #F7E1D7;
  --herb: #5F7234;
  --danger: #B3261E;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .07);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, ui-serif, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1512;
    --surface: #241D18;
    --surface-2: #2E2620;
    --ink: #F3EAE0;
    --ink-2: #B7A897;
    --line: #3A3029;
    --accent: #E2744F;
    --accent-ink: #1A1512;
    --accent-soft: #3D2A21;
    --herb: #A7BC72;
    --danger: #F2847B;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(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: 16px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { flex: none; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
.center { text-align: center; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h2 { font-size: 1.2rem; }
.topbar-actions { display: flex; gap: 4px; }
.brand { font-size: 1.45rem; color: var(--ink); }
.brand::first-letter { color: var(--accent); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; background: var(--surface-2); }
.icon-btn.fav-on { color: var(--accent); }

/* ---------- layout ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 8px 16px calc(110px + var(--safe-bottom)); }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.loading { display: grid; place-items: center; padding: 60px 0; grid-column: 1 / -1; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  background: var(--accent-soft); color: var(--ink); border-radius: 12px;
  padding: 10px 14px; margin: 0 0 12px; font-size: .95rem;
}
.banner.info { background: color-mix(in srgb, var(--herb) 16%, var(--surface)); }
.empty { color: var(--ink-2); text-align: center; padding: 40px 0; grid-column: 1 / -1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.big { min-height: 56px; font-size: 1.1rem; flex: 1; }
.btn:disabled { opacity: .45; cursor: default; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; }

.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-bottom)); z-index: 20;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 22px 14px 18px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 700;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ---------- home ---------- */
.search input {
  width: 100%; height: 48px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 16px; scrollbar-width: none; margin: 0 -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: .9rem; cursor: pointer; text-transform: capitalize;
}
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.static { cursor: default; background: var(--surface-2); border-color: transparent; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card {
  display: flex; flex-direction: column; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); transition: transform .15s ease;
}
.card:active { transform: scale(.98); }
.card-img { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; }
.card-img .ph { width: 100%; height: 100%; }
.card-img img.photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-fav {
  position: absolute; top: 8px; right: 8px; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%; background: var(--surface); color: var(--accent);
}
.card-body { padding: 10px 12px 12px; }
.card-body h3 { font-size: 1.02rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 6px 0 0; font-size: .82rem; color: var(--ink-2); }
.meta .dot { margin: 0 2px; }
.ph {
  display: grid; place-items: center;
  background: linear-gradient(135deg, hsl(var(--h) 55% 82%), hsl(calc(var(--h) + 25) 50% 70%));
}
.ph span { font: 600 2.6rem var(--serif); color: hsl(var(--h) 45% 30%); opacity: .75; }
@media (prefers-color-scheme: dark) {
  .ph { background: linear-gradient(135deg, hsl(var(--h) 30% 28%), hsl(calc(var(--h) + 25) 30% 20%)); }
  .ph span { color: hsl(var(--h) 50% 75%); }
}

.empty-state { grid-column: 1 / -1; text-align: center; padding: 50px 20px; }
.empty-state h2 { font-size: 1.5rem; margin-bottom: 8px; }
.empty-state p { color: var(--ink-2); max-width: 340px; margin: 0 auto 20px; }

/* ---------- recipe ---------- */
.hero { margin: 0 -16px 16px; aspect-ratio: 16 / 10; max-height: 420px; overflow: hidden; background: var(--surface-2); }
.hero img { width: 100%; height: 100%; object-fit: cover; }
@media (min-width: 700px) { .hero { margin: 8px 0 20px; border-radius: 20px; aspect-ratio: auto; height: 400px; max-height: none; } }
.recipe-head h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); }
.lead { color: var(--ink-2); margin: 8px 0 0; }
.facts { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.fact { background: var(--surface-2); border-radius: 12px; padding: 8px 14px; display: flex; flex-direction: column; }
.fact span { font-size: .75rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.fact b { font-size: .98rem; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }

.recipe-body { display: grid; gap: 16px; }
@media (min-width: 860px) {
  .recipe-body { grid-template-columns: 360px 1fr; align-items: start; }
  .ingredients-panel { position: sticky; top: 76px; }
}
.panel h2 { font-size: 1.3rem; margin-bottom: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
.stepper { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .92rem; }

.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li.section, .steps li.section {
  font: 600 1rem var(--serif); color: var(--herb); margin: 16px 0 6px; list-style: none;
}
.ingredient {
  display: flex; gap: 12px; align-items: flex-start; padding: 9px 0;
  border-bottom: 1px dashed var(--line); cursor: pointer; user-select: none;
}
.ingredient:last-child { border-bottom: 0; }
.tick {
  flex: none; width: 22px; height: 22px; margin-top: 1px; border-radius: 6px;
  border: 2px solid var(--line); display: grid; place-items: center; color: transparent;
}
.ingredient.done .tick { background: var(--herb); border-color: var(--herb); color: var(--surface); }
.ingredient.done > span:last-child { text-decoration: line-through; color: var(--ink-2); }

.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; gap: 14px; margin-bottom: 18px; }
.step .num {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .9rem;
}
.step p { margin: 3px 0 0; }
.notes { white-space: pre-wrap; color: var(--ink-2); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.danger-row { display: flex; gap: 10px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 0; border-radius: 20px; padding: 22px; width: min(480px, calc(100% - 24px));
  max-height: 85dvh; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(20, 12, 6, .45); }
dialog.sheet h2 { font-size: 1.3rem; margin-bottom: 6px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.busy { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(20, 12, 6, .35); }
.busy-card { background: var(--surface); padding: 24px 28px; border-radius: 18px; text-align: center; box-shadow: var(--shadow); max-width: 280px; }
.busy-card p { margin: 12px 0 0; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; transition: all .25s ease; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
body.cooking .toast { bottom: auto; top: calc(64px + var(--safe-top)); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-weight: 600; font-size: .9rem; }
.field small { color: var(--ink-2); font-size: .8rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none; font-size: 16px; /* 16px stops iOS zooming */
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.row2, .row4 { display: grid; gap: 0 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .row4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.form-error { color: var(--danger); font-weight: 600; }
.edit { max-width: 760px; }
.edit-img { margin: -18px -18px 16px; aspect-ratio: 16 / 7; overflow: hidden; border-radius: var(--radius) var(--radius) 0 0; }
.edit-img img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- add ---------- */
.add { max-width: 640px; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--surface-2); padding: 5px; border-radius: 16px; margin-bottom: 16px; }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--ink-2);
}
.tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.options { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 14px; }
.photo-drop {
  display: grid; place-items: center; min-height: 180px; border: 2px dashed var(--line);
  border-radius: 16px; cursor: pointer; text-align: center; overflow: hidden; color: var(--ink-2);
}
.photo-drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.photo-drop span { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px; }
.photo-drop img { max-height: 320px; border-radius: 10px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card form { text-align: left; margin-top: 20px; }
.logo {
  width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 14px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
.lang-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }

/* ---------- settings ---------- */
.settings { max-width: 560px; }
.settings h3 { font-size: 1.05rem; margin-bottom: 8px; }
.status { display: flex; align-items: center; gap: 10px; margin: 0; }
.led { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ink-2); }
.status.on .led { background: var(--herb); box-shadow: 0 0 0 4px color-mix(in srgb, var(--herb) 25%, transparent); }

/* ---------- cooking mode ---------- */
body.cooking { overflow: hidden; }
.cook { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.cook-top { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-top)) 12px 8px; }
.cook-title { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; }
.cook-title b { font-family: var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cook-title span { font-size: .85rem; color: var(--ink-2); }
.progress { height: 4px; background: var(--surface-2); }
.progress div { height: 100%; background: var(--accent); transition: width .3s ease; }
.cook-body {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; justify-content: center;
  padding: 24px clamp(20px, 6vw, 80px); max-width: 900px; width: 100%; margin: 0 auto;
}
.cook-section { color: var(--herb); font: 600 1.1rem var(--serif); margin: 0 0 10px; }
.cook-step { font-size: clamp(1.35rem, 4.2vw, 2.1rem); line-height: 1.45; margin: 0; font-family: var(--serif); }
.cook-timers { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.cook-done { text-align: center; }
.cook-done .big { width: 96px; height: 96px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; background: var(--herb); color: var(--surface); }
.cook-done h2 { font-size: 2rem; }
.timers { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; padding: 0 12px; }
.timer-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  border: 0; background: var(--ink); color: var(--bg); font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer;
}
.timer-pill.ring { background: var(--accent); color: var(--accent-ink); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.cook-nav { display: flex; gap: 12px; padding: 12px 16px calc(12px + var(--safe-bottom)); max-width: 900px; width: 100%; margin: 0 auto; }
.awake { position: absolute; top: calc(58px + var(--safe-top)); right: 14px; margin: 0; font-size: .75rem; color: var(--ink-2); display: flex; gap: 4px; align-items: center; }
.awake[hidden] { display: none; }

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

/* ---------- shopping list ---------- */
.cart-link { position: relative; }
.badge {
  position: absolute; top: 3px; right: 1px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
.badge[hidden] { display: none; }
.shopping { max-width: 640px; }
.add-item { display: flex; gap: 8px; margin: 4px 0 16px; }
.add-item input {
  flex: 1; min-width: 0; height: 48px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); outline: none; font-size: 16px;
}
.add-item input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.add-item .btn { width: 48px; height: 48px; padding: 0; }
.small-btn { min-height: 38px; padding: 6px 14px; margin-bottom: 8px; font-size: .9rem; }
.shop-group { margin-bottom: 18px; }
.shop-group h3 { font-size: 1rem; color: var(--herb); margin: 0 0 6px 4px; }
.shop-list {
  list-style: none; margin: 0; padding: 0 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.shop-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.shop-item:last-child { border-bottom: 0; }
.shop-tick {
  flex: none; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line);
  background: transparent; color: transparent; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.shop-text { flex: 1; min-width: 0; cursor: pointer; display: flex; flex-direction: column; }
.shop-text small { color: var(--ink-2); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-item.done .shop-tick { background: var(--herb); border-color: var(--herb); color: var(--surface); }
.shop-item.done .shop-text span { text-decoration: line-through; color: var(--ink-2); }
.icon-btn.ghost { background: transparent; color: var(--ink-2); }
.buy-chip {
  flex: none; min-width: 32px; height: 32px; padding: 0 12px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--accent-soft); background: var(--accent-soft); color: var(--accent);
  font: inherit; font-size: .88rem; font-weight: 600; display: inline-grid; place-items: center; cursor: pointer;
}
.buy-chip.empty { padding: 0; background: transparent; border: 1px dashed var(--line); color: var(--ink-2); }
.buy-chip.open { border-color: var(--accent); }
.buy-chip.static { cursor: default; background: var(--surface-2); border-color: transparent; color: var(--ink-2); }
.buy-editor { padding: 4px 0 14px; border-bottom: 1px dashed var(--line); display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.buy-editor:last-child { border-bottom: 0; }
.buy-row { display: flex; align-items: center; gap: 6px; }
.buy-row input {
  height: 40px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 16px; outline: none; min-width: 0;
}
.buy-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.buy-row .buy-qty { width: 64px; text-align: center; font-weight: 600; }
.buy-row .buy-unit { flex: 1; width: 0; margin-left: 4px; }
.buy-row .icon-btn.small { width: 40px; height: 40px; }
.buy-units { display: flex; flex-wrap: wrap; gap: 6px; }
.buy-units .chip { padding: 5px 12px; font-size: .88rem; text-transform: none; }
.buy-actions { display: flex; justify-content: space-between; align-items: center; }
.buy-actions .small-btn { margin: 0; }
.done-group { opacity: .85; }
.done-head { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 6px; }
.done-head h3 { margin: 0; color: var(--ink-2); }
.empty-state .icon { color: var(--ink-2); margin-bottom: 10px; }
.pick-list { list-style: none; padding: 0; margin: 8px 0 0; max-height: 50dvh; overflow-y: auto; }
.pick-list .check { margin: 0; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.pick-list li.section { font: 600 1rem var(--serif); color: var(--herb); margin: 12px 0 2px; }
