:root {
  --bg: #0d0e12;
  --surface: #16181e;
  --surface-2: #1e2028;
  --line: #2a2d37;
  --text: #f3f3f5;
  --muted: #8b8f9a;
  --accent: #ff4f3a;
  --accent-2: #ff8f3c;
  --sleep: #7d84ff;
  --sleep-2: #a58bff;
  --ok: #3ed598;
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
h1 { font-size: clamp(30px, 8vw, 40px); line-height: 1.1; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 28px; letter-spacing: -0.02em; font-weight: 700; }
.muted { color: var(--muted); }
.accent { background: linear-gradient(90deg, var(--accent-2), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.fine { font-size: 13px; text-align: center; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 54px; padding: 0 24px; border-radius: 16px; font-weight: 600; font-size: 17px;
  transition: transform .12s ease, opacity .2s ease, background .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; box-shadow: 0 8px 30px -10px rgba(255, 79, 58, .7); }
.btn.primary:disabled { opacity: .35; box-shadow: none; cursor: not-allowed; }
.btn.ghost { background: var(--surface); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.pill { height: 34px; padding: 0 14px; border-radius: 99px; background: var(--surface-2); font-size: 14px; font-weight: 600; }
.pill.on { color: var(--ok); }

.input, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  color: var(--text); font: inherit; padding: 14px 16px; outline: none; transition: border-color .2s;
}
.input:focus, textarea:focus { border-color: var(--accent-2); }
textarea { resize: none; }

/* Segmented control */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface); padding: 4px; border-radius: 14px; border: 1px solid var(--line); }
.seg button { height: 40px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button.active { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }

/* ───── Onboarding ───── */
.onboard { min-height: 100%; display: flex; justify-content: center; padding: max(48px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom)); }
.step { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 22px; animation: rise .45s ease both; }
.step .btn.primary { margin-top: auto; }
.logo-mark {
  width: 72px; height: 72px; border-radius: 22px; margin-top: 24px;
  background: conic-gradient(from 0deg, var(--accent) 0 75%, var(--surface-2) 75% 100%);
  -webkit-mask: radial-gradient(circle, transparent 18px, #000 19px); mask: radial-gradient(circle, transparent 18px, #000 19px);
  border-radius: 50%;
}
.bullets { list-style: none; padding: 0; display: grid; gap: 14px; color: var(--muted); }
.bullets li { padding-left: 22px; position: relative; }
.bullets li::before { content: ""; position: absolute; left: 0; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.bullets b { color: var(--text); font-weight: 600; }
.rule { font-size: 20px; line-height: 1.4; color: var(--muted); }
.rule b { color: var(--text); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ───── Sleep dial ───── */
.dial-host { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.dial-readout { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 12px; }
.dial-readout div { display: grid; gap: 2px; }
.dial-readout div:last-child { text-align: right; }
.dial-readout .k { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 600; }
.dial-readout div:last-child .k { justify-content: flex-end; }
.dial-readout .v { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.dial-readout .k svg { width: 14px; height: 14px; }
.dial { width: 100%; max-width: 320px; touch-action: none; user-select: none; -webkit-user-select: none; }
.dial .track { fill: none; stroke: var(--surface-2); stroke-width: 44; }
.dial .arc { fill: none; stroke-width: 40; stroke-linecap: round; cursor: grab; }
.dial .tick { stroke: #4a4e5a; stroke-width: 1.5; }
.dial .tick.hr { stroke: #8b8f9a; stroke-width: 2; }
.dial .num { fill: var(--muted); font: 600 12px var(--font); text-anchor: middle; dominant-baseline: central; }
.dial .num.major { fill: var(--text); font-size: 13px; }
.dial .knob { cursor: grab; }
.dial .knob circle { fill: #11121a; }
.dial .knob path { fill: none; stroke: var(--sleep-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dial .knob.wake path { stroke: #ffc65c; }
.dial-duration { font-size: 15px; color: var(--muted); }
.dial-duration b { color: var(--text); font-size: 20px; }

/* ───── App shell ───── */
.app { max-width: 460px; margin: 0 auto; min-height: 100%; padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
.view { display: flex; flex-direction: column; gap: 18px; animation: rise .35s ease both; }
.top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.brand { font-weight: 700; font-size: 22px; display: flex; align-items: center; gap: 8px; letter-spacing: -0.02em; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.ring-wrap { position: relative; width: min(300px, 82vw); aspect-ratio: 1; margin: 4px auto 0; }
#ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 16; }
.ring-progress { fill: none; stroke: url(#g-tomato); stroke-width: 16; stroke-linecap: round; transition: stroke-dashoffset 1s linear, stroke .3s; }
.ring-wrap.asleep .ring-progress { stroke: var(--sleep); }
.ring-wrap.paused .ring-progress { stroke: #3a3d48; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 2px; }
.countdown { font: 700 64px/1 var(--font); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.countdown.small { font-size: 34px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.card.flat { padding: 20px 16px; }
.interval-range { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.acct { display: grid; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 .btn { padding: 0 12px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: grid; gap: 2px; }
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .t { font-size: 12px; color: var(--muted); }

.journal { display: grid; gap: 22px; }
.day h3 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.entries { display: grid; gap: 0; border-left: 2px solid var(--line); margin-left: 6px; }
.entry { position: relative; padding: 0 0 16px 20px; }
.entry::before { content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.entry .time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.entry .note { white-space: pre-wrap; overflow-wrap: anywhere; }
.entry.missed::before { background: var(--line); }
.entry.missed .note { color: var(--muted); font-style: italic; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 460px;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(13, 14, 18, .85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.tab { display: grid; justify-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }

/* ───── Alarm ───── */
.alarm {
  position: fixed; inset: 0; z-index: 100; display: flex; justify-content: center; align-items: center;
  background: radial-gradient(120% 80% at 50% 0%, #3a1410 0%, var(--bg) 60%);
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
}
.alarm-pulse { position: absolute; inset: 0; background: var(--accent); opacity: 0; animation: flash 1.2s ease-in-out infinite; pointer-events: none; }
@keyframes flash { 0%, 100% { opacity: 0; } 15% { opacity: .14; } }
.alarm-inner { position: relative; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.alarm-count { font-size: 13px; color: var(--accent-2); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; min-height: 18px; }
.alarm-bell { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 79, 58, .15); animation: ring .6s ease-in-out infinite; }
.alarm-bell svg { width: 32px; height: 32px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-14deg); } 75% { transform: rotate(14deg); } }
.alarm-q { font-size: 19px; color: var(--muted); }
.alarm-q b { color: var(--text); }
.alarm-plan { font-size: 15px; color: var(--muted); background: var(--surface); border-radius: 12px; padding: 10px 14px; border: 1px dashed var(--line); }
.alarm textarea { font-size: 17px; min-height: 120px; }
.sound-hint { color: var(--accent-2); font-weight: 600; text-decoration: underline; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}

/* Sign-in step */
.back { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; }
.back:hover { color: var(--text); }
.link { color: var(--muted); font-weight: 600; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; align-self: center; padding: 8px; }
.link:hover { color: var(--text); }

/* Account deletion */
.link.danger { color: #ff6b5e; font-size: 14px; justify-self: center; }
.btn.danger { background: #c8322a; color: #fff; }
