/* Recipe diagrams — mobile-first, respects prefers-color-scheme. */

:root {
  --bg: #f2f2f7;
  --fg: #1c1c1e;
  --muted: #636366;
  --card: #ffffff;
  --border: #c6c6c8;
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.1);
  --checked-fg: #8e8e93;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --fg: #f2f2f7;
    --muted: #98989d;
    --card: #1c1c1e;
    --border: #48484a;
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.16);
    --checked-fg: #636366;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

h1 {
  font-size: 1.6rem;
  margin: 0.4em 0 0.2em;
}

h2 {
  font-size: 1.15rem;
  margin: 1.6em 0 0.5em;
}

.lede,
.hint {
  color: var(--muted);
  margin: 0.2em 0 1em;
}

.hint {
  font-size: 0.9rem;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
}

.back-link:hover {
  text-decoration: underline;
}

.source {
  margin: 0.2em 0 0;
  color: var(--muted);
}

.provenance {
  margin: 0.35em 0 0;
  color: var(--muted);
  font-size: 0.95em;
}

.source a {
  color: var(--accent);
}

/* ---- Controls: stepper, servings, progress ---- */

.controls {
  margin-top: 1em;
  display: flex;
  flex-direction: column;
  gap: 0.8em;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stepper-label {
  color: var(--muted);
  font-size: 0.95rem;
}

.mult-btn,
.mult-custom,
.reset-btn {
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 0 16px;
  font-size: 1rem;
  cursor: pointer;
}

.mult-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.mult-custom {
  width: 84px;
  border-radius: var(--radius);
  text-align: center;
}

.servings {
  margin: 0;
  font-weight: 600;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-text {
  font-size: 0.95rem;
  color: var(--muted);
  white-space: nowrap;
}

.progress-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.reset-btn {
  border-radius: var(--radius);
}

/* ---- Setup checklist ---- */

.setup-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setup-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

.setup-item .box {
  flex: none;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 0.9rem;
}

.setup-item.checked .box {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.setup-item.checked .setup-text {
  text-decoration: line-through;
  color: var(--checked-fg);
}

/* ---- Diagram table ---- */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

table.diagram {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 620px; /* forces horizontal scroll on phones */
}

.diagram th,
.diagram td {
  border-bottom: 2px solid var(--border);
  border-right: 2px solid var(--border);
  padding: 0;
  vertical-align: top;
}

.diagram thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--card);
}

.diagram tbody tr:last-child th,
.diagram tbody tr:last-child td {
  border-bottom: none;
}

.diagram tr > *:last-child {
  border-right: none;
}

/* Sticky ingredient column */
.diagram .col-ingredient,
.diagram td.ingredient {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
  min-width: 170px;
  max-width: 240px;
}

.ingredient-btn {
  width: 100%;
  min-height: 64px;
  display: block;
  padding: 10px 12px;
  border: none;
  background: none;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  font-size: 1rem;
}

.ingredient-btn.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.ing-name {
  font-weight: 600;
}

.ing-qty {
  color: var(--accent);
  font-weight: 600;
  margin-top: 2px;
}

.qty-note {
  display: block;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
}

.ing-prep {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}

td.stage {
  min-width: 150px;
}

/* Action cells: full-cell tap targets (height is set from JS to fill rowspan cells) */
.action {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 12px;
  border: none;
  background: var(--accent-soft);
  color: var(--fg);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  border-radius: 0;
}

.action + .action {
  border-top: 1px solid var(--border);
}

.action.checked {
  opacity: 0.55;
}

.action.checked .action-label {
  text-decoration: line-through;
  color: var(--checked-fg);
}

/* Highlighted when their ingredient row is tapped: the whole cell fills,
   not just the button, so the highlight can never fall short of the cell */
td.stage.cell-consumes {
  background: var(--accent);
}
td.stage.cell-consumes .action {
  background: transparent;
  color: #fff;
  box-shadow: none;
}

/* ---- Notes / index / errors ---- */

.notes-list {
  margin: 0;
  padding-left: 1.2em;
  color: var(--muted);
}

.notes-list li {
  margin-bottom: 0.4em;
}

.recipe-list {
  list-style: none;
  margin: 1.5em 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recipe-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  text-decoration: none;
  font-size: 1.05rem;
}

.recipe-card:hover {
  border-color: var(--accent);
}

.recipe-card-go {
  color: var(--accent);
  font-size: 1.3rem;
}

.loading,
.empty {
  color: var(--muted);
  padding: 2em 0;
}

.error {
  padding: 3em 0;
  text-align: center;
}

.error p {
  color: var(--muted);
}

@media (min-width: 720px) {
  h1 {
    font-size: 2rem;
  }

  .controls {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  table.diagram {
    min-width: 0; /* fits naturally on desktop */
  }
}
