@font-face { font-family: "Space Grotesk"; src: url(/fonts/space-grotesk.woff2) format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(/fonts/plex-mono-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(/fonts/plex-mono-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }

/* Night shop: dark, high contrast, one yellow accent. Readable with one hand under supermarket lights. */
:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-2: #2a2a2a;
  --text: #f2efe8;
  --muted: #a8a397;
  --line: #2e2e2e;
  --accent: #f5c84b;
  --accent-text: #121212;
  --ok: #8fd18f;
  --danger: #ff8a7a;
  --radius: 12px;
  --tabs-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.4 "Space Grotesk", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(var(--tabs-h) + var(--safe-b) + 96px);
  outline: none;
}
h1 { font-size: 2.1rem; line-height: 1.02; margin: 8px 0 12px; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 1.2rem; margin: 0; font-weight: 700; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--mono); font-size: 0.8rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary svg { fill: currentColor; stroke: none; width: 16px; height: 16px; }
.btn.outline { background: transparent; border: 2px solid var(--accent); color: var(--accent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.4; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; background: none; border-radius: 50%; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }

/* Bottom tabs */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: center;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 0 1 220px; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--mono); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); text-decoration: none;
}
.tabs a[aria-current="page"] { color: var(--accent); }
.badge { font-weight: 600; }
body.cooking .tabs { display: none; }

/* Shared bits */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-left: -6px; padding: 8px 6px; color: var(--muted); text-decoration: none; font-size: 1rem; min-width: 0; }
.back svg { width: 20px; height: 20px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.meta { color: var(--muted); }

/* Recipe index */
.search { position: sticky; top: 0; z-index: 5; margin: 0 -16px; padding: 8px 16px; background: var(--bg); }
.search input, .add-form input {
  width: 100%; min-height: 52px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid transparent; background: var(--surface); font-size: 1rem;
}
.search input:focus, .add-form input:focus { outline: none; border-color: var(--accent); }
input::placeholder { color: #77736a; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 4px -16px 8px; padding: 4px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: transparent;
  font-family: var(--mono); font-size: 0.75rem; font-weight: 500; text-transform: uppercase; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.cards { display: grid; gap: 8px; margin-top: 4px; }
.card { display: block; padding: 16px; border-radius: var(--radius); background: var(--surface); color: inherit; text-decoration: none; }
.card:active { background: var(--surface-2); }
.card h3 { margin: 4px 0 0; font-size: 1.3rem; line-height: 1.15; letter-spacing: -0.01em; }
.card p { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Recipe page */
.lede { color: var(--muted); margin: 0 0 8px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 24px 0 10px; }
.stepper { display: inline-flex; align-items: center; border-radius: var(--radius); background: var(--surface); }
.stepper button { width: 44px; height: 44px; border: 0; background: none; font-size: 1.4rem; color: var(--accent); }
.stepper output { min-width: 52px; text-align: center; font-size: 0.85rem; }
.ingredients, .steps, .list-items { list-style: none; margin: 0; padding: 0; }
.ingredients { display: grid; gap: 4px; }
.ingredients li { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 2px 4px 14px; border-radius: 10px; background: var(--surface); }
.ingredients li.section { min-height: 0; padding: 14px 0 4px; background: none; font-family: var(--mono); font-size: 0.75rem; text-transform: uppercase; color: var(--muted); }
.ingredients .qty { flex: none; width: 4.6rem; font-family: var(--mono); font-weight: 600; font-size: 0.9rem; color: var(--accent); }
.ing { flex: 1; min-width: 0; padding: 6px 0; border: 0; background: none; text-align: left; font-size: inherit; }
.ing .note { display: block; color: var(--muted); font-size: 0.85rem; }
.staple .ing, .staple .qty { color: var(--muted); }
.tag { margin-left: 8px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); font-family: var(--mono); font-size: 0.65rem; text-transform: uppercase; color: var(--muted); vertical-align: 2px; }
.add-one { color: var(--accent); }
.add-one.on { color: var(--ok); }
.add-all { margin: 12px 0 6px; }
.steps { display: grid; gap: 4px; }
.steps li { display: flex; gap: 14px; padding: 14px; border-radius: 10px; cursor: pointer; }
.steps .num { flex: none; color: var(--accent); padding-top: 3px; }
.steps li.done { color: var(--muted); }
.steps li.done .num { color: var(--muted); text-decoration: line-through; }
.notes { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); margin-top: 10px; }
.source { margin-top: 20px; font-size: 0.9rem; }

/* Cooking mode */
.cook { display: flex; flex-direction: column; gap: 14px; min-height: calc(100dvh - 120px); }
.progress { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.cook-step { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 24px 20px; border-radius: 18px; background: var(--accent); color: var(--accent-text); }
.cook-step .num { font-size: 0.95rem; font-weight: 600; }
.cook-step p { margin: 0; font-size: 1.65rem; line-height: 1.25; font-weight: 500; letter-spacing: -0.01em; }
.cook-ings summary { cursor: pointer; padding: 12px 0; color: var(--muted); }
.cook-ings ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cook-ings li { display: flex; gap: 12px; }
.cook-ings .qty { width: 4.6rem; flex: none; color: var(--accent); font-weight: 600; text-transform: none; }
.cook-nav { position: sticky; bottom: calc(12px + var(--safe-b)); display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.cook-nav .btn { min-height: 56px; }
body.cooking main { padding-bottom: calc(var(--safe-b) + 16px); }

/* Shopping list */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sync-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 4px; color: var(--muted); text-decoration: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.busy { background: var(--accent); }
.add-form { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; margin: 0 -16px; padding: 8px 16px; background: var(--bg); }
.add-form input { flex: 1; min-width: 0; }
.add-form button { flex: none; width: 52px; height: 52px; padding: 0; border-radius: var(--radius); border: 0; background: var(--accent); color: var(--accent-text); }
.add-form button svg { stroke-width: 2.6; }
.group-title { margin: 18px 0 6px; color: var(--muted); }
.list-items { display: grid; gap: 6px; }
.list-items li { display: flex; align-items: center; border-radius: var(--radius); background: var(--surface); }
.list-items label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; min-height: 60px; padding: 6px 0 6px 16px; cursor: pointer; }
.list-items input[type=checkbox] {
  appearance: none; -webkit-appearance: none; flex: none; width: 24px; height: 24px; margin: 0;
  border: 2px solid #5a5a5a; border-radius: 6px; display: grid; place-items: center;
}
.list-items input[type=checkbox]:checked { background: var(--ok); border-color: var(--ok); }
.list-items input[type=checkbox]:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-text); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.item-text { flex: 1; min-width: 0; }
.item-text small { display: block; color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-items .qty { flex: none; color: var(--accent); font-size: 0.85rem; text-transform: none; }
.list-items li.checked { background: transparent; border: 1px solid var(--line); }
.list-items li.checked .item-name { text-decoration: line-through; color: var(--muted); }
.list-items li.checked .qty { color: var(--muted); }
.cart-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 52px; margin: 18px 0 6px; padding: 0 16px;
  border-radius: var(--radius); border: 1px dashed #3a3a3a; background: none; color: var(--muted); font-size: 1rem;
}
.list-actions { display: flex; gap: 8px; margin-top: 24px; }
.list-actions .btn { flex: 1; background: transparent; font-weight: 500; font-size: 0.95rem; }
.btn.danger-text { color: var(--danger); }

/* Pairing */
.pair { text-align: center; }
.pair .qr { display: inline-block; padding: 10px; border-radius: var(--radius); background: #fff; margin: 8px 0; }
.pair .qr img { display: block; }
.pair .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0 16px; }
.pair p { text-align: left; }

/* Toast */
.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + var(--safe-b) + 12px);
  display: flex; align-items: center; gap: 16px; width: max-content; max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 16px; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgb(0 0 0 / .5);
}
.toast button { min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 700; }

/* Edit dialog */
dialog { width: min(420px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 18px; padding: 20px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .6); }
dialog h2 { margin: 0 0 14px; }
dialog label { display: block; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }
dialog input, dialog select { display: block; width: 100%; min-height: 46px; margin-top: 4px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 1rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.dialog-actions span { flex: 1; }
.dialog-actions button { min-height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; }
.dialog-actions button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.dialog-actions .danger { color: var(--danger); border-color: transparent; padding: 0 4px; background: none; }

@media (min-width: 900px) {
  main { padding-top: 40px; }
  h1 { font-size: 2.6rem; }
}
