:root {
  --bg: #ffffff;
  --fg: #16221f;
  --muted: #5d6d68;
  --rule: #0f6f5c;
  --rule-soft: #bcdad2;
  --accent: #0f6f5c;
  --field: #f6f9f8;
  --shadow: 0 1px 2px rgba(16, 40, 34, 0.06), 0 8px 24px rgba(16, 40, 34, 0.06);
  --radius: 10px;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614;
    --fg: #e8efec;
    --muted: #9bb0aa;
    --rule: #3f9f88;
    --rule-soft: #26443c;
    --accent: #4fbfa4;
    --field: #17211e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* Author display rules otherwise beat the UA stylesheet's [hidden] rule. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

/* ── Masthead ─────────────────────────────────────────────────────────── */

.masthead {
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px 20px 20px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 650;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

footer {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px 40px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ── Composer ─────────────────────────────────────────────────────────── */

.composer {
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: 6px 18px 18px;
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--rule-soft);
  margin: 0 -18px 18px;
  padding: 0 12px;
}

.tab {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.94rem;
  padding: 12px 12px 11px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab:hover { color: var(--fg); }

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.panel.is-hidden { display: none; }

textarea,
input[type="url"] {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--field);
  border: 1px solid var(--rule-soft);
  border-radius: 8px;
  padding: 12px 14px;
  resize: vertical;
}

textarea:focus,
input[type="url"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  background: var(--field);
  border: 1.5px dashed var(--rule-soft);
  border-radius: 8px;
  cursor: pointer;
}

.dropzone.is-over { border-color: var(--accent); color: var(--accent); }
.dropzone img { max-height: 260px; max-width: 100%; border-radius: 6px; }

.hint {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

button.primary,
button.ghost {
  font: inherit;
  font-size: 0.95rem;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  border: 1px solid var(--accent);
}

button.primary {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

button.ghost {
  background: transparent;
  color: var(--accent);
}

button.primary:hover { filter: brightness(1.08); }
button.ghost:hover { background: var(--field); }
button:disabled { opacity: 0.55; cursor: default; filter: none; }

.error {
  margin: 14px 0 0;
  padding: 11px 14px;
  border-radius: 8px;
  background: #fdeceb;
  color: #8c2b22;
  font-size: 0.92rem;
}

@media (prefers-color-scheme: dark) {
  .error { background: #3a1c19; color: #f4b8b1; }
}

/* ── Working ──────────────────────────────────────────────────────────── */

.working {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 42px 4px;
  color: var(--muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--rule-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* ── Recipe head ──────────────────────────────────────────────────────── */

.recipe-head { margin: 28px 0 4px; }

.recipe-head h1 {
  margin: 0;
  font-size: 1.65rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

.meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0 22px;
}

.toolbar button { padding: 7px 14px; font-size: 0.88rem; }

/* ── The matrix ───────────────────────────────────────────────────────── */

.matrix-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.matrix {
  border-collapse: collapse;
  width: 100%;
  min-width: 720px;
  table-layout: fixed;
}

table.matrix td,
table.matrix th {
  border: 1px solid var(--rule);
  padding: 14px 16px;
  vertical-align: middle;
  font-size: 0.95rem;
}

table.matrix th {
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  padding: 9px 12px;
}

/* Full-width prelude and coda rows. */
td.band {
  text-align: center;
  font-weight: 600;
}

/* Ingredient column. */
td.ingredient {
  width: 34%;
  text-align: left;
}

/* Action cells. */
td.step { text-align: center; }

/* Merged empty regions: keep the outer grid line, drop the inner clutter. */
td.void { border: 0; }

.matrix-wrap .scroll-hint {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ── Flow view (narrow screens) ───────────────────────────────────────── */

/* Wide screens get the grid; phones get the same flow turned vertical. Either
   one can be asked for explicitly, and the explicit choice always wins. */
.flow { display: none; }

body.view-cards .matrix-wrap { display: none; }
body.view-cards .flow { display: block; }

@media (max-width: 720px) {
  .matrix-wrap { display: none; }
  .flow { display: block; }

  body.view-grid .matrix-wrap { display: block; }
  body.view-grid .flow { display: none; }
}

.diagram {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* Ingredients entering the flow. Chips keep ten of them to three lines
   instead of ten rows, so the block reads as one thing at a glance. */
.d-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 8px;
}

/* Small and dense on purpose: a block of ten ingredients should register as
   one cluster you take in at once, not as ten lines you read. */
.d-chip {
  border: 1px solid var(--rule-soft);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.73rem;
  line-height: 1.35;
  background: var(--field);
}

/* The step being performed. */
.d-step {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--bg);
}

.d-num {
  flex: none;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.72rem;
  font-weight: 700;
}

.d-text { font-size: 0.93rem; line-height: 1.4; }

/* Connector between blocks: a line down the middle with an arrowhead. */
.d-link {
  height: 26px;
  position: relative;
}

.d-link::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 6px;
  width: 2px;
  margin-left: -1px;
  background: var(--rule);
}

.d-link::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 8px;
  height: 8px;
  margin-left: -5px;
  border-right: 2px solid var(--rule);
  border-bottom: 2px solid var(--rule);
  transform: rotate(45deg);
}

/* A merge: everything upstream gathers here. The wide bar is the visual echo
   of a wide spanning cell on the grid — the moment separate things become one.
   The stem keeps running through it, so the flow is never broken. */
.d-link.is-merge {
  height: 34px;
  background: linear-gradient(var(--rule), var(--rule)) no-repeat center top 12px / 58% 2px;
}

.d-band {
  border: 1px dashed var(--rule-soft);
  border-radius: var(--radius);
  padding: 11px 14px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
}

/* On a narrow screen the grid needs to keep its shape, so let cells stay
   readable and let the container scroll. */
@media (max-width: 720px) {
  table.matrix { min-width: 640px; }
  table.matrix td,
  table.matrix th { padding: 11px 12px; font-size: 0.9rem; }
  td.ingredient { width: 40%; }
}

/* ── Shopping + notes ─────────────────────────────────────────────────── */

.shopping,
.notes { margin-top: 40px; }

.shopping h2,
.notes h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.aisles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 22px 32px;
}

.aisle h3 {
  margin: 0 0 8px;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--rule-soft);
  padding-bottom: 5px;
}

.aisle ul { list-style: none; margin: 0; padding: 0; }

.aisle li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.94rem;
}

.aisle li input { margin: 0; accent-color: var(--accent); }
.aisle li.pantry { color: var(--muted); }
.aisle .qty { color: var(--muted); font-size: 0.88rem; }
.aisle li.checked span { text-decoration: line-through; opacity: 0.5; }

.notes ul { margin: 0; padding-left: 20px; color: var(--muted); }
.notes li { margin: 5px 0; }

.warnings {
  margin-top: 26px;
  color: var(--muted);
  font-size: 0.84rem;
}

/* ── Print ────────────────────────────────────────────────────────────── */

@media print {
  :root {
    --bg: #fff;
    --fg: #000;
    --muted: #444;
    --rule: #000;
    --rule-soft: #999;
    --accent: #000;
    --shadow: none;
  }

  body { font-size: 11pt; }
  main { max-width: none; padding: 0; }
  .no-print, footer { display: none !important; }

  .matrix-wrap { display: block !important; overflow: visible; }
  .flow { display: none !important; }
  table.matrix { min-width: 0; }
  table.matrix td, table.matrix th { padding: 7px 9px; font-size: 9.5pt; }
  table.matrix tr, .step-card, .aisle { break-inside: avoid; }
  .recipe-head { margin-top: 0; }
  .shopping { break-before: page; }
}
