/* Colour lives here, not in the state machine (docs/state-machine.md section 3).
   Each state swaps a small set of tokens; nothing else in the sheet knows the
   difference between "normal" and "over six hours".

   The ramp is deliberate: neutral, then green when the feed is due, then amber,
   then red. Green reads as "go" rather than as an alarm, which is what the Feed
   due state means — the feed is wanted, nothing is wrong.

   Dark by preference, because the design constraint is a parent at 3am (§1) and
   a white screen at that hour is its own small cruelty. */

:root {
  --bg: #ececeb;
  --card: #ffffff;
  --ink: #16181d;
  --ink-soft: #6b7280;
  --line: #e3e3e1;

  --accent: #2f56d9;
  --accent-ink: #ffffff;
  --panel: transparent;
  --panel-ink: var(--ink);

  --radius: 22px;
  --tap: 60px;
}

/* Feed due — the state docs/state-machine.md added, and the one a parent with a
   sub-4h gap sees most often. */
.state-feed_due {
  --accent: #0e7c66;
  --panel: #daf2ec;
  --panel-ink: #0b5748;
}

/* Spec §3.6, both variants. The colour is the same; only the wording differs. */
.state-warn_early,
.state-warn_overdue {
  --accent: #b26a00;
  --panel: #fbeed2;
  --panel-ink: #6b3f00;
}

/* Spec §3.7. Colour and wording only — no instruction, no escalation. */
.state-alert {
  --accent: #b32020;
  --panel: #fadedd;
  --panel-ink: #7a1414;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --card: #16191f;
    --ink: #f2f4f7;
    --ink-soft: #9aa3af;
    --line: #262b33;
    --accent: #5b7cf5;
  }
  .state-feed_due {
    --accent: #2fb69a;
    --panel: #10312b;
    --panel-ink: #8fe0cd;
  }
  .state-warn_early,
  .state-warn_overdue {
    --accent: #d99320;
    --panel: #3a2a0c;
    --panel-ink: #f6d79a;
  }
  .state-alert {
    --accent: #e05252;
    --panel: #3d1414;
    --panel-ink: #ffbdbd;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: block;
  max-width: 460px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
}

section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

p {
  margin: 0;
}

.sub {
  color: var(--ink-soft);
  font-size: 15px;
}

.footnote {
  font-size: 14px;
}

.day {
  color: var(--ink-soft);
  font-size: 15px;
}

/* The largest element on the screen, in every state (§1). */
.elapsed {
  font-size: clamp(40px, 13vw, 56px);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.banner {
  background: var(--panel);
  color: var(--panel-ink);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.banner .sub {
  color: inherit;
  opacity: 0.75;
}

.banner-title {
  font-weight: 700;
  font-size: 18px;
}

.lede {
  font-size: 26px;
  font-weight: 700;
}

.next .due {
  font-size: 26px;
  font-weight: 700;
}

.next .in {
  font-size: 17px;
  font-weight: 400;
  color: var(--ink-soft);
}

.bar {
  height: 8px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
  margin-top: 6px;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.detail {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

/* Two equal buttons, no pre-selected side: the app does not guess (§3.3). */
.sides {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

button {
  font: inherit;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 14px;
  min-height: var(--tap);
  cursor: pointer;
}

.start,
.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 700;
  font-size: 20px;
  min-height: var(--tap);
}

.secondary {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 12px;
}

.secondary-btn {
  min-height: 52px;
}

.bar-top {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  color: var(--ink-soft);
  font-size: 16px;
  text-align: center;
}

.bar-top .back,
.bar-top .link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 8px;
  min-height: 44px;
  font-size: 17px;
}

.bar-top .back {
  font-size: 28px;
  line-height: 1;
  text-align: left;
}

.stopwatch {
  font-size: clamp(52px, 18vw, 76px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: -0.02em;
}

.feeding .sub,
.burp .sub {
  text-align: center;
}

.chip {
  border-radius: 14px;
  padding: 14px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.chip-active {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--panel-ink);
  font-weight: 700;
}

.state-normal .chip-active,
.addpast .chip-active,
.history .chip-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

/* Paused, tapping a side is what resumes the feed, so both sides take the
   filled treatment the home screen gives Left and Right — it means the same
   thing there. Specificity is deliberate: .chip.chip-resume outranks
   .chip-active, so it does not matter which rule the cascade meets first. */
.chip.chip-resume {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 700;
}

/* Both sides are filled now, so the one that was in progress keeps a ring —
   otherwise the screen stops saying which breast the baby was on. */
.chip.chip-resume.chip-active {
  box-shadow: inset 0 0 0 2px var(--accent-ink);
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choices .chip {
  flex: 1 1 auto;
  min-width: 88px;
  min-height: 52px;
}

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

.nudge {
  min-height: 44px;
  padding: 8px 12px;
  font-size: 15px;
}

.danger {
  color: #b32020;
  border-color: currentColor;
}

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

.entry-main {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  text-align: left;
  min-height: 52px;
}

.entry-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.entry-detail {
  color: var(--ink-soft);
  font-size: 15px;
}

.day-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.day-head {
  font-weight: 600;
}

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

select {
  font: inherit;
  padding: 14px;
  min-height: 56px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
}

.toggle input {
  width: 52px;
  height: 32px;
  accent-color: var(--accent);
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 8px 0;
  width: 100%;
}

.gear {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 10px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  z-index: 2;
}

.gear svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Home is the only screen without its own top bar. Everywhere else the gear is
   fixed over whatever sits top-right — on the feeding screen it lands squarely
   on "Edit" — and those screens all have a back button to leave by. */
body:not([data-route='home']) .gear {
  display: none;
}

/* --- first launch and sharing ------------------------------------------- */

.title {
  font-size: 34px;
  font-weight: 750;
  letter-spacing: -0.02em;
  text-align: center;
  margin: 8px 0 0;
}

.centred {
  text-align: center;
}

/* A rule either side of the word, so "or" reads as a choice between the two
   paths rather than as a heading for what follows. */
.or {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.or::before,
.or::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--line);
}

.code-input,
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 17px;
  letter-spacing: 0.01em;
}

.code-input {
  width: 100%;
  padding: 16px;
  min-height: 56px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.code-input::placeholder {
  color: var(--ink-soft);
  opacity: 0.7;
}

/* The one thing on the screen that gets read out loud, so it is set apart and
   allowed to wrap rather than being truncated into something unsayable. */
.code {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  font-weight: 700;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  overflow-wrap: anywhere;
}

.problem {
  color: #b32020;
}

.sharing {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.device {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

button:disabled {
  opacity: 0.55;
}

/* Keyboard focus has to be visible: these are large tap targets, but the app is
   also used on a laptop while one hand is otherwise occupied. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* db.js fell back to memory. Above the card rather than inside it, so no screen
   has to know, and plain rather than alarming: nothing has gone wrong yet. */
.storage-warning {
  max-width: 460px;
  margin: 0 auto 12px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #fbeed2;
  color: #6b3f00;
  font-size: 15px;
}

.storage-warning[hidden] {
  display: none;
}
