:root {
  --bg: #0b0d12;
  --bg-elev: #14171f;
  --bg-elev-2: #1c202b;
  --line: #2a2f3d;
  --text: #eef0f5;
  --text-dim: #9aa2b4;
  --text-faint: #5c6478;
  --accent: #7fb2ff;
  --accent-dim: #3d5a8a;
  --moon: #b9a6ff;
  --sun: #ffcf7a;
  --accelerate: #ff8f45;
  --rust: #ff7538;
  --danger: #ff6b6b;
  --danger-dim: #4a2b2b;
  --good: #6fdc9a;
  --accelerate-dim: #4a3320;
  --rust-dim: #4a2c18;
  --sun-dim: #4a4020;
  --moon-dim: #332a4a;
  --accent-bg-dim: #22314a;
  --good-dim: #1f3d2e;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  padding-top: calc(16px + env(safe-area-inset-top));
  animation: fade-in .25s ease;
}

.hidden { display: none !important; }

@keyframes fade-in { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

h1 { font-size: 22px; margin: 0 0 16px; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 4px; font-weight: 600; }
a { color: var(--accent); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 24px;
}

.section-header { margin: 0 0 10px 2px; }

button {
  font-family: inherit;
  border: none;
  border-radius: 14px;
  padding: 15px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-elev-2);
  transition: transform .1s ease, opacity .15s ease;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #0b0d12; }
.btn-danger { background: var(--danger-dim); color: #ffb3b3; }
.btn-danger.solid { background: var(--danger); color: #1a0a0a; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-block { width: 100%; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.field { margin-bottom: 10px; }
.field-label { display: block; font-size: 13px; color: var(--text); margin-bottom: 6px; }
.field-hint { font-size: 16px; line-height: 1.45; color: var(--text); margin: -4px 0 14px; }
.field-error { font-size: 12.5px; line-height: 1.4; color: var(--danger); margin: -4px 0 14px; }
.duration-flag { color: var(--danger); font-weight: 700; }
.field input[type="time"] {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 18px;
  font-family: inherit;
  color-scheme: dark;
}
/* -webkit-datetime-edit-ampm-field targets just the AM/PM segment of a
   native <input type="time"> — a webkit-only pseudo-element, needed to
   tint that half without recoloring the whole box. */
.field input[type="time"].ampm-unusual-input::-webkit-datetime-edit-ampm-field {
  color: #f0d3d3;
}
#ob-sleep-duration.sleep-duration-warning { color: var(--danger); }
.field input[type="time"].bedtime-too-late { border-color: var(--danger); }

.tick-confirm { margin: 2px 0 14px; }
.tick-confirm label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
}
.tick-confirm input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.ob-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.bottom-row { margin-top: auto; padding-top: 16px; }

.step-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; flex-wrap: wrap; }
.step-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.step-dots span.active { background: var(--accent); width: 18px; border-radius: 4px; }

.ob-choice-row { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.btn-choice { width: 100%; text-align: left; padding: 18px; background: var(--bg-elev-2); border: 1px solid var(--line); }
.btn-choice:active { background: var(--bg-elev-3, var(--bg-elev-2)); }

.bedtime-options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin-top: 18px;
}
.bedtime-options-list .btn-ghost { padding: 14px; }

.text-escape {
  display: block;
  width: 100%;
  margin-top: 14px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 6px;
}

.ob-splash-img-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
}
/* Percentage heights (and thus plain max-height:100%/object-fit against a
   percentage box) don't reliably resolve when the parent's height comes
   from flex-grow alone rather than an explicit value — that's what was
   silently cropping this image top/bottom despite max-width capping the
   width. Absolute-positioning the img against its `position: relative`
   wrap sizes it against the wrap's actual padding box instead of a
   percentage, which resolves correctly, then object-fit:contain shrinks
   the image to fit inside that box without ever cropping it. */
.ob-splash-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }

.ob-blocked-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  text-align: center;
  padding: 0 8px;
}
.ob-blocked-icon { font-size: 56px; line-height: 1; }

.explainer-body { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; flex: 1; min-height: 0; }
.explainer-body p { margin: 0; line-height: 1.4; }

.privacy-verify-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 12px; }
.privacy-verify-list li { line-height: 1.4; }
.privacy-verify-list a { display: block; color: var(--accent); font-size: 13.5px; margin-top: 2px; }

.icon-btn {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* ---- Home screen: just the bedtime/wake split, nothing else ---- */

.split-schedule {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.split-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.split-pane-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: auto 0;
}
.split-line { height: 1px; background: var(--line); margin: 0; flex-shrink: 0; }

.split-heading {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.split-kind {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.split-time {
  display: block;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.split-kind-under {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: center;
  margin-top: 2px;
}
.split-time.label-dimmed { color: var(--text-faint); opacity: .55; text-decoration: line-through; }

.split-ampm.ampm-unusual { color: #f0d3d3; }

.split-time-input {
  width: 160px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 22px;
  font-family: inherit;
  color-scheme: dark;
  text-align: center;
}

.override-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 2px 8px 0;
}

.bed-pending-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 6px;
  padding: 10px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.bed-pending-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.bed-pending-btn {
  flex-shrink: 0;
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
}

/* Two fixed instances (#pane-top-streak / #pane-bottom-streak), inline
   right after that pane's "Bedtime" label text — updateStreakBadge() just
   toggles which one is visible instead of reparenting a single node (a
   previous DOM-swap approach left the badge detached/invisible depending
   on which pane was live). */
.streak-inline {
  display: inline-block;
  margin-left: 6px;
  font-weight: 800;
  letter-spacing: normal;
  background: linear-gradient(135deg, #fff7ec 0%, #ffb347 60%, #ff8a1e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.next-alarm-caption {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

.reset-link {
  align-self: center;
  margin: 2px auto 0;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  text-decoration: none;
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.footer-links .reset-link { margin: 0; }

.footer-unblock-link { margin-top: 4px; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.screen-fullbleed { padding: 0 !important; position: relative; overflow: hidden; }

.welcome-bg {
  position: absolute; inset: 0;
  background: url('bg-sun.jpg') center / cover no-repeat;
}
.welcome-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end;
  background: linear-gradient(180deg, rgba(11,13,18,0) 35%, rgba(11,13,18,.85) 75%, rgba(11,13,18,.98));
  padding: 24px 24px calc(36px + env(safe-area-inset-bottom));
}
/* flex column (not width:100%) so children like <a>, normally inline,
   get blockified into real flex items — needed for .reset-link's
   align-self:center/auto-margin centering to work here. */
.welcome-content { width: 100%; display: flex; flex-direction: column; }
.welcome-title { font-size: 34px; margin: 0 0 6px; }

.welcome-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(20px + env(safe-area-inset-top)) 24px 44px;
  background: linear-gradient(180deg, rgba(11,13,18,.92), rgba(11,13,18,.55) 65%, rgba(11,13,18,0));
}
.welcome-subtitle {
  margin: 0;
  max-width: 320px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-dim);
}

/* Alarm-splash is a normal (non-fullbleed) flex column now: the image gets
   its own contain-sized box (flex:1, never crops) and the title/hint/button
   sit below it in normal flow, so every element is fully visible on screen
   at once instead of text overlaid on a cropped full-bleed photo. */
.alarm-splash-layout { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 20px; }
.splash-bg {
  flex: 1;
  min-height: 0;
  background-color: var(--bg-elev);
  background-size: contain; background-position: center; background-repeat: no-repeat;
  border-radius: var(--radius);
}
#screen-alarm-splash.splash-bed .splash-bg { background-image: url('bg-bed.jpg'); }
#screen-alarm-splash.splash-wake .splash-bg { background-image: url('bg-sun.jpg'); }
.splash-content { text-align: center; padding-bottom: env(safe-area-inset-bottom); }
.splash-title { font-size: 28px; margin-bottom: 8px; }
.splash-time-hint { font-size: 15px; margin-bottom: 20px; }
.splash-action { width: 100%; max-width: 320px; margin: 0 auto; display: block; }

.task-layout {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  background: #000;
}

.task-top-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.task-title {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  max-width: 300px;
  line-height: 1.4;
}

.timer-pill {
  background: rgba(255,255,255,.08);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}
.timer-pill.warn { color: var(--danger); }

.task-stage {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  max-height: 58vh;
  background: #000;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
}
.task-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
/* MediaRecorder reads off the MediaStream track directly, not this
   <video> element — this filter/pause is purely a UI effect and never
   touches the actual recording. */
.task-stage video.video-blurred { filter: blur(8px) brightness(.85); }

.task-sun-message {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 30px;
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.45;
  text-shadow: 0 2px 12px rgba(0,0,0,.6);
}

.extend-chip {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.task-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* touch-action:none on .shutter below is required — without it, a finger
   drifting mid-press gets read as a scroll/zoom gesture, which fires
   pointercancel and resets the in-progress recording. */
.shutter-wrap { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.shutter-ring {
  position: absolute; inset: 0;
  transform: rotate(-90deg);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.shutter-ring.on { opacity: 1; }
.shutter-ring-track { fill: none; stroke: rgba(255,255,255,.25); stroke-width: 4; }
.shutter-ring-progress {
  fill: none;
  stroke: var(--danger);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 276.5; /* 2 * pi * r(44) */
  stroke-dashoffset: 276.5;
}
.shutter {
  position: absolute; inset: 0;
  width: 96px; height: 96px;
  border-radius: 50%;
  background: transparent;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.shutter-dot {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255,255,255,.35);
  transition: background .15s;
}
.shutter.recording .shutter-dot { background: var(--danger); }

.task-checking-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(2px);
}
.task-checking-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  animation: task-checking-spin .8s linear infinite;
}
@keyframes task-checking-spin { to { transform: rotate(360deg); } }
.task-checking-label { color: #fff; font-size: 14px; font-weight: 600; }

.emergency-text-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 4px;
}

.streak-flame-big {
  font-size: 96px;
  line-height: 1;
  margin-bottom: 4px;
  animation: streak-flame-pulse 1.6s ease-in-out infinite;
}
@keyframes streak-flame-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.streak-delta {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 2px 0 0;
}
.streak-count-orange {
  font-size: 64px;
  font-weight: 800;
  color: var(--accelerate);
  line-height: 1;
  margin: 2px 0 28px;
}

.unblock-confirm-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8vh 24px 32px;
}
.unblock-confirm-layout .bedtime-options-list { margin-top: auto; }

.streak-loss-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 26px;
  font-weight: 800;
  margin: 6px 0 2px;
}
.streak-loss-current { color: var(--accelerate); }
.streak-loss-arrow { color: var(--text-faint); font-weight: 400; }
.streak-loss-zero { color: var(--text-dim); }

.unblock-confirm-subtitle {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  max-width: 300px;
  margin: 12px 0 4px;
  line-height: 1.4;
}

.pair-confirm-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 20px;
  margin: 14px 0;
}
.pair-confirm-error { color: var(--danger); }

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 70;
  max-width: 90%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.toast-action {
  flex-shrink: 0;
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

/* z-index 80 — must stay above .task-checking-overlay (3) and .toast (70)
   so the reliability banner is never covered by either. */
.banner-stack {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
}
.top-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  /* Modifier classes below set --tb-bg/--tb-border; danger red is the
     fallback when no modifier is applied. */
  background: var(--tb-bg, var(--danger-dim));
  border-bottom: 1px solid var(--tb-border, var(--danger));
}
.top-banner--fullscreen-intent { --tb-bg: var(--accelerate-dim); --tb-border: var(--accelerate); }
.top-banner--battery { --tb-bg: var(--sun-dim); --tb-border: var(--sun); }
.top-banner--dnd { --tb-bg: var(--moon-dim); --tb-border: var(--moon); }
.top-banner--volume { --tb-bg: var(--accent-bg-dim); --tb-border: var(--accent); }
.top-banner--block-permission { --tb-bg: var(--rust-dim); --tb-border: var(--rust); }
.top-banner--bedtime-block { --tb-bg: var(--moon-dim); --tb-border: var(--moon); }
.top-banner-text {
  flex: 1;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.top-banner-action {
  flex-shrink: 0;
  background: var(--tb-border, var(--danger));
  color: #1a0d0d;
  border: none;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.done-check { font-size: 56px; margin-bottom: 6px; }
.done-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  max-width: 280px;
  margin: -6px 0 18px;
  line-height: 1.4;
}
/* rgba white, not var(--text-faint) — that color is too dark to read
   against this screen's black camera background. */
.task-privacy-note {
  font-size: 11.5px;
  color: rgba(255,255,255,.45);
  max-width: 260px;
  text-align: center;
  line-height: 1.4;
  margin: 0;
}

small.hint { color: var(--text-faint); font-size: 12px; }
