@font-face {
  font-family: "Atkinson Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* ------------------------------------------------------------------ tokens */

:root {
  --milk: #EEF2F7;
  --ink: #1C2340;
  --ink-soft: #4B5371;
  --honey: #F5C04A;
  --sky: #BCE0F5;
  --night: #243063;
  --moon: #FFF0C4;
  --rain: #93D2DE;
  --cocoa: #C99E66;

  --bg: var(--milk);
  --surface: #FFFFFF;
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --line: #D3DAE6;
  --focus: var(--ink);
  --danger: #A8261D;

  --feed-bg: var(--honey);  --feed-ink: var(--ink);  --feed-dot: var(--honey);
  --day-bg: var(--sky);     --day-ink: var(--ink);   --sun: #FFD866;
  --night-bg: var(--night); --night-ink: var(--moon); --sleep-dot: var(--night);
  --wet-bg: var(--rain);    --wet-ink: var(--ink);   --wet-dot: var(--rain);
  --dirty-bg: var(--cocoa); --dirty-ink: var(--ink); --dirty-dot: var(--cocoa);

  --toast-bg: var(--ink);
  --toast-ink: #FFFFFF;
}

/* Between 20:00 and 07:00: dark and dim, so night feeds don't light up the room.
   Pure black on purpose: the pixels of an OLED screen are then off. */
html.night {
  --bg: #000000;
  --surface: #0E1120;
  --text: #C7CCDA;
  --text-soft: #7E869B;
  --line: #262C40;
  --focus: #C7CCDA;
  --danger: #E88A82;

  --feed-bg: #3A2E0C;  --feed-ink: #F2CF78;  --feed-dot: #F2CF78;
  --day-bg: #0F2B3A;   --day-ink: #A7CBE6;   --sun: #5E5228;
  --night-bg: #1A1846; --night-ink: #E8DCAA; --sleep-dot: #8E93DA;
  --wet-bg: #0E2D35;   --wet-ink: #9BD0DA;   --wet-dot: #9BD0DA;
  --dirty-bg: #2F2318; --dirty-ink: #D8B485; --dirty-dot: #D8B485;

  --toast-bg: #1B2034;
  --toast-ink: #E1E5EF;
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Atkinson Next", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  transition: background-color 600ms ease;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ------------------------------------------------------------------ setup */

.setup {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 520px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px;
}

.setup-name {
  margin: 0 0 12px;
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.setup-text {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.45;
}

/* ------------------------------------------------------------------ home */

.home {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.home-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 6px 0;
}

.home-name {
  margin: 0;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.home-clock {
  color: var(--text-soft);
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.conn {
  margin: 0 2px;
  padding: 8px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 1rem;
  line-height: 1.3;
}

/* A tile is one big button: one tap saves one thing. */
.tile {
  --tile-bg: var(--surface);
  --tile-ink: var(--text);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  width: 100%;
  margin: 0;
  padding: 18px 20px;
  border: 0;
  border-radius: 28px;
  background: var(--tile-bg);
  color: var(--tile-ink);
  text-align: left;
  transition: transform 90ms ease-out, background-color 500ms ease, color 500ms ease;
}

.tile:active { transform: scale(0.975); }

.tile-feed,
.tile-sleep {
  flex: 1 1 0;
  min-height: 136px;
}

.tile-feed { --tile-bg: var(--feed-bg); --tile-ink: var(--feed-ink); }
.tile-sleep { --tile-bg: var(--day-bg); --tile-ink: var(--day-ink); }
.tile-sleep[data-state="asleep"] { --tile-bg: var(--night-bg); --tile-ink: var(--night-ink); }

.tile-label {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1;
}

.tile-status {
  margin-top: 10px;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
}

.tile-sub {
  font-size: 1.1rem;
  line-height: 1.3;
  opacity: 0.85;
}

.tile-sub:empty { display: none; }

.tile-icon {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 60px;
  height: 60px;
}

/* The sleep tile is a small window: day sky while she's awake, night sky while she sleeps. */
.sky {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.sun {
  position: absolute;
  top: -48px;
  right: -40px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: var(--sun);
  transition: transform 600ms ease, opacity 500ms ease;
}

.moon {
  position: absolute;
  top: 20px;
  right: 40px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  box-shadow: 14px -8px 0 0 var(--night-ink);
  opacity: 0;
  transform: translateY(24px);
  transition: transform 600ms ease, opacity 500ms ease;
}

.star {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--night-ink);
  opacity: 0;
  transition: opacity 700ms ease;
}

.star:nth-child(3) { top: 26px; right: 132px; }
.star:nth-child(4) { top: 64px; right: 168px; width: 4px; height: 4px; }
.star:nth-child(5) { top: 92px; right: 26px; }
.star:nth-child(6) { top: 18px; right: 214px; width: 3px; height: 3px; }
.star:nth-child(7) { top: 108px; right: 112px; width: 4px; height: 4px; }

.tile-sleep[data-state="asleep"] .sun { opacity: 0; transform: translateY(60px); }
.tile-sleep[data-state="asleep"] .moon { opacity: 1; transform: none; }
.tile-sleep[data-state="asleep"] .star { opacity: 0.9; }

/* Shown for a moment after a tap, so nobody wonders whether it worked. */
.tile-check {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: inherit;
  color: var(--tile-ink);
  font-size: 1.6rem;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
}

.tile-check svg { width: 76px; height: 76px; }

.tile.is-saved .tile-check { animation: saved 1100ms ease-out; }

@keyframes saved {
  0%   { opacity: 0; transform: scale(0.92); }
  15%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes saved-fade {
  0%   { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

.diaper { flex: 0 0 auto; }

.diaper-title {
  margin: 4px 6px 8px;
  font-size: 1.2rem;
  font-weight: 400;
  line-height: 1.25;
}

.diaper-title strong { font-weight: 800; }

.diaper-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tile-small {
  height: clamp(104px, 15vh, 150px);
  padding: 12px 14px;
  border-radius: 22px;
}

.tile-small .tile-label { font-size: 1.75rem; }

.tile-small .tile-icon {
  top: 12px;
  right: auto;
  left: 13px;
  width: 44px;
  height: 44px;
}

.tile-small .tile-check svg { width: 56px; height: 56px; }

.tile-wet { --tile-bg: var(--wet-bg); --tile-ink: var(--wet-ink); }
.tile-dirty { --tile-bg: var(--dirty-bg); --tile-ink: var(--dirty-ink); }

.tile-both {
  --tile-ink: var(--wet-ink);
  background: linear-gradient(135deg, var(--wet-bg) 50%, var(--dirty-bg) 50%);
}

.tile-both .tile-icon { width: 62px; height: 52px; top: 8px; left: 8px; }

.log-link {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 10px 18px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: transparent;
  text-align: left;
}

.log-link-title {
  flex: 0 0 auto;
  font-size: 1.25rem;
  font-weight: 800;
}

.log-link-summary {
  color: var(--text-soft);
  font-size: 1rem;
  text-align: right;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 536px;
  min-height: 66px;
  margin: 0 auto;
  padding: 8px 8px 8px 18px;
  border-radius: 18px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  box-shadow: 0 10px 30px rgba(28, 35, 64, 0.28);
  opacity: 0;
  transform: translateY(16px);
  transition: transform 160ms ease-out, opacity 160ms ease-out;
}

.toast.is-open { opacity: 1; transform: none; }

.toast-text {
  flex: 1 1 auto;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.toast-btn {
  flex: 0 0 auto;
  min-height: 50px;
  padding: 0 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
}

.toast-undo {
  border-color: transparent;
  background: var(--toast-ink);
  color: var(--toast-bg);
}

/* ------------------------------------------------------------------ log */

.log {
  max-width: 640px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

.log-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: 0 18px 0 8px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: transparent;
  font-size: 1.15rem;
  font-weight: 700;
}

.back svg { width: 28px; height: 28px; }

.log-title {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.1;
}

.day-nav {
  display: flex;
  gap: 10px;
  margin: 18px 0 4px;
}

.day-btn {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  font-size: 1.05rem;
  font-weight: 700;
}

.day-next { margin-left: auto; }

.log-summary {
  margin: 14px 2px 12px;
  font-size: 1.2rem;
  line-height: 1.45;
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 2px solid var(--line);
}

.row {
  display: grid;
  grid-template-columns: 4.6rem 18px 1fr;
  align-items: center;
  column-gap: 12px;
  width: 100%;
  min-height: 66px;
  padding: 10px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.row-time {
  font-size: 1.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.row-time small,
.row-text small {
  display: block;
  color: var(--text-soft);
  font-weight: 400;
}

.row-time small { font-size: 0.8rem; }

.row-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dot);
}

.row-feed { --dot: var(--feed-dot); }
.row-sleep { --dot: var(--sleep-dot); }
.row-wet { --dot: var(--wet-dot); }
.row-dirty { --dot: var(--dirty-dot); }
.row-both .row-dot { background: linear-gradient(135deg, var(--wet-dot) 50%, var(--dirty-dot) 50%); }

.row-text {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
}

.row-text small { font-size: 1rem; }

.log-actions {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.add-btn {
  min-height: 60px;
  border: 2px solid var(--text);
  border-radius: 18px;
  background: transparent;
  font-size: 1.2rem;
  font-weight: 800;
}

.install-btn {
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  font-weight: 700;
}

.device-note {
  margin: 26px 0 0;
  color: var(--text-soft);
  font-size: 0.95rem;
  text-align: center;
}

/* ------------------------------------------------------------------ sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(28, 35, 64, 0.5);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-width: 640px;
  max-height: 94vh;
  max-height: 94dvh;
  margin: 0 auto;
  overflow-y: auto;
  padding: 22px 16px max(18px, env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  animation: sheet-in 200ms ease-out;
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(40px); }
}

.sheet-title {
  margin: 0 0 16px;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.15;
}

.choices {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.choices:empty { display: none; }

.choice {
  grid-column: span 2;
  min-height: 58px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: transparent;
  font-size: 1.15rem;
  font-weight: 800;
}

.choice-wide { grid-column: span 3; }

.choice[aria-pressed="true"] {
  border-color: var(--text);
  background: var(--c-bg);
  color: var(--c-ink);
}

.choice-feed { --c-bg: var(--feed-bg); --c-ink: var(--feed-ink); }
.choice-sleep { --c-bg: var(--night-bg); --c-ink: var(--night-ink); }
.choice-wet { --c-bg: var(--wet-bg); --c-ink: var(--wet-ink); }
.choice-dirty { --c-bg: var(--dirty-bg); --c-ink: var(--dirty-ink); }
.choice-both { --c-ink: var(--wet-ink); }
.choice-both[aria-pressed="true"] { background: linear-gradient(135deg, var(--wet-bg) 50%, var(--dirty-bg) 50%); }

.time-field { margin-bottom: 16px; }
.time-field:empty { display: none; }

.tf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}

.tf-label { font-size: 1.15rem; font-weight: 800; }
.tf-day { color: var(--text-soft); }

.tf-row {
  display: grid;
  grid-template-columns: 54px 54px minmax(0, 1fr) 54px 54px;
  align-items: center;
  gap: 6px;
}

.tf-btn {
  height: 56px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tf-time-wrap { position: relative; }

.tf-time {
  width: 100%;
  height: 60px;
  padding: 0 6px;
  border: 2px solid var(--text);
  border-radius: 14px;
  background: var(--bg);
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tf-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

html.night .tf-native { color-scheme: dark; }

.sheet-title:focus { outline: none; }

.still-sleeping {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 10px 10px 16px;
  border-radius: 16px;
  background: var(--bg);
}

.still-sleeping p { margin: 0; font-size: 1.15rem; font-weight: 800; }

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 6px;
}

.plain-btn {
  min-height: 56px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 700;
}

.primary-btn {
  min-height: 56px;
  border: 0;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  font-size: 1.2rem;
  font-weight: 800;
}

.delete-btn {
  display: block;
  min-height: 48px;
  margin: 14px auto 0;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------ fit */

@media (max-height: 700px) {
  .home-name { font-size: 2.1rem; }
  .home-clock { font-size: 1.25rem; }
  .tile-feed, .tile-sleep { min-height: 112px; }
  .tile-label { font-size: 2.1rem; }
  .tile-status { margin-top: 6px; font-size: 1.2rem; }
  .tile-icon { width: 48px; height: 48px; }
  .tile-small { height: 96px; }
  .tile-small .tile-label { font-size: 1.5rem; }
  .tile-small .tile-icon { width: 36px; height: 36px; }
  .log-link { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  body, .tile, .sun, .moon, .star, .toast { transition: none; }
  .sheet { animation: none; }
  .tile:active { transform: none; }
  .tile.is-saved .tile-check { animation-name: saved-fade; }
}
