/* =============================================
   Cook Planner — style.css
   Warm orange palette, mobile-first, light + dark
   following the system setting (no manual toggle).
   ============================================= */

:root {
  color-scheme: light dark;

  /* Orange is the tool's own accent; amber marks whatever is happening now. */
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-soft: #ffedd5;
  --accent-glow: rgba(234, 88, 12, 0.2);
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  /* Amber is too pale to write in on a pale amber card. */
  --amber-ink: #b45309;
  /* The solid band behind whichever stage is happening right now. */
  --now-bg: #ffe8d1;
  --now-sub: #9a3412;

  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-input: #f4f4f5;
  --bg-hover: #e4e4e7;
  --border: #d4d4d8;
  --border-light: #e4e4e7;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;

  --green: #10b981;
  --green-soft: #d1fae5;
  /* Carving and plating: the last hands-on job, and the only step that is
     neither heat nor waiting, so it gets a colour that is neither. */
  --plate: #8b5cf6;
  --plate-soft: #ede9fe;
  /* The running count. Not orange: the step's own label is orange, and a
     figure that changes under it should read as a separate thing rather than
     as part of the heading. */
  --timer: #0f766e;
  --danger: #ef4444;
  --danger-soft: #fee2e2;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 0.5rem;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --space-xl: 1.5rem;
  --space-2xl: 2rem;
  --space-3xl: 3rem;
}

/* Only the values that differ are redefined — every token above keeps its
   light value unless it appears here. */
@media (prefers-color-scheme: dark) {
  :root {
    --accent-soft: #431407;
    --accent-glow: rgba(234, 88, 12, 0.3);
    --amber-soft: #451a03;
    --amber-ink: #fbbf24;
    --now-bg: #3d1709;
    --now-sub: #fdba74;

    --bg: #0a0a0a;
    --bg-card: #171717;
    --bg-input: #171717;
    --bg-hover: #262626;
    --border: #3f3f46;
    --border-light: #262626;
    --text: #fafafa;
    --text-2: #a1a1aa;
    --text-3: #71717a;

    --green-soft: #022c22;
    --plate: #a78bfa;
    --plate-soft: #2e1065;
    --timer: #2dd4bf;
    --danger-soft: #450a0a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

/* ---- Reset ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Firefox does not hide an element whose display is overridden by flex/grid,
   so the attribute needs an explicit rule to stay reliable. */
[hidden] {
  display: none !important;
}

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

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
}

img,
svg {
  display: block;
  max-width: 100%;
}
input,
button,
textarea,
select {
  font: inherit;
}
button {
  cursor: pointer;
}

/* ---- Layout ---- */
.container {
  width: 100%;
  max-width: 44rem;
  margin-inline: auto;
  padding-inline: var(--space-lg);
}

@media (min-width: 640px) {
  .container {
    padding-inline: var(--space-xl);
  }
}

.view {
  padding-block: var(--space-xl);
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

/* ---- App Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--accent-soft);

  & h1 {
    font-family: Georgia, 'Times New Roman', Times, serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.01em;
  }

  & .header-actions {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
  }
}

@media (min-width: 640px) {
  .app-header h1 {
    font-size: 1.75rem;
  }
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.625rem var(--space-lg);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
  text-decoration: none;
  white-space: nowrap;

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  &:hover:not(:disabled) {
    background: var(--accent-hover);
  }
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  &:hover:not(:disabled) {
    background: var(--bg-hover);
  }
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  &:hover:not(:disabled) {
    background: var(--bg-input);
    color: var(--text);
  }
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  &:hover:not(:disabled) {
    background: var(--danger);
    color: #fff;
  }
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 0.875rem var(--space-xl);
  font-size: 1.125rem;
  width: 100%;
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-xs);
  border-radius: 0.25rem;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  transition:
    background 0.15s,
    color 0.15s;
  &:hover {
    background: var(--bg-hover);
    color: var(--text);
  }
}

/* ---- Form elements ---- */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--space-xs);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.form-hint {
  display: block;
  margin-top: var(--space-xs);
  font-size: 0.8125rem;
  color: var(--text-3);
}

.input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;

  &:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px
      color-mix(in srgb, var(--accent) 20%, transparent);
  }

  &::placeholder {
    color: var(--text-3);
  }
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

@media (min-width: 480px) {
  .input-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.input-time-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);

  & .input {
    flex: 1;
  }
  & .time-unit {
    font-size: 0.875rem;
    color: var(--text-2);
    white-space: nowrap;
  }
}

/* Segmented control (start/end toggle) */
.seg-control {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 2px;
  gap: 2px;

  & button {
    padding: 0.375rem 0.875rem;
    font-size: 0.875rem;
    font-weight: 500;
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    color: var(--text-2);
    cursor: pointer;
    transition:
      background 0.15s,
      color 0.15s;

    &.active {
      background: var(--accent);
      color: #fff;
    }

    &:not(.active):hover {
      background: var(--bg-hover);
      color: var(--text);
    }
  }
}

/* ---- Setup section ---- */
.setup-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 0.5rem;
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-md);

  & .setup-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-lg);
  }

  & .setup-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);

    & .form-label {
      margin-bottom: 0;
    }
  }

  & .setup-field-time {
    & .time-row {
      display: flex;
      align-items: center;
      gap: var(--space-sm);
    }
    & .input[type='time'] {
      width: 8rem;
    }
  }

  & .setup-gear {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    background: none;
    height: 2rem;
    font-size: 2rem;
    display: flex;
    align-items: end;
    line-height: 1;
    opacity: 0.35;
    padding: 0.25rem;
    transition:
      opacity 0.15s,
      transform 0.3s;
    &:hover {
      opacity: 0.75;
      transform: rotate(60deg);
    }
  }
}

/* ---- Items section ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);

  & h2 {
    font-size: 1.125rem;
    font-weight: 600;
  }
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 0.5rem;
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s;

  &:hover {
    border-color: var(--accent);
  }

  & .item-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
  }

  & .item-name {
    font-weight: 600;
    font-size: 1rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  & .item-actions {
    display: flex;
    gap: var(--space-xs);
    flex-shrink: 0;
  }

  & .item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-md);
    font-size: 0.8125rem;
    color: var(--text-2);
  }

  & .item-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-input);
    color: var(--text-2);
    border: 1px solid var(--border);
  }

  & .item-badge-type {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
  }
}

.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-lg);
  color: var(--text-3);
  background: var(--bg-input);
  border: 2px dashed var(--border);
  border-radius: 0.5rem;
  margin-bottom: var(--space-xl);

  & p {
    margin-top: var(--space-sm);
    font-size: 0.875rem;
  }
}

/* ---- Generate button footer ---- */
.input-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* ---- Schedule View ---- */
.schedule-view {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

/* Clock bar */
.clock-bar {
  background: var(--accent);
  color: #fff;
  border-radius: 0.5rem;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);

  & .clock-bar-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-md);
  }

  & .clock-next {
    flex: 1;
    min-width: 0;

    & .clock-next-label {
      opacity: 0.8;
      font-size: 0.8125rem;
      margin-bottom: 0.125rem;
    }
    & .clock-next-countdown {
      font-family: ui-monospace, monospace;
      font-size: 2.25rem;
      font-weight: 700;
      letter-spacing: -0.02em;
      line-height: 1;
      margin-bottom: 0.25rem;
    }
    & .clock-next-event {
      font-size: 0.9375rem;
      font-weight: 600;
      line-height: 1.3;
    }
    & .clock-next-event-large {
      font-size: 1.5rem;
    }
  }

  & .clock-now {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-md);
    padding-top: var(--space-sm);
    border-top: 1px solid rgba(255, 255, 255, 0.2);

    & .clock-time {
      font-size: 1.25rem;
      font-weight: 700;
      font-family: ui-monospace, monospace;
      letter-spacing: -0.02em;
      line-height: 1;
    }
    & .clock-date {
      font-size: 0.8125rem;
      opacity: 0.8;
    }
  }

  & .wake-lock-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
    flex-shrink: 0;

    &:hover {
      background: rgba(255, 255, 255, 0.3);
    }
    &.active {
      background: rgba(255, 255, 255, 0.35);
    }
  }
}

/* Notifications: in-memory chime log, manually dismissed */
.notifications {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);

  &:empty {
    display: none;
  }
}

.notification {
  --bar: 4px;
  --bar-colour: var(--text-3);
  display: flex;
  gap: var(--space-md);
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: var(--space-sm) var(--space-md) var(--space-sm) calc(var(--space-md) + var(--bar));
  box-shadow: var(--shadow-md);
  animation: notification-in 0.2s ease-out;
  /* The accent is a clipped pseudo-element rather than a border-left, which
     would curve the bar's inner edge along with its outer one and pinch it at
     the corners. overflow: hidden does the clipping, so the outer edge follows
     the radius and the inner edge stays straight. */
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--bar);
    background: var(--bar-colour);
  }

  & .notification-time {
    font-family: ui-monospace, monospace;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-2);
    flex-shrink: 0;
  }

  & .notification-content {
    flex: 1;
    min-width: 0;
  }

  & .notification-label {
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.3;
  }

  & .notification-sub {
    font-size: 0.8125rem;
    color: var(--text-2);
    margin-top: 0.125rem;
  }

  & .notification-dismiss {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-3);
    font-size: 1rem;
    line-height: 1;
    padding: 0.375rem 0.5rem;
    border-radius: 0.25rem;
    flex-shrink: 0;
    &:hover {
      background: var(--bg-input);
      color: var(--text);
    }
  }

  /* Per-type accent matches the timeline chip colours */
  &.notification-prep      { --bar-colour: var(--amber); }
  &.notification-preheat   { --bar-colour: var(--amber); }
  &.notification-cook_start { --bar-colour: var(--accent); }
  &.notification-move      { --bar-colour: var(--accent); }
  &.notification-cook_end  { --bar-colour: var(--text-3); }
  &.notification-set       { --bar-colour: #3b82f6; }
  &.notification-serve_prep { --bar-colour: var(--plate); }
  &.notification-ready     { --bar-colour: var(--green); }
  &.notification-serve     { --bar-colour: var(--amber); }
}

@keyframes notification-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Serve summary */
.serve-summary {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 0.5rem;
  padding: var(--space-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md) var(--space-xl);

  & .serve-stat {
    & .serve-stat-label {
      font-size: 0.8125rem;
      color: var(--text-2);
      margin-bottom: 0.125rem;
    }
    & .serve-stat-value {
      font-weight: 600;
      font-size: 1rem;
    }
  }
}

/* Heads-up notices. Amber rather than red: nothing is wrong with the plan,
   there is just something in it you would not have thought of. */
.notices-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.notice-card {
  background: var(--amber-soft);
  border: 1px solid var(--amber);
  border-radius: 0.375rem;
  padding: var(--space-md) var(--space-lg);
  font-size: 0.875rem;
  color: var(--amber-ink);

  & strong {
    font-weight: 600;
  }

  & .notice-detail {
    margin-top: var(--space-xs);
    color: var(--text);
    font-size: 0.8125rem;
  }
}

/* Conflict warnings */
.conflicts-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.conflict-card {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: 0.375rem;
  padding: var(--space-md) var(--space-lg);
  font-size: 0.875rem;
  color: var(--danger);

  & strong {
    font-weight: 600;
  }

  & .conflict-detail {
    margin-top: var(--space-xs);
    color: var(--text);
    font-size: 0.8125rem;
  }
}

/* Timeline */
.timeline-section {
  & h2 {
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-2);
    margin-bottom: var(--space-md);
    font-size: 0.8125rem;
  }
}

.timeline {
  display: flex;
  flex-direction: column;
  /* Stops sit apart rather than butting together: each one's highlight band is
     the full height of its row, so with no gap two lit rows meet edge to edge
     and read as one block. */
  gap: var(--space-md);
  position: relative;

  &::before {
    content: '';
    position: absolute;
    left: 3.75rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
  }
}

.tl-event {
  --bar: 4px;
  display: grid;
  grid-template-columns: 3.5rem 1.5rem 1fr;
  gap: 0 var(--space-sm);
  align-items: flex-start;
  padding-block: var(--space-sm);
  position: relative;
  isolation: isolate;

  & .tl-time {
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: ui-monospace, monospace;
    color: var(--text-2);
    text-align: right;
    padding-top: 0.125rem;
    line-height: 1.4;
  }

  /* Both labels are rendered on every stop; CSS alone decides which stop
     shows which, so the clock moves the highlight by toggling a class and
     nothing else. */
  & .tl-stage {
    display: none;
    margin-top: 0.1875rem;
    padding: 0 0.25rem;
    border-radius: 0.1875rem;
    font-family: inherit;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  & .tl-dot {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 0.25rem;
    position: relative;
    z-index: 1;

    & span {
      width: 0.75rem;
      height: 0.75rem;
      border-radius: 50%;
      background: var(--border);
      border: 2px solid var(--bg);
      flex-shrink: 0;
    }
  }

  & .tl-content {
    & .tl-sub-event {
      padding-left: var(--space-sm);
      border-left: 3px solid var(--border);
    }

    & .tl-sub-event + .tl-sub-event {
      margin-top: var(--space-sm);
      padding-top: var(--space-sm);
      border-top: 1px dashed var(--border);
    }

    /* Per-type left border colours */
    /* Heating an oven and prepping a dish are the same kind of thing -- a job
       to do before anything cooks -- so they share a colour and differ by
       their chip. */
    & .tl-type-prep,
    & .tl-type-preheat {
      border-left-color: var(--amber);
    }
    /* Moving a dish between ovens is an oven job like putting one in. */
    & .tl-type-cook_start,
    & .tl-type-move {
      border-left-color: var(--accent);
    }
    & .tl-type-cook_end {
      border-left-color: var(--text-3);
    }
    & .tl-type-set {
      border-left-color: #3b82f6;
    }
    & .tl-type-serve_prep {
      border-left-color: var(--plate);
    }
    & .tl-type-ready {
      border-left-color: var(--green);
    }

    /* The live count sits under the step's own details, where the static
       "1h 30m" it is counting towards already is. */
    & .tl-elapsed {
      display: inline-flex;
      align-items: baseline;
      gap: 0.3em;
      margin-top: var(--space-xs);
      font-size: 0.8125rem;
      color: var(--text-2);
    }

    & .tl-elapsed-value {
      font-family: ui-monospace, monospace;
      font-variant-numeric: tabular-nums;
      font-weight: 600;
      color: var(--timer);
    }

    & .tl-tracker {
      display: none;
    }

    & .tl-edit {
      display: inline-flex;
      align-items: center;
      background: transparent;
      border: 1px solid var(--border);
      border-radius: 0.25rem;
      font-size: 0.75rem;
      padding: 0.0625rem 0.375rem;
      margin-left: 0.25rem;
      cursor: pointer;
      color: var(--text-3);
      vertical-align: middle;
      &:hover {
        color: var(--text);
        border-color: var(--text-2);
      }
    }

    & .tl-sub-event.editing .tl-override {
      display: block;
    }

    & .tl-chip {
      display: inline-block;
      font-size: 0.6875rem;
      font-weight: 700;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      padding: 0.0625rem 0.375rem;
      border-radius: 0.25rem;
      margin-bottom: 0.1875rem;
      background: var(--bg-input);
      color: var(--text-3);
      border: 1px solid var(--border);
    }

    & .tl-type-prep .tl-chip,
    & .tl-type-preheat .tl-chip {
      background: var(--amber-soft);
      color: var(--amber);
      border-color: var(--amber);
    }
    & .tl-type-cook_start .tl-chip,
    & .tl-type-move .tl-chip {
      background: var(--accent-soft);
      color: var(--accent);
      border-color: var(--accent);
    }
    & .tl-type-set .tl-chip {
      background: #dbeafe;
      color: #1d4ed8;
      border-color: #3b82f6;
    }
    & .tl-type-serve_prep .tl-chip {
      background: var(--plate-soft);
      color: var(--plate);
      border-color: var(--plate);
    }
    & .tl-type-ready .tl-chip {
      background: var(--green-soft);
      color: var(--green);
      border-color: var(--green);
    }

    & .tl-label {
      font-size: 0.9375rem;
      font-weight: 500;
      line-height: 1.4;
    }
    & .tl-sub {
      font-size: 0.8125rem;
      color: var(--text-2);
      margin-top: 0.125rem;
    }
    & .tl-tray {
      font-size: 0.8125rem;
      color: var(--now-sub);
      margin-top: 0.125rem;
    }
    & .tl-override {
      display: none;
      margin-top: var(--space-sm);
      padding: var(--space-sm);
      background: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: var(--radius);

      & .tl-edit-row {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-sm);
        align-items: flex-end;
      }
      & .tl-edit-row + .tl-edit-row {
        margin-top: var(--space-sm);
        padding-top: var(--space-sm);
        border-top: 1px dashed var(--border);
      }
      & .override-name {
        flex-basis: 100%;
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-2);
      }
      & .tl-field {
        display: flex;
        flex-direction: column;
        gap: 0.125rem;
        font-size: 0.6875rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--text-3);
      }
      & .tl-field-control {
        display: flex;
        align-items: center;
        gap: 0.25rem;
      }
      & input[type='time'],
      & select {
        font-size: 0.8125rem;
        font-weight: 400;
        letter-spacing: normal;
        text-transform: none;
        padding: 0.1875rem 0.375rem;
        border: 1px solid var(--border);
        border-radius: 0.25rem;
        background: var(--bg);
        color: var(--text);
      }
      & .btn-clear-override {
        font-size: 0.75rem;
        color: var(--text-3);
        background: none;
        border: none;
        cursor: pointer;
        padding: 0.125rem;
        &:hover {
          color: var(--danger);
        }
      }
    }
  }

  /* State variants */
  &.tl-past {
    opacity: 0.45;
    & .tl-dot span {
      background: var(--green);
    }
  }

  /* Mid-cook: a dish is in the oven. Several stops are in this state at once
     for most of a roast, so it stays quiet — it is not where the cook is up to. */
  &.tl-active {
    & .tl-dot span {
      background: var(--accent);
      box-shadow: 0 0 0 4px
        color-mix(in srgb, var(--accent) 25%, transparent);
    }
    & .tl-label {
      color: var(--accent);
      font-weight: 600;
    }
  }

  /* The stage the cook is up to: one solid band running the full width of the
     page. The cook is somewhere down the timeline rather than at the top of the
     screen, so this has to be findable without reading any of the other stops.
     The band is a pseudo-element, not a background on the row, so it can bleed
     past the container's gutters without dragging the time column and dots out
     of line with every other stop. */
  &.tl-current {
    opacity: 1;   /* outranks .tl-past, which a passed stop still carries */

    &::after {
      content: '';
      position: absolute;
      inset-block: 0;
      inset-inline: calc(var(--space-lg) * -1);
      z-index: -1;
      /* The bar is painted into the background rather than drawn as a border:
         a border-left curves at both edges once the band has a radius, which
         leaves the bar pinched at top and bottom. A background is clipped to
         the curve, so the outer edge follows the corner and the inner edge
         stays straight. */
      background: linear-gradient(to right,
        var(--accent) 0 var(--bar), var(--now-bg) var(--bar));
    }
    & .tl-time {
      color: var(--text);
    }
    & .tl-stage-now {
      display: block;
      background: var(--accent);
      color: #fff;
    }
    & .tl-dot span {
      background: var(--accent);
      box-shadow: 0 0 0 4px
        color-mix(in srgb, var(--accent) 25%, transparent);
    }
    & .tl-label {
      color: var(--accent);
      font-weight: 700;
      font-size: 1rem;
    }
    & .tl-sub-event {
      border-left-color: var(--accent);
    }
    & .tl-chip {
      background: var(--accent);
      border-color: var(--accent);
      color: #fff;
    }
  }

  /* What comes next: outlined rather than filled, so there is never a question
     which of the two is happening now. */
  &.tl-next {
    &::after {
      content: '';
      position: absolute;
      inset-block: 0;
      inset-inline: calc(var(--space-lg) * -1);
      z-index: -1;
      background: linear-gradient(to right,
        color-mix(in srgb, var(--accent) 35%, transparent) 0 var(--bar),
        color-mix(in srgb, var(--now-bg) 45%, transparent) var(--bar));
    }
    & .tl-stage-next {
      display: block;
      background: transparent;
      border: 1px solid var(--accent);
      color: var(--accent);
      padding: 0 0.1875rem;
    }
  }

  &.tl-serve {
    & .tl-dot span {
      background: var(--amber);
      width: 1rem;
      height: 1rem;
    }
    & .tl-label {
      font-weight: 700;
      font-size: 1.0625rem;
    }
  }

  &.tl-conflict {
    & .tl-dot span {
      background: var(--danger);
    }
    & .tl-label {
      color: var(--danger);
    }
  }
}

/* The band bleeds by one gutter, so it reaches the screen edge on a phone.
   There it would look like a card with its corners sliced off, so the radius
   only arrives once the container has margins of its own to sit inside. */
@media (min-width: 640px) {
  .tl-event.tl-current::after,
  .tl-event.tl-next::after {
    inset-inline: calc(var(--space-xl) * -1);
    border-radius: var(--radius);
  }
}

/* The timeline and the chime log, side by side once there is room. The log
   stays put while the timeline scrolls: on a two-hour cook the point of it is
   to see what has just gone off without leaving the stage you are on. */
.schedule-main {
  display: grid;
  gap: var(--space-lg);
}

.schedule-aside {
  /* Stacked, the log belongs above the timeline — below it would be past the
     end of a two-hour cook. */
  order: -1;

  & h2 {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-2);
    margin-bottom: var(--space-md);
  }
}

.schedule-aside-empty {
  font-size: 0.8125rem;
  color: var(--text-3);
  line-height: 1.45;
}

.schedule-aside:has(.notifications:not([hidden])) .schedule-aside-empty {
  display: none;
}

/* Narrow, there is no column to fill and nothing has chimed yet, so the
   heading and its placeholder are just something else to scroll past. */
@media (max-width: 1023px) {
  .schedule-aside:not(:has(.notifications:not([hidden]))) {
    display: none;
  }
}

@media (min-width: 1024px) {
  /* The schedule view alone widens — the editor is a column of form rows and
     has nothing to do with the extra space. */
  #view-schedule .container {
    max-width: 64rem;
  }

  .schedule-main {
    grid-template-columns: minmax(0, 1fr) 17rem;
    /* The highlight band bleeds a gutter's width past the timeline's content,
       so the gap has to cover that before it starts separating the columns. */
    gap: var(--space-3xl);
    align-items: start;
  }

  .schedule-aside {
    order: 0;
    position: sticky;
    top: var(--space-lg);
    /* Its own scrollbar rather than the page's, so a long stack of chimes
       can't push the column taller than the screen. */
    max-height: calc(100dvh - var(--space-2xl));
    overflow-y: auto;
  }
}

/* Appliance summary */
.appliance-section {
  & h2 {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-2);
    margin-bottom: var(--space-md);
  }

  & .appliance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);

    @media (min-width: 480px) {
      grid-template-columns: 1fr 1fr 1fr;
    }
  }
}

.appliance-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 0.375rem;
  padding: var(--space-md);

  & .app-name {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-2);
    margin-bottom: var(--space-xs);
  }

  & .app-capacity {
    font-size: 0.8125rem;
    color: var(--text-2);
    margin-bottom: var(--space-xs);
  }

  & .slot-bar {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;

    & .slot {
      width: 1.5rem;
      height: 0.625rem;
      border-radius: 0.125rem;
      background: var(--bg-hover);
      border: 1px solid var(--border);

      &.used {
        background: var(--accent);
        border-color: var(--accent-hover);
      }
    }
  }

  & .app-items {
    margin-top: var(--space-sm);
    font-size: 0.8125rem;
    color: var(--text-2);
    display: flex;
    flex-direction: column;
    gap: 1px;
  }
}

/* Schedule footer */
.schedule-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
}

/* ---- Dialog (native <dialog>) ---- */
dialog {
  padding: 0;
  border: 1px solid var(--border-light);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--text);
  width: 32rem;
  max-width: calc(100% - 2rem);
  max-height: 90dvh;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;

  &::backdrop {
    background: rgba(0, 0, 0, 0.5);
  }
}

/* Layout only applied when open, so the UA's `dialog:not([open]) { display: none }`
   keeps the dialog hidden when closed. Explicit transform-based centring avoids
   UA-stylesheet quirks where `inset: 0 + margin: auto` can pin the dialog to a
   corner once `display: flex` is in play. */
dialog[open] {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  margin: 0;
}

/* Narrow viewport: dialog fills the screen */
@media (max-width: 639px) {
  dialog {
    inset: 0;
    margin: 0;
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  dialog[open] {
    top: 0;
    left: 0;
    translate: none;
  }
}

.dialog-header {
  background: var(--bg);
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.dialog-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.dialog-close {
  font-size: 1.5rem;
  width: 2rem;
  height: 2rem;
}

.dialog-body {
  padding: var(--space-lg);
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.dialog-footer {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
  margin-top: var(--space-lg);
}

/* ---- Cook type icons ---- */
.cook-type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);

  @media (min-width: 360px) {
    grid-template-columns: repeat(3, 1fr);
  }
}

.cook-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-md) var(--space-sm);
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-2);

  & .cook-icon {
    font-size: 1.375rem;
    line-height: 1;
  }

  &:hover {
    border-color: var(--accent);
  }

  &.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
  }
}

/* Slot picker */
/* Autocomplete follow-up: the catalogue's timings, offered or just applied. */
.food-suggest {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-sm);

  & .food-suggest-note {
    font-size: 0.75rem;
    color: var(--text-2);
  }
}

.slot-picker {
  display: flex;
  align-items: center;
  gap: var(--space-md);

  & .slot-visual {
    display: flex;
    gap: 3px;

    & .sv-slot {
      width: 1.75rem;
      height: 1.75rem;
      border-radius: 0.25rem;
      background: var(--bg-input);
      border: 2px solid var(--border);
      cursor: pointer;
      transition:
        background 0.1s,
        border-color 0.1s;

      &.filled {
        background: var(--accent);
        border-color: var(--accent-hover);
      }
    }
  }

  & .slot-label {
    font-size: 0.875rem;
    color: var(--text-2);
  }
}

/* ---- Focus states ---- */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Print ---- */
/* ---- Appliance peek ---- */
/* The appliance's name in a step, made into a handle. It has to keep reading
   as part of the sentence it sits in, so it borrows every font property from
   its surroundings and says "hover me" with a dotted rule and the cursor. */
.appl-peek {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 0.15em;
  text-decoration-thickness: 1px;

  &:hover,
  &:focus-visible {
    color: var(--accent);
    text-decoration-style: solid;
  }
}

#appliance-peek {
  /* A popover is centred by the UA, which is right for a dialog and wrong for
     a tooltip; anchor positioning hangs it off the name instead, and flips it
     when there is no room below or to the side. */
  position: fixed;
  inset: auto;
  margin: 0;
  position-anchor: --appl-peek;
  position-area: block-end span-inline-end;
  position-try-fallbacks: flip-block, flip-inline;

  width: max-content;
  max-width: min(22rem, calc(100vw - 2rem));
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  font-size: 0.8125rem;

  & .peek-head {
    display: flex;
    justify-content: space-between;
    gap: var(--space-lg);
    align-items: baseline;
    font-weight: 600;
    margin-bottom: var(--space-sm);

    & span {
      font-family: ui-monospace, monospace;
      font-weight: 500;
      color: var(--text-2);
    }
  }

  & .peek-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);

    & li {
      display: flex;
      justify-content: space-between;
      gap: var(--space-lg);
      align-items: baseline;
    }
  }

  & .peek-dish {
    font-weight: 500;
  }

  & .peek-when,
  & .peek-foot,
  & .peek-empty {
    color: var(--text-2);
  }

  & .peek-foot {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-light);
    font-size: 0.75rem;
  }
}

/* ---- Shared icons ---- */
/* Masked rather than inlined so the icon takes `currentColor` and follows the
   light/dark scheme like any other text. */
.icon-mask {
  display: inline-block;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.icon-settings {
  width: 1.25rem;
  height: 1.25rem;
  -webkit-mask-image: url(/icons/settings.svg);
  mask-image: url(/icons/settings.svg);
}

.icon-stopwatch {
  width: 1.25rem;
  height: 1.25rem;
  -webkit-mask-image: url(/icons/stopwatch.svg);
  mask-image: url(/icons/stopwatch.svg);
}

/* ---- Simulated clock ---- */
/* The pill, pinned above everything, is the only thing that says the time on
   screen is made up -- so it stays visible however far the timeline scrolls,
   and it is loud enough not to be read as part of the plan. */
.sim-bar {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: var(--space-lg);
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  max-width: calc(100vw - var(--space-lg) * 2);
  background: var(--amber);
  color: #1c1310;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  font-size: 0.8125rem;

  & button {
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    font: inherit;
    padding: var(--space-sm) var(--space-md);
    border-radius: 999px;
    &:hover { background: rgba(0, 0, 0, 0.12); }
  }

  & .sim-bar-main {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
  }

  & strong {
    font-family: ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
  }

  & .sim-bar-exit {
    font-size: 1.125rem;
    line-height: 1;
    padding-inline: var(--space-md);
  }
}

/* A running simulation gets a pulse; a paused one sits still. */
.sim-bar-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #1c1310;
  flex: none;
  animation: sim-pulse 1.6s ease-in-out infinite;
}

@keyframes sim-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  .sim-bar-dot { animation: none; }
}

/* The live clock readout is the one place a fake time could be taken for real,
   so it is tinted while the simulation is on. */
body.simulating .clock-time {
  color: var(--amber);
}

.sim-readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-md);

  & .sim-readout-time {
    font-family: ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
  }

  & .sim-readout-state {
    font-size: 0.8125rem;
    color: var(--text-2);
  }
}

.sim-range {
  width: 100%;
  accent-color: var(--accent);
}

.sim-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-3);
  font-family: ui-monospace, monospace;
  margin-bottom: var(--space-lg);
}

/* Every control row wraps rather than scrolls -- at 325px the nudge buttons
   need two lines and that is fine. */
.sim-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);

  & .btn {
    width: auto;
    flex: 1 1 auto;
    white-space: nowrap;
  }
}

/* The nudges are a set of equals, so they go in a grid rather than wrapping
   into a short second row of stretched buttons. */
.sim-nudges {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

@media (max-width: 460px) {
  .sim-nudges {
    grid-template-columns: repeat(3, 1fr);
  }
}

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


/* ---- Settings dialog ---- */
#btn-settings {
  position: relative;
}

/* A failing sync is worth seeing without opening the dialog. */
.sync-error-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--danger);
  border: 1px solid var(--bg);
}

.settings-section {
  & + & {
    margin-top: var(--space-xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border);
  }
}

.settings-heading {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  margin-bottom: var(--space-md);
}

.settings-hint {
  font-size: 0.8125rem;
  color: var(--text-2);
  line-height: 1.45;
  margin-bottom: var(--space-md);
}

@media print {
  /* The chime log is a record of a cook in progress — on paper it is a list of
     things that already happened, and an empty column beside the timeline. */
  .clock-bar .wake-lock-btn,
  .schedule-footer,
  .app-header .header-actions,
  .schedule-aside,
  .sim-bar {
    display: none !important;
  }

  .schedule-main {
    display: block;
  }

  .clock-bar {
    background: none;
    color: var(--text);
    border: 1px solid var(--border);
  }

  .clock-bar .clock-next-countdown {
    font-size: 1.5rem;
  }

  .tl-event.tl-past {
    opacity: 1;
  }

  /* A printed plan is read off the worktop over the whole cook, so "now" is
     whenever you happen to look at it — the highlight would be a lie by the
     time the ink is dry. */
  .tl-event.tl-current::after,
  .tl-event.tl-next::after,
  .tl-stage,
  .tl-elapsed,
  #appliance-peek {
    display: none !important;
  }

  /* On paper there is nothing to hover, so the handle is just a name again. */
  .appl-peek {
    text-decoration: none;
    color: inherit;
  }
}
