@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f4ebdd;
  --card: #fffaf1;
  --ink: #352a21;
  --sub: #7d6c5c;
  --line: rgba(53, 42, 33, 0.09);
  --line2: rgba(53, 42, 33, 0.17);
  --sleep: #75638f;
  --sleepT: #ece5f1;
  --accent: #b96543;
  --accentT: #f8e3d6;
  --gold: #c0932f;
  --ok: #6f9a5a;
  --milk: #fffdf7;
  --onc: #fffaf1;
  --danger: #b23b2e;
  --hatch: rgba(117, 99, 143, 0.65);
  --goldInk: #8a6516;
  --shadow: 0 1px 3px rgba(53, 42, 33, 0.05), 0 6px 18px rgba(53, 42, 33, 0.05);
  --scrim: rgba(40, 28, 16, 0.42);
  --serif: "Fraunces", Georgia, serif;
}

html[data-theme="night"] {
  color-scheme: dark;
  --bg: #1d1611;
  --card: #281f18;
  --ink: #f1e6d6;
  --sub: #b09a85;
  --line: rgba(241, 230, 214, 0.08);
  --line2: rgba(241, 230, 214, 0.16);
  --sleep: #a594c6;
  --sleepT: #312a3d;
  --accent: #dc8661;
  --accentT: #3a261c;
  --gold: #d9b35c;
  --milk: #f5ecdc;
  --onc: #1d1611;
  --danger: #e07366;
  --hatch: rgba(165, 148, 198, 0.7);
  --goldInk: #e3c47a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --scrim: rgba(8, 5, 3, 0.62);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    color-scheme: dark;
    --bg: #1d1611;
    --card: #281f18;
    --ink: #f1e6d6;
    --sub: #b09a85;
    --line: rgba(241, 230, 214, 0.08);
    --line2: rgba(241, 230, 214, 0.16);
    --sleep: #a594c6;
    --sleepT: #312a3d;
    --accent: #dc8661;
    --accentT: #3a261c;
    --gold: #d9b35c;
    --milk: #f5ecdc;
    --onc: #1d1611;
    --danger: #e07366;
    --hatch: rgba(165, 148, 198, 0.7);
    --goldInk: #e3c47a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --scrim: rgba(8, 5, 3, 0.62);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, -apple-system, "SF Pro Rounded", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
h1, h2, p { margin: 0; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.shell {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) 18px calc(36px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.kicker { font-size: 11.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--sub); }
.heading { display: flex; flex-direction: column; gap: 3px; }
.heading h2, .sheet-title { font-family: var(--serif); font-weight: 600; font-size: 21px; color: var(--ink); }

/* header */
.topbar { display: flex; align-items: flex-start; justify-content: space-between; padding: 0 2px; }
.brand { display: flex; flex-direction: column; gap: 6px; }
.brand-date, .brand-name { display: flex; align-items: baseline; }
.brand-date { gap: 8px; }
.brand-name { gap: 10px; }
.day-count { font-family: var(--serif); font-weight: 600; font-size: 14px; color: var(--accent); }
.brand-name h1 { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 34px; line-height: 1; letter-spacing: -0.01em; }
.brand-sub { font-size: 13px; color: var(--sub); }
.icon-button {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1.5px solid var(--line2); background: none; color: var(--sub);
  display: flex; align-items: center; justify-content: center;
}
.icon-button:active { transform: scale(0.94); }

/* status */
.status { border-radius: 22px; padding: 18px 20px; display: flex; align-items: center; gap: 18px; background: var(--card); box-shadow: var(--shadow); }
.status.sleeping { background: var(--sleepT); box-shadow: none; }
.status-badge { width: 58px; height: 58px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; }
.status.awake .status-badge { background: var(--accentT); color: var(--accent); }
.status.sleeping .status-badge { background: var(--sleep); color: var(--onc); }
.status-copy { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.status.sleeping .kicker { color: var(--sleep); }
.status-value { font-family: var(--serif); font-weight: 600; font-size: 40px; line-height: 1; }
.status-unit { font-size: 18px; font-weight: 500; color: var(--sub); }
.status-note { font-size: 13px; color: var(--sub); }


/* actions */
.actions, .follow { display: grid; grid-template-columns: 1fr; gap: 10px; }
.action {
  min-height: 104px; border-radius: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.action:active, .follow-button:active { transform: scale(0.96); }
.action-label { font-size: 16px; font-weight: 700; color: var(--ink); }
.action.sleep { border: 1.5px solid color-mix(in srgb, var(--sleep) 30%, transparent); background: var(--sleepT); color: var(--sleep); }
.action.sleep .icon-sun { display: none; }
.action.sleep.asleep { border: none; background: var(--sleep); color: var(--onc); }
.action.sleep.asleep .action-label { color: var(--onc); }
.action.sleep.asleep .icon-moon { display: none; }
.action.sleep.asleep .icon-sun { display: block; }
.follow-sub { display: block; font-size: 11.5px; font-weight: 600; opacity: 0.8; margin-top: 3px; }

.follow-button {
  min-height: 64px; border-radius: 18px; padding: 10px 12px;
  border: 1.5px solid color-mix(in srgb, var(--sleep) 45%, transparent); background: var(--card); color: var(--sleep);
  font-size: 14px; font-weight: 700; line-height: 1.25;
  display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
}
#sleepFollow { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#sleepFollow .follow-button { padding: 10px 8px; font-size: 13.5px; }
.follow-button.done { background: var(--sleepT); }
.fuss-badge {
  min-width: 24px; height: 24px; padding: 0 6px; border-radius: 999px;
  background: var(--sleep); color: var(--onc); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
/* cards */
.card { background: var(--card); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-end; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--sub); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line2); }
.sync.ok .sync-dot { background: var(--ok); }
.sync.offline .sync-dot { background: var(--gold); }
.tiles { display: grid; gap: 8px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile { background: var(--bg); border-radius: 14px; padding: 11px 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tile-value { font-family: var(--serif); font-weight: 600; font-size: 21px; line-height: 1.1; }
.tiles.three .tile-value { font-size: clamp(16px, 4.7vw, 21px); letter-spacing: -0.01em; }
.tile-value.sleep { color: var(--sleep); }
.tile-label { font-size: 11.5px; color: var(--sub); line-height: 1.25; }

/* nap columns */
.naps { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.naps-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 8px; }
.naps-title { font-size: 13px; font-weight: 700; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 11.5px; font-weight: 600; color: var(--sub); }
.legend-item { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--sleep); }
.swatch.dashed { background: none; border: 1.5px dashed var(--sleep); }
/* today is twice as wide so forecast times fit inside its blocks */
.nap-grid { display: grid; grid-template-columns: 26px repeat(6, minmax(0, 1fr)) minmax(0, 2fr); column-gap: 5px; }
.col-head { display: flex; flex-direction: column; align-items: center; gap: 1px; padding-bottom: 6px; }
.col-dow { font-size: 10px; font-weight: 700; letter-spacing: 0.03em; }
.col-date { font-family: var(--serif); font-size: 13px; font-weight: 600; }
.col-head.today { color: var(--accent); }
.axis { position: relative; height: 384px; font-size: 10px; color: var(--sub); }
.axis span { position: absolute; transform: translateY(-50%); }
.col { position: relative; height: 384px; background: var(--bg); border-radius: 8px; overflow: hidden; }
.col.today { background: var(--accentT); overflow: visible; }
.gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); }
.nap-block {
  position: absolute; left: 2px; right: 2px; border-radius: 6px; background: var(--sleep);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: clamp(8.5px, 2.6vw, 10px); font-weight: 700; letter-spacing: -0.02em; color: var(--onc);
}
.nap-block.false-start { background: none; border: 1.5px dashed var(--sleep); }
.nap-block.ongoing { opacity: 0.75; }
.nap-block.night { background: color-mix(in srgb, var(--sleep) 35%, transparent); }
.swatch.night { background: color-mix(in srgb, var(--sleep) 35%, transparent); }
.now-line { position: absolute; left: -3px; right: -3px; border-top: 1.5px dotted var(--ink); }
.col-total { text-align: center; font-size: 10.5px; font-weight: 600; color: var(--sub); padding-top: 6px; }

/* nap forecast */
.forecast { display: flex; flex-direction: column; gap: 6px; }
.forecast .tile-value { font-size: clamp(16px, 4.7vw, 21px); white-space: nowrap; }
.forecast .tile:first-child { background: var(--sleepT); }
.forecast-label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sub); }
.chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.chip { background: var(--bg); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.chip.next { background: var(--sleepT); }
.chip-what { font-size: 11.5px; font-weight: 700; color: var(--sub); }
.chip.next .chip-what { color: var(--sleep); }
.nap-choice { margin-top: 2px; }
.nap-choice button { min-height: 36px; padding: 6px 0; font-size: 13px; }
.nap-choice .odds { font-weight: 600; color: var(--sub); }
.chip-when { font-family: var(--serif); font-size: clamp(15px, 4.6vw, 18px); font-weight: 600; white-space: nowrap; }
.nap-block.expected {
  background: repeating-linear-gradient(135deg, var(--hatch) 0 2px, transparent 2px 6px);
  border: 1.5px solid var(--hatch); flex-direction: column; justify-content: flex-start; padding: 2px 0; overflow: visible;
}
.nap-block.expected.ends { justify-content: flex-end; }
.fc-time { background: var(--card); color: var(--ink); border-radius: 4px; padding: 0 4px; font-size: 10.5px; line-height: 14px; letter-spacing: 0; white-space: nowrap; }
.crib-bar { position: absolute; left: 0; width: 4px; background: var(--gold); }
.swatch.crib { width: 4px; border-radius: 2px; background: var(--gold); }
.swatch.expected { border: 1px solid var(--hatch); background: repeating-linear-gradient(135deg, var(--hatch) 0 1.5px, transparent 1.5px 3.5px); }

/* nap transitions */
.transition { background: color-mix(in srgb, var(--gold) 13%, transparent); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.transition-title { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.transition-text { font-size: 13px; line-height: 1.35; color: var(--sub); }
.age-track { position: relative; height: 34px; margin: 0 7px; }
.age-rail, .age-window { position: absolute; top: 8px; height: 6px; border-radius: 3px; }
.age-rail { left: 0; right: 0; background: var(--line2); }
.age-window { background: var(--gold); }
.age-dot { position: absolute; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 3px solid var(--accent); transform: translateX(-50%); }
.age-tick { position: absolute; top: 20px; font-size: 10.5px; color: var(--sub); white-space: nowrap; }
.age-tick.win { font-weight: 700; color: var(--goldInk); }
.age-tick.end { transform: translateX(-100%); }
.signs-title { font-size: 13px; font-weight: 700; margin-top: 12px; }
.signs { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; line-height: 1.35; }
.week-facts { font-size: 13px; line-height: 1.35; margin-top: 10px; }
.transition-foot { font-size: 12px; line-height: 1.4; color: var(--sub); margin-top: 12px; }

.day-rows { display: flex; flex-direction: column; }
.day-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 2px; border-top: 1px solid var(--line); }
.day-row-label { font-size: 13.5px; font-weight: 600; }
.day-row-text { font-size: 13px; color: var(--sub); text-align: right; }

/* history */
.history-section { display: flex; flex-direction: column; gap: 6px; }
.history-heading { padding: 8px 4px 4px; cursor: pointer; list-style: none; position: relative; }
.history-heading::-webkit-details-marker { display: none; }
.chevron { position: absolute; right: 10px; bottom: 14px; width: 9px; height: 9px; border-right: 2px solid var(--sub); border-bottom: 2px solid var(--sub); transform: rotate(45deg); transition: transform 0.2s; }
.history-section[open] .chevron { transform: rotate(-135deg); }
.history-group { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.history-day { font-size: 12px; font-weight: 700; color: var(--sub); padding: 6px 4px 0; }
.history-card { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 4px 0; display: flex; flex-direction: column; }
.history-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 11px 16px;
  background: none; border: none; border-top: 1px solid var(--line); text-align: left; color: var(--ink);
}
.history-item:first-child { border-top: none; }
.history-item:active { background: var(--bg); }
.history-icon { width: 34px; height: 34px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; background: var(--sleepT); color: var(--sleep); }
.history-item.false-start .history-icon { opacity: 0.5; }
.history-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.history-title { font-size: 14.5px; font-weight: 600; }
.history-item.false-start .history-title { color: var(--sub); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.history-meta { font-size: 12.5px; color: var(--sub); }
.history-time { flex: none; font-size: 12.5px; font-weight: 600; color: var(--sub); }
.empty { padding: 16px; color: var(--sub); font-size: 14px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translateX(-50%) translateY(24px); max-width: calc(100vw - 32px); width: max-content;
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--bg);
  font-size: 13.5px; font-weight: 600; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  opacity: 0; pointer-events: none; transition: 180ms ease;
}
.toast.open { opacity: 1; transform: translateX(-50%) translateY(0); }

/* sheets */
.scrim { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 480px; background: var(--card); color: var(--ink);
  border-radius: 24px 24px 0 0; padding: 14px 20px calc(22px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.grabber { width: 36px; height: 4px; border-radius: 999px; background: var(--line2); align-self: center; }
.sheet .sheet-title { font-size: 26px; }
#settingsSheet .sheet-title { font-size: 24px; }
#detailSheet.sleep .kicker { color: var(--sleep); }
.detail-rows { display: flex; flex-direction: column; }
.detail-row { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.detail-row .k { color: var(--sub); }
.detail-row .v { font-weight: 600; }
.fusses { display: flex; flex-direction: column; gap: 8px; }
.fusses-label, .setting-label { font-size: 13px; font-weight: 600; color: var(--sub); }
.fuss-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fuss-chip { font-size: 13px; font-weight: 600; color: var(--sleep); background: var(--sleepT); border-radius: 999px; padding: 6px 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.danger, .primary, .secondary { min-height: 50px; border-radius: 999px; font-size: 15px; font-weight: 700; padding: 13px 22px; }
.danger { color: var(--danger); background: none; border: 1.5px solid color-mix(in srgb, var(--danger) 45%, transparent); }
.primary { flex: 1; color: var(--onc); background: var(--ink); border: none; }
.secondary { color: var(--ink); background: none; border: 1.5px solid var(--line2); }
a.secondary { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.danger:active, .primary:active, .secondary:active { transform: scale(0.98); }

.setting { display: flex; flex-direction: column; gap: 8px; }
.segmented { display: flex; gap: 6px; background: var(--bg); border-radius: 999px; padding: 4px; }
.segmented button { flex: 1; min-height: 42px; padding: 10px 0; border: none; border-radius: 999px; background: transparent; color: var(--sub); font-size: 14px; font-weight: 700; }
.segmented button.on { color: var(--ink); background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* lock */
.lock { position: fixed; inset: 0; z-index: 90; background: var(--bg); padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.lock-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.lock-name { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 34px; }
.lock-sub { font-size: 13.5px; color: var(--sub); }
.pin-dots { display: flex; gap: 14px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--sub); }
.pin-dots span.filled { background: var(--ink); border-color: var(--ink); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.keypad button { height: 64px; border-radius: 50%; border: none; background: var(--card); color: var(--ink); font-family: var(--serif); font-size: 24px; font-weight: 500; }
.keypad .key-back { background: transparent; }
.keypad button:active { transform: scale(0.93); }
.lock-hint { font-size: 12px; color: var(--sub); min-height: 1.2em; }
.lock-hint.error { color: var(--danger); font-weight: 700; }
