/* Single phone-first column: live timer on top, the day's numbers, a 24h strip from morning to morning, then the log. */
:root {
  --bg: #F2F4F8;
  --surface: #FFFFFF;
  --ink: #1A2134;
  --muted: #5F6880;
  --line: #DDE1EB;
  --night: #3D4B98;
  --night-soft: #E3E7F7;
  --nap: #B98222;
  --nap-soft: #F5EBD6;
  --on-accent: #FFFFFF;
  --danger: #B0423A;
  --scrim: rgba(18, 22, 36, 0.45);
  --font-display: "Sora", "Figtree", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D111D; --surface: #151A2A; --ink: #E5E8F1; --muted: #949CB3; --line: #252C42;
    --night: #8E9CF0; --night-soft: #212849; --nap: #E0B25A; --nap-soft: #352C1C;
    --on-accent: #0D111D; --danger: #EE8A80; --scrim: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
.wrap { max-width: 560px; margin: 0 auto; padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 18px; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--night); outline-offset: 2px; }

/* Header */
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.sync { font-size: 0.8rem; color: var(--muted); margin: -10px 0 -4px; display: flex; align-items: center; gap: 6px; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: #4E9A6B; display: inline-block; }
.sync.offline i { background: var(--nap); }
.sync.error { color: var(--danger); }
.sync.error i { background: var(--danger); }

/* Timer */
.timer { border-radius: var(--radius); padding: 22px 20px 20px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; }
.timer.asleep { background: var(--night-soft); border-color: transparent; }
.state { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--nap); }
.asleep .dot { background: var(--night); animation: breathe 3.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.clock { font-family: var(--font-display); font-weight: 300; font-size: clamp(2.8rem, 13vw, 3.6rem); line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.asleep .clock { color: var(--night); }
.since { color: var(--muted); font-size: 0.92rem; margin-top: -6px; }
.timer-actions { display: flex; flex-direction: column; gap: 10px; }
.primary { width: 100%; min-height: 58px; border: 0; border-radius: 14px; background: var(--night); color: var(--on-accent); font-weight: 600; font-size: 1.05rem; }
.primary:disabled { opacity: 0.5; cursor: default; }
.primary:active { transform: scale(0.99); }
.text-btn { background: none; border: 0; color: var(--night); font-weight: 600; font-size: 0.92rem; padding: 4px 0; align-self: center; }

/* Day nav */
.daynav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daynav h2 { margin: 0; font-size: 1.05rem; font-weight: 600; text-align: center; flex: 1; min-width: 0; }
.daynav .sub { display: block; font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.daynav button:disabled { opacity: 0.35; cursor: default; }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 13px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile.total { grid-column: 1 / -1; gap: 10px; }
.label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.label i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: none; }
.val { font-family: var(--font-display); font-weight: 400; font-size: 1.45rem; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile.total .val { font-size: 2rem; font-weight: 300; }
.hint { font-size: 0.8rem; color: var(--muted); }
.split { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; display: flex; }
.split span { height: 100%; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }

/* Timeline */
.strip { position: relative; height: 44px; border-radius: 8px; background: var(--bg); overflow: hidden; }
.strip .nightzone { position: absolute; top: 0; bottom: 0; background: var(--night-soft); opacity: 0.55; }
.strip .blk { position: absolute; top: 8px; bottom: 8px; border-radius: 4px; min-width: 3px; border: 0; padding: 0; }
.strip .blk.nap { background: var(--nap); }
.strip .blk.night { background: var(--night); }
.strip .blk.live { opacity: 0.7; }
.strip .nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: 0.6; }
.ticks { position: relative; height: 16px; font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ticks span:first-child { transform: none; }
.ticks span:last-child { transform: translateX(-100%); }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Log */
.loghead { display: flex; justify-content: space-between; align-items: center; }
.add { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; font-weight: 600; font-size: 0.85rem; color: var(--night); }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.log li + li { border-top: 1px solid var(--line); }
.row { width: 100%; background: none; border: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 2px; text-align: left; }
.chip { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 999px; }
.chip.nap { background: var(--nap-soft); color: var(--nap); }
.chip.night { background: var(--night-soft); color: var(--night); }
.row .times { font-variant-numeric: tabular-nums; min-width: 0; }
.row .dur { font-weight: 600; font-variant-numeric: tabular-nums; }
.row .wake { display: block; font-size: 0.78rem; color: var(--muted); }
.empty { color: var(--muted); font-size: 0.92rem; padding: 6px 0 2px; }

/* Week */
.week { display: grid; grid-template-columns: 28px 1fr; gap: 6px; }
.yaxis { position: relative; height: 140px; font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.yaxis span { position: absolute; right: 0; transform: translateY(50%); }
.plot { position: relative; height: 140px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; }
.plot .grid { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); }
.bar { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; background: none; border: 0; padding: 0; border-radius: 4px; }
.bar span { display: block; width: 100%; }
.bar .n { background: var(--night); border-radius: 0 0 4px 4px; }
.bar .d { background: var(--nap); border-radius: 4px 4px 0 0; }
.bar.cur { outline: 2px solid var(--ink); outline-offset: 3px; }
.xlabels { grid-column: 2; display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; font-size: 0.72rem; color: var(--muted); text-align: center; }
.xlabels .cur { color: var(--ink); font-weight: 700; }

/* Sheets */
.overlay { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; max-height: 92%; overflow-y: auto; margin: 0; }
@media (min-width: 600px) { .overlay { align-items: center; } .sheet { border-radius: 20px; padding-bottom: 24px; } }
.sheet h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.2rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field input { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; width: 100%; -webkit-appearance: none; appearance: none; }
.field input:disabled { opacity: 0.45; }
.check { display: flex; align-items: center; gap: 10px; font-size: 0.95rem; }
.check input { width: 20px; height: 20px; accent-color: var(--night); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { text-align: center; padding: 10px 4px; font-size: 0.92rem; font-weight: 600; color: var(--muted); cursor: pointer; position: relative; }
.seg label + label { border-left: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--night-soft); color: var(--ink); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--night); outline-offset: -2px; }
.help { font-size: 0.82rem; color: var(--muted); margin: -6px 0 0; font-weight: 400; }
.err { color: var(--danger); font-size: 0.88rem; margin: 0; }
.sheet-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sheet-actions .spacer { flex: 1; }
.btn { min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.btn.save { background: var(--night); color: var(--on-accent); border-color: transparent; }
.btn.del { color: var(--danger); border-color: transparent; background: none; padding: 0 6px; }
.btn.del.armed { background: var(--danger); color: var(--surface); padding: 0 14px; }
.signout { background: none; border: 0; color: var(--muted); font-size: 0.85rem; text-decoration: underline; padding: 0; align-self: flex-start; }

/* Sign-in */
.gate { min-height: 80vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.gate form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.gate img { width: 64px; height: 64px; border-radius: 15px; }
.gate h1 { font-size: 1.6rem; }
.gate p { margin: 0; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { .asleep .dot { animation: none; } .primary:active { transform: none; } }
