:root {
  color-scheme: light;
  --bg: #f3efe6;
  --ink: #1c1712;
  --muted: #6f675e;
  --line: #ddd4c6;
  --card: #fffaf3;
  --tomato: #c4341d;
  --good: #1e6b43;
  --shadow: 0 16px 40px rgba(48, 28, 12, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12100e;
    --ink: #f6f1e8;
    --muted: #c4b8aa;
    --line: #3c342c;
    --card: #24201c;
    --tomato: #e15a48;
    --good: #8dcea8;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

button:disabled { opacity: 0.35; cursor: default; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.top {
  padding: calc(10px + env(safe-area-inset-top)) 16px 4px;
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.mark {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.stepper {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.round, .count {
  border: 0;
  background: transparent;
}

.round {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 32px;
  line-height: 1;
}

.count {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  min-height: 64px;
}

.count-label {
  margin: 0 0 6px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

main {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 4px 16px 12px;
}

.weigh, .shop {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plate {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px 18px 22px;
  min-height: 240px;
}

.plate-top, .plate > .eyebrow {
  display: flex;
  justify-content: space-between;
  width: 100%;
  align-items: baseline;
}

.eyebrow, .progress {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.plate[data-phase="poolish"] .eyebrow { color: var(--good); }
.plate[data-phase="sauce"] .eyebrow { color: var(--tomato); }

.amount-block {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}

.amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.num, .amount {
  font-size: clamp(72px, 22vw, 112px);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 0.9;
}

.unit {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--muted);
}

.ingredient {
  margin: 8px 0 0;
  font-size: clamp(28px, 7vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.hint, .quiet, .notice {
  color: var(--muted);
  line-height: 1.4;
}

.hint {
  margin: 10px 0 0;
  max-width: 28ch;
  font-size: 16px;
}

.quiet, .notice { margin: 0; font-size: 14px; }

.notice:empty { display: none; }

.actions {
  display: grid;
  grid-template-columns: 0.42fr 1fr;
  gap: 8px;
}

.primary, .ghost, .wide, .texty, .switch button, .presets button, .keys button {
  border-radius: 16px;
}

.primary, .ghost {
  min-height: 64px;
  font-size: 18px;
  font-weight: 700;
}

.primary, .wide {
  border: 0;
  background: var(--tomato);
  color: white;
}

.ghost, .texty, .keys button, .presets button, .switch button {
  background: transparent;
  border: 1px solid var(--line);
}

.wide {
  min-height: 56px;
  font-size: 17px;
  font-weight: 700;
}

.texty {
  min-height: 44px;
  border: 0;
  color: var(--muted);
  font-weight: 700;
}

.primary:active, .wide:active { transform: translateY(1px); }

.yeast-block { display: flex; flex-direction: column; gap: 6px; }

.switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}

.switch button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  font-weight: 700;
  color: var(--muted);
}

.switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.rows {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

.shop-row {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.shop-row:last-child { border-bottom: 0; }

.row-name { font-size: 17px; font-weight: 600; }

.amt {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.box {
  width: 28px;
  height: 28px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.shop-row[aria-pressed="true"] { color: var(--muted); }
.shop-row[aria-pressed="true"] .row-name { text-decoration: line-through; }
.shop-row[aria-pressed="true"] .box { background: var(--ink); }
.shop-row[aria-pressed="true"] .box::after {
  content: "";
  width: 12px;
  height: 7px;
  border-left: 2px solid var(--bg);
  border-bottom: 2px solid var(--bg);
  transform: rotate(-45deg) translate(0, -1px);
}

.notes { color: var(--muted); font-size: 14px; line-height: 1.45; }
.notes summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.notes p { margin: 0 0 10px; }

.nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.nav button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.nav button[aria-current="page"] {
  background: var(--ink);
  color: var(--bg);
}

dialog {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 100%;
  background: transparent;
  position: fixed;
  inset: auto 0 0 0;
}

dialog::backdrop { background: rgba(20, 16, 12, 0.48); }

.keypad-sheet {
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.keypad-display {
  margin: 0;
  text-align: center;
  font-size: 64px;
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.keypad-display.is-placeholder { opacity: 0.35; }

.presets, .keys { display: grid; gap: 8px; }
.presets { grid-template-columns: repeat(6, 1fr); }
.keys { grid-template-columns: repeat(3, 1fr); }

.presets button, .keys button {
  min-height: 48px;
  font-weight: 700;
  background: var(--bg);
}

.keys button { min-height: 56px; font-size: 24px; }

.presets button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.keypad-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.keypad-actions button { min-height: 52px; font-weight: 700; font-size: 17px; }

.boot { color: var(--muted); }

@media (min-width: 720px) {
  dialog {
    inset: 0;
    margin: auto;
    width: min(420px, calc(100% - 32px));
    height: fit-content;
  }
  .keypad-sheet { border-radius: 22px; }
  .app { max-width: 480px; margin: 0 auto; border-inline: 1px solid var(--line); }
}

@media (max-height: 520px) {
  .count { font-size: 40px; min-height: 48px; }
  .round { width: 48px; height: 48px; }
  .num, .amount { font-size: 64px; }
  .primary, .ghost, .round { min-height: 48px; }
  .plate { min-height: 0; padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .primary:active, .wide:active { transform: none; }
}
