/* Layout and controls follow Apple's HIG: system font, system colours, 44px targets,
   a translucent bottom sheet, segmented control and switches. */
:root {
  color-scheme: light dark;
  --green: #34c759; --yellow: #ffcc00; --red: #ff3b30;
  --done-bg: #f2f2f7; --done-fg: #000;
  --sheet-bg: rgba(242, 242, 247, 0.78); --sheet-fg: #000; --sub: rgba(60, 60, 67, 0.62);
  --group: rgba(255, 255, 255, 0.72); --sep: rgba(60, 60, 67, 0.18); --fill: rgba(120, 120, 128, 0.16);
  --seg-on: #fff; --field: rgba(255, 255, 255, 0.9); --tint: #0062cc; --tint-text: #0062cc;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sheet-h: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --green: #30d158; --yellow: #ffd60a; --red: #ff453a;
    --done-bg: #1c1c1e; --done-fg: #fff;
    --sheet-bg: rgba(28, 28, 30, 0.78); --sheet-fg: #fff; --sub: rgba(235, 235, 245, 0.62);
    --group: rgba(44, 44, 46, 0.8); --sep: rgba(84, 84, 88, 0.6); --fill: rgba(120, 120, 128, 0.36);
    --seg-on: #636366; --field: rgba(58, 58, 60, 0.9); --tint: #0071e3; --tint-text: #4da3ff;
  }
}
body { --bg: var(--green); --fg: #101010; }
body[data-light='yellow'] { --bg: var(--yellow); }
body[data-light='red'] { --bg: var(--red); }
body[data-light='done'] { --bg: var(--done-bg); --fg: var(--done-fg); }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Segoe UI', sans-serif;
  font-size: 1.0625rem; /* 17pt, the iOS body size */
  transition: background 0.5s var(--ease);
  -webkit-font-smoothing: antialiased;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- display: the stage is a size container so type scales with the space it gets ---- */
.stage {
  position: fixed; inset: 0 0 var(--sheet-h) 0; /* resize the container itself: Firefox won't re-evaluate cq units on padding changes */
  container-type: size;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2cqh; text-align: center;
}
.readout { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1cqh; }
.emoji { font-size: clamp(1.5rem, min(20cqw, 24cqh), 20rem); line-height: 1; }
.time {
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: clamp(2.5rem, min(31cqw, 42cqh), 40rem);
  font-weight: 700; line-height: 1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.label { font-size: clamp(0.9rem, min(7cqw, 9cqh), 6rem); font-weight: 600; }
@container (min-aspect-ratio: 3/2) {
  .readout { flex-direction: row; gap: 3cqw; }
  .emoji { font-size: clamp(1.5rem, min(14cqw, 40cqh), 20rem); }
  .time { font-size: clamp(2.5rem, min(22cqw, 62cqh), 40rem); }
  .label { font-size: clamp(0.9rem, min(4cqw, 9cqh), 6rem); }
}
.pizza { width: min(34cqw, 40cqh); height: min(34cqw, 40cqh); flex: none; overflow: visible; }
.slice { transition: opacity 0.4s var(--ease), transform 0.4s var(--ease); }
.slice.gone { opacity: 0; transform: scale(0.6); }
body.hide-pizza .pizza, body.hide-emoji .emoji, body[data-light='done'] .pizza { display: none; }
body.hide-time:not([data-light='done']) .time { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@container (min-aspect-ratio: 3/2) { .pizza { width: min(24cqw, 62cqh); height: min(24cqw, 62cqh); } }
@container (max-height: 160px) { .label { display: none; } }
@container (max-width: 200px) { .emoji { display: none; } }
body[data-light='done'] .emoji, body[data-light='done'] .label { display: none; }
body[data-light='done'] .time { font-size: clamp(1.5rem, min(14cqw, 22cqh), 20rem); letter-spacing: 0; }

/* ---- round control button ---- */
.fab {
  position: fixed; z-index: 3;
  top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  width: 44px; height: 44px; border: 0; border-radius: 50%; padding: 0;
  display: grid; place-items: center; cursor: pointer;
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 14%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  opacity: 0.6; transition: opacity 0.2s, transform 0.2s var(--ease);
}
.fab:hover, .fab:focus-visible { opacity: 1; }
.fab:active { transform: scale(0.94); }

/* ---- sheet ---- */
.sheet {
  position: fixed; z-index: 4; left: 50%; bottom: max(8px, env(safe-area-inset-bottom));
  width: min(calc(100% - 16px), 640px); max-height: min(85dvh, 820px, calc(100dvh - 140px)); overflow: auto;
  overscroll-behavior: contain; scroll-padding-block: 16px;
  transform: translate(-50%, calc(100% + 24px)); visibility: hidden;
  transition: transform 0.4s var(--ease), visibility 0s 0.4s;
  padding: 6px 16px calc(28px + env(safe-area-inset-bottom)); border-radius: 22px;
  background: var(--sheet-bg); color: var(--sheet-fg);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column; gap: 14px;
}
.sheet.open { transform: translate(-50%, 0); visibility: visible; transition-delay: 0s; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--sub); opacity: 0.5; margin: 4px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h1 { margin: 0; font-size: 1.375rem; font-weight: 700; }
.cap { margin: 4px 0 -6px 16px; font-size: 0.8125rem; font-weight: 400; text-transform: uppercase; color: var(--sub); letter-spacing: 0.02em; }
.keys { margin: 0 4px; font-size: 0.8125rem; color: var(--sub); }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 3px solid var(--tint); outline-offset: 2px; }
.plain { min-height: 44px; min-width: 44px; padding: 0 8px; color: var(--tint-text); font-weight: 600; border-radius: 10px; }

/* segmented control */
.seg { display: flex; padding: 2px; border-radius: 12px; background: var(--fill); gap: 2px; }
.seg button { flex: 1; min-height: 44px; border-radius: 10px; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 8px; }
.seg button::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.seg button[data-light='green'] { --c: var(--green); }
.seg button[data-light='yellow'] { --c: var(--yellow); }
.seg button[data-light='red'], .seg button[data-light='work'] { --c: var(--red); }
.seg button { font-size: 0.9375rem; line-height: 1.15; text-align: center; }
.seg button[aria-pressed='true'] { background: var(--seg-on); font-weight: 700; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); }

/* buttons */
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.filled, .tinted { min-height: 50px; padding: 0 22px; border-radius: 14px; font-weight: 600; }
.filled { flex: 2 1 140px; background: var(--tint); color: #fff; }
.tinted { flex: 1 1 90px; background: color-mix(in srgb, var(--tint) 16%, transparent); color: var(--tint-text); }
.filled:active, .tinted:active, .plain:active { opacity: 0.6; }
.stepper { flex: 1 1 100%; display: flex; border-radius: 12px; background: var(--fill); }
.stepper button { flex: 1; min-height: 44px; font-weight: 500; }
.stepper button + button { border-left: 1px solid var(--sep); }

/* grouped inset list */
.group { border-radius: 12px; background: var(--group); overflow: hidden; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 6px 16px; }
.item + .item { border-top: 1px solid var(--sep); }
.item.col { flex-direction: column; align-items: stretch; justify-content: center; gap: 4px; }
.item.col label, .item.col strong { font-size: 0.8125rem; color: var(--sub); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 22px; background: var(--fill); font-weight: 500; }
.chip[aria-pressed='true'] { background: var(--tint); color: #fff; }
input, select { min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: var(--field); }
.chips input { width: 6.5rem; }
.note { font-size: 0.8125rem; color: var(--sub); }

/* switch */
.switch { flex: none; position: relative; width: 51px; height: 31px; border-radius: 16px; background: var(--fill); transition: background 0.25s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.switch[aria-checked='true'] { background: var(--green); }
.switch[aria-checked='true']::after { transform: translateX(20px); }
.switch { margin: 6px 0; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.switch::before { content: ""; position: absolute; inset: -7px -4px; } /* 44px tap area */
.sheet > * { flex: none; } /* keep groups at full height; the sheet scrolls instead of squashing them */
/* Tiny windows: the round button would cover the digits. H still opens the controls. */
@media (max-height: 200px), (max-width: 260px) { .fab { display: none; } }
.item > span, .item label { min-width: 0; overflow-wrap: anywhere; }
.item.col > input, .item.col > select { width: 100%; }
.sheet [hidden] { display: none; }
body:has(.sheet.open) .fab { display: none; } /* Done closes the sheet; the button would cover the digits */

.foot { margin: -6px 16px 0; font-size: 0.8125rem; color: var(--sub); }
.seg.cls button::before { display: none; }
.seg.cls button { padding: 0 4px; font-size: 0.875rem; }
.pages { display: flex; align-items: center; gap: 6px; }
.pages button { min-width: 44px; min-height: 44px; border-radius: 10px; background: var(--fill); font-weight: 600; font-size: 1.25rem; }
.pages button:disabled { opacity: 0.4; cursor: default; }
.pages output { min-width: 2.5ch; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }

/* collapsible categories */
.cat { display: block; }
.cap-btn { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 44px; margin: 4px 0 -8px; padding: 0 16px; text-align: left; font-size: 0.8125rem; text-transform: uppercase; color: var(--sub); letter-spacing: 0.02em; border-radius: 10px; }
.chev { flex: none; transition: transform 0.2s var(--ease); }
.cat.closed > .group { display: none; }
.cat.closed .chev { transform: rotate(-90deg); }
.cat.closed .cap-btn { margin-bottom: 0; }
.item .note { line-height: 1.35; }

/* mascot */
.mascot { width: 40px; height: 40px; flex: none; }
.mascot.sm { width: 22px; height: 22px; vertical-align: middle; margin-right: 6px; }
.sheet-head { align-items: center; gap: 8px; }
.sheet-head h1 { flex: 1; }

/* chef: pixel mascot beside the pizza (local helper page only) */
.chef { display: none; flex-direction: column; align-items: center; gap: 1cqh; }
body.show-chef .chef { display: flex; }
body.show-chef .emoji { display: none; }
body.show-chef .readout { display: grid; grid-template-columns: auto auto; justify-content: center; align-items: center; column-gap: 3cqw; row-gap: 1cqh; }
body.show-chef .time { grid-column: 1 / -1; }
body.show-chef.hide-pizza .pizza { display: block; }
body.show-chef[data-light='done'] .pizza { display: none; }
body.show-chef .label { display: none; }
.chef-fig { position: relative; height: min(46cqw, 44cqh); aspect-ratio: 32 / 46; animation: chef-bob 6s steps(6) infinite; }
.chef-art { width: 100%; height: 100%; display: block; }
.quote { position: relative; max-width: 40cqw; min-height: 1.3em; margin-bottom: 14px; padding: 0.5em 0.8em; background: #fff; color: #1b1b1b; border: 3px solid #1b1b1b; border-radius: 14px; font-size: clamp(0.8rem, min(3.4cqw, 3.6cqh), 2rem); font-weight: 600; line-height: 1.25; }
.quote::before, .quote::after { content: ''; position: absolute; left: 50%; border-style: solid; border-color: transparent; }
.quote::before { bottom: -17px; margin-left: -11px; border-width: 14px 11px 0; border-top-color: #1b1b1b; }
.quote::after { bottom: -11px; margin-left: -8px; border-width: 11px 8px 0; border-top-color: #fff; }
body.show-chef[data-light='done'] .quote { visibility: hidden; }
@container (min-aspect-ratio: 3/2) {
  body.show-chef .readout { flex-direction: unset; }
  .chef-fig { height: min(16cqw, 30cqh); }
  .quote { max-width: 34cqw; }
  body.show-chef .time { font-size: clamp(2rem, min(16cqw, 30cqh), 40rem); }
}
@keyframes chef-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.4%); } }
@media (prefers-reduced-motion: reduce) { .chef-fig { animation: none; } }

.chef-line { max-width: 40cqw; color: #000; font-size: clamp(0.95rem, min(4.6cqw, 4.8cqh), 3rem); font-weight: 700; line-height: 1.2; text-align: center; }
body.show-chef .chef-line:empty { display: none; }
@container (min-aspect-ratio: 3/2) { .chef-line { max-width: 34cqw; font-size: clamp(0.95rem, min(2.6cqw, 5cqh), 2.2rem); } }
