/* BotHam Cooking — cream/ink/red house style */

:root {
  --bg: #faf6ee;
  --surface: #fffcf5;
  --ink: #221a12;
  --muted: #7d7264;
  --line: rgba(34, 26, 18, 0.14);
  --red: #b23a28;
  --red-soft: rgba(178, 58, 40, 0.09);
  --shadow: 0 1px 2px rgba(34, 26, 18, 0.06), 0 6px 18px rgba(34, 26, 18, 0.05);
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Manrope', system-ui, -apple-system, sans-serif;
  --mono: 'DM Mono', ui-monospace, 'SF Mono', monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191512;
    --surface: #211c17;
    --ink: #f0e8da;
    --muted: #a3978a;
    --line: rgba(240, 232, 218, 0.16);
    --red: #e0604c;
    --red-soft: rgba(224, 96, 76, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--sat);
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.12;
  margin: 0 0 0.35em;
  text-wrap: balance;
}

h1 { font-size: 2.1rem; }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.25rem; }

a { color: var(--red); }

img { max-width: 100%; }

button { font-family: var(--sans); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--red);
  color: #fff;
  padding: 0.6rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem max(1rem, env(safe-area-inset-left)) 0.65rem max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
}

.brand {
  font-family: var(--serif);
  font-size: 1.35rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand-dot { color: var(--red); font-size: 0.8em; margin: 0 0.12em; }

.app-nav { display: flex; gap: 0.35rem; align-items: center; }

.app-nav a {
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--muted);
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
}
.app-nav a[aria-current] { color: var(--ink); background: var(--red-soft); }
.app-nav a.nav-add { color: #fff; background: var(--red); }

.nav-badge {
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  margin-left: 0.3rem;
  vertical-align: 1px;
}

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.1rem max(1rem, env(safe-area-inset-left)) calc(3.5rem + var(--sab)) max(1rem, env(safe-area-inset-right));
}
main:focus { outline: none; }

/* ---- Pills & glyphs ---- */
.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
  white-space: nowrap;
}
.pill-red { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, transparent); background: var(--red-soft); }
.pill-mute { color: var(--muted); }

.glyph-review { color: var(--red); }

.section-num {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--red);
  letter-spacing: 0.04em;
}

/* ---- Forms ---- */
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--red); outline-offset: 1px; }

label { font-size: 0.8rem; font-weight: 700; display: block; margin: 0.9rem 0 0.3rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.2rem; }

/* ---- Login ---- */
.login {
  max-width: 21rem;
  margin: 14vh auto 0;
  text-align: center;
}
.login h1 { font-size: 2.5rem; }
.login .tagline { color: var(--muted); margin-bottom: 2rem; }
.login form { text-align: left; }
.login .btn { width: 100%; margin-top: 1.2rem; }
.form-error { color: var(--red); font-size: 0.85rem; margin-top: 0.8rem; }

/* ---- Browse ---- */
.searchbar { position: relative; margin-bottom: 1rem; }
.searchbar input { padding-left: 2.3rem; border-radius: 999px; }
.searchbar::before {
  content: '⌕';
  position: absolute;
  left: 0.95rem;
  top: 50%;
  transform: translateY(-54%);
  font-size: 1.15rem;
  color: var(--muted);
}

.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list li { border-bottom: 1px solid var(--line); }
.cat-list a {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.85rem 0.15rem;
  text-decoration: none;
  color: var(--ink);
}
.cat-list .section-num { min-width: 2.4rem; }
.cat-list .cat-name { font-family: var(--serif); font-size: 1.3rem; flex: 1; }
.cat-list .cat-count { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }

.offline-note {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  margin: 0.8rem 0;
}

/* ---- Recipe cards ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.card-photo {
  aspect-ratio: 4 / 3;
  background: var(--red-soft);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.card-photo .no-photo { font-family: var(--serif); font-size: 2rem; color: var(--red); opacity: 0.45; }

.card-body { padding: 0.6rem 0.7rem 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; flex: 1; }
.card-title { font-family: var(--serif); font-size: 1.06rem; line-height: 1.2; }
.card-pills { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: auto; }

.back-link {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 0.6rem;
}

/* ---- Recipe view ---- */
.recipe-photo {
  border-radius: 16px;
  overflow: hidden;
  margin: 0.4rem 0 1rem;
  max-height: 300px;
  display: grid;
  place-items: center;
  background: var(--red-soft);
}
.recipe-photo img { width: 100%; max-height: 300px; object-fit: cover; }

.recipe-pills { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.6rem 0 1.4rem; }

.scaler {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.5rem;
  width: fit-content;
  margin: 0.6rem 0 1rem;
}
.scaler button {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
}
.scaler .scaler-value { font-family: var(--mono); font-size: 0.9rem; min-width: 6.5rem; text-align: center; }

.ing-list { list-style: none; margin: 0 0 1.6rem; padding: 0; }
.ing-list li {
  display: flex;
  gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed var(--line);
  align-items: baseline;
}
.ing-amount {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--red);
  min-width: 4.6rem;
  text-align: right;
  white-space: nowrap;
}
.ing-unscaled { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }

.step-list { list-style: none; margin: 0; padding: 0; }
.step-list li { display: flex; gap: 0.8rem; padding: 0.7rem 0; }
.step-list .section-num { padding-top: 0.2rem; min-width: 2.2rem; }

.recipe-notes {
  background: var(--red-soft);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  white-space: pre-wrap;
  margin: 1rem 0;
}

/* ---- Cook mode ---- */
.cook {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: calc(0.8rem + var(--sat)) 1.2rem calc(1rem + var(--sab));
  touch-action: pan-y;
}
.cook-top { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.cook-progress { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.cook-close {
  border: none;
  background: none;
  font-size: 1.7rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}
.cook-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  overflow-y: auto;
  max-width: 38rem;
  margin: 0 auto;
  width: 100%;
}
.cook-step-title { font-family: var(--mono); font-size: 0.85rem; color: var(--red); letter-spacing: 0.05em; }
.cook-step-body { font-size: 1.5rem; line-height: 1.5; }
@media (min-width: 640px) { .cook-step-body { font-size: 1.7rem; } }

.cook-nav { display: flex; gap: 0.6rem; max-width: 38rem; margin: 0.6rem auto 0; width: 100%; }
.cook-nav .btn { flex: 1; padding: 0.9rem; font-size: 1.05rem; }

.cook-bar { text-align: center; margin-top: 0.7rem; }

.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.18);
  max-height: 72vh;
  overflow-y: auto;
  padding: 0.9rem 1.3rem calc(1.2rem + var(--sab));
  z-index: 60;
  transform: translateY(105%);
  transition: transform 0.25s ease;
}
.drawer.open { transform: translateY(0); }
.drawer h3 { margin-top: 0.4rem; }
.drawer-handle {
  width: 2.6rem; height: 0.3rem;
  background: var(--line);
  border-radius: 99px;
  margin: 0 auto 0.5rem;
}

/* ---- Edit form ---- */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.8rem; }

.ing-editor, .step-editor { display: flex; flex-direction: column; gap: 0.45rem; }
.ing-row { display: flex; gap: 0.4rem; align-items: center; }
.ing-row input { flex: 1; }
.row-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.3rem;
}
.parse-preview {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  padding-left: 0.4rem;
  margin-top: -0.2rem;
}
.parse-preview .ok { color: var(--red); }
.step-row { display: flex; gap: 0.4rem; align-items: flex-start; }
.step-row textarea { flex: 1; min-height: 4.2rem; }
.add-row { align-self: flex-start; margin-top: 0.2rem; }

.photo-preview { max-width: 12rem; border-radius: 12px; display: block; margin-top: 0.5rem; }

.import-box {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem 1rem;
  margin-bottom: 1.4rem;
}
.import-box .hint { font-size: 0.78rem; color: var(--muted); margin: 0.1rem 0 0.5rem; }
.import-row { display: flex; gap: 0.5rem; }
.import-row input { flex: 1; }

.checkbox-row { display: flex; align-items: center; gap: 0.55rem; margin-top: 1rem; }
.checkbox-row input { width: 1.15rem; height: 1.15rem; }
.checkbox-row label { margin: 0; }

/* ---- Review queue ---- */
.review-list { list-style: none; padding: 0; margin: 1rem 0; }
.review-list li { border-bottom: 1px solid var(--line); }
.review-list a {
  display: block;
  padding: 0.75rem 0.1rem;
  text-decoration: none;
  color: var(--ink);
}
.review-list .why {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  display: block;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Toast & misc ---- */
.toast {
  position: fixed;
  bottom: calc(1.2rem + var(--sab));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 80;
  max-width: 90vw;
}

.empty-note { color: var(--muted); text-align: center; margin: 3rem 0; }

.ios-hint {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1.1rem;
  font-size: 0.85rem;
  margin-top: 2rem;
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
}
.ios-hint button { margin-left: auto; }

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