/*
  Wind-Down.

  The design rule for this whole file: as bedtime gets closer the screen gets
  DARKER AND QUIETER, never louder. No red, no pulsing, no exclamation marks.
  The accent walks from a cool sage through dusk blues into a warm amber — the
  colour of a room where the lamps are going off, not an alarm going off.

  A scolding app gets deleted. That is a design constraint, not a nicety.
*/

/* ── phase palette ─────────────────────────────────────────────────────────
   Driven by data-phase on <html>, set once a second by app.js. */

:root {
  --plane: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2230;
  --hairline: rgba(255, 255, 255, 0.08);

  --ink: #e6edf3;
  --ink-2: #9aa7b4;
  --ink-muted: #6e7d8c;

  --accent: #7ba894;
  --glow: rgba(123, 168, 148, 0.16);

  --radius: 18px;
  --radius-sm: 12px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* Colour transitions are slow on purpose — you should never catch the
     screen changing, only notice later that it has. */
  --shift: 2400ms;

  color-scheme: dark;
}

:root[data-phase='rest']     { --accent: #7ba894; --glow: rgba(123, 168, 148, 0.16); --plane: #0d1117; }
:root[data-phase='approach'] { --accent: #6f9ec4; --glow: rgba(111, 158, 196, 0.16); --plane: #0c1016; }
:root[data-phase='wind']     { --accent: #8b9bd4; --glow: rgba(139, 155, 212, 0.17); --plane: #0b0e14; }
:root[data-phase='close']    { --accent: #a892c8; --glow: rgba(168, 146, 200, 0.17); --plane: #0a0d12; }
:root[data-phase='edge']     { --accent: #cf9f8a; --glow: rgba(207, 159, 138, 0.18); --plane: #090b10; }
:root[data-phase='now']      { --accent: #dfae86; --glow: rgba(223, 174, 134, 0.20); --plane: #08090d; }
:root[data-phase='done']     { --accent: #86b6ef; --glow: rgba(134, 182, 239, 0.14); --plane: #08090d; }

/* ── base ─────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

/* Must come before any component that sets `display`. An author-stylesheet
   `display: grid` on .sheet or .toast outranks the UA sheet's [hidden] rule,
   which leaves a full-screen overlay sitting invisibly on top of the app
   eating every tap. Belt and braces. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--plane);
  color: var(--ink);
  font: 400 17px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background var(--shift) var(--ease);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

/* A single soft light source, low on the screen, dimming through the evening. */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(60% 45% at 50% 18%, var(--glow), transparent 70%);
  transition: background var(--shift) var(--ease);
}

h1, h2 { font-weight: 600; letter-spacing: -0.01em; margin: 0 0 8px; }
h1 { font-size: 26px; line-height: 1.25; }
h2 { font-size: 17px; }
p { margin: 0 0 12px; }

.muted { color: var(--ink-2); font-size: 15px; }
.hint { color: var(--ink-muted); font-size: 14px; margin-top: 12px; }
.lede { color: var(--ink-2); font-size: 17px; }
.footnote { text-align: center; padding: 0 24px 8px; font-size: 14px; }

/* ── buttons & fields ─────────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 13px 22px;
  cursor: pointer;
  transition: background 160ms var(--ease), border-color 160ms var(--ease), opacity 160ms;
  -webkit-tap-highlight-color: transparent;
  min-height: 46px;
}
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--accent);
  color: #0a0d12;
  transition: background var(--shift) var(--ease);
}
.btn-primary:not(:disabled):active { transform: scale(0.985); }

.btn-quiet {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--hairline);
}
.btn-quiet:not(:disabled):hover { background: rgba(255, 255, 255, 0.04); color: var(--ink); }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.file-btn { display: inline-flex; align-items: center; }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
}
.field:last-of-type { border-bottom: 0; }
.field > span { color: var(--ink-2); font-size: 16px; }

input[type='time'], input[type='text'], input[type='number'] {
  font: inherit;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-height: 42px;
}
input[type='time'] { min-width: 120px; }
input[type='text'] { width: 100%; }
input:focus-visible, .btn:focus-visible, summary:focus-visible, [role='tab']:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── layout ───────────────────────────────────────────────────────────── */

.view { display: none; position: relative; z-index: 1; padding: 0 20px; max-width: 620px; margin: 0 auto; }
.view.is-active { display: block; }
.view-title { padding: calc(24px + env(safe-area-inset-top)) 0 12px; font-size: 22px; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.card-head h2 { margin: 0; }

.pill {
  font-size: 13px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill.is-good { color: #86b6ef; border-color: rgba(134, 182, 239, 0.35); }
.pill.is-attention { color: #dfae86; border-color: rgba(223, 174, 134, 0.35); }

/* ── tonight ──────────────────────────────────────────────────────────── */

.tonight-head { padding: calc(28px + env(safe-area-inset-top)) 0 0; text-align: center; }
.phase-label {
  color: var(--ink-muted);
  font-size: 13px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin: 0;
}

.countdown-card { text-align: center; padding: 30px 0 22px; position: relative; z-index: 1; }
.countdown-lede { color: var(--ink-2); font-size: 15px; margin: 0 0 4px; }

.countdown {
  font-size: clamp(60px, 20vw, 88px);
  font-weight: 200;
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  margin: 0 0 14px;
  transition: color var(--shift) var(--ease);
}

/* The one animation in the app: a slow breath at the deadline. Roughly the
   pace of a calm exhale — an invitation, not an alarm. */
:root[data-phase='now'] .countdown { animation: breathe 5.5s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { opacity: 0.72; }
  50%      { opacity: 1; }
}

.target-chip {
  font: inherit;
  font-size: 15px;
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  min-height: 38px;
}
.target-chip:hover { color: var(--ink); }

.stage-message {
  margin: 18px auto 0;
  max-width: 30ch;
  color: var(--ink-2);
  font-size: 17px;
  line-height: 1.45;
  min-height: 3em;
}

/* ── checklist ────────────────────────────────────────────────────────── */

.checklist { list-style: none; margin: 14px 0 0; padding: 0; }
.checklist li { border-bottom: 1px solid var(--hairline); }
.checklist li:last-child { border-bottom: 0; }

.check {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 2px;
  cursor: pointer;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
.check input { position: absolute; opacity: 0; pointer-events: none; }

.check .box {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1.5px solid var(--ink-muted);
  display: grid;
  place-items: center;
  transition: background 200ms var(--ease), border-color 200ms var(--ease);
}
.check .box::after {
  content: '';
  width: 11px;
  height: 6px;
  border-left: 2px solid #0a0d12;
  border-bottom: 2px solid #0a0d12;
  transform: rotate(-45deg) scale(0.5);
  opacity: 0;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after { opacity: 1; transform: rotate(-45deg) scale(1); }
.check input:checked ~ .check-label { color: var(--ink-muted); }
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.check-label { transition: color 200ms var(--ease); }

.checklist-actions { margin-top: 16px; display: flex; justify-content: center; }

.done-card { text-align: center; }
.done-mark { font-size: 34px; color: var(--accent); margin: 0 0 6px; }

.streak-line {
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
  padding: 4px 0 24px;
}

/* ── stats ────────────────────────────────────────────────────────────── */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}
.stat-value { font-size: 27px; font-weight: 300; color: var(--ink); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--ink-muted); margin-top: 5px; letter-spacing: 0.02em; }

/* ── heatmap ──────────────────────────────────────────────────────────── */

.heatmap-wrap { position: relative; margin: 4px 0 14px; }
.heatmap-svg { display: block; overflow: visible; }
.heatmap-label { fill: var(--ink-muted); font-size: 9px; font-family: inherit; }

.heatmap-cell {
  stroke: var(--hairline);
  stroke-width: 1;
  cursor: pointer;
  transition: opacity 120ms var(--ease);
}
.heatmap-cell:hover, .heatmap-cell:focus { opacity: 0.75; outline: none; }
.heatmap-cell.is-future { cursor: default; stroke: rgba(255, 255, 255, 0.04); }
.heatmap-cell.is-today { stroke: var(--accent); stroke-width: 1.5; }

.heatmap-tooltip {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #05070a;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.heatmap-tooltip strong { display: block; font-weight: 600; }
.heatmap-tooltip span { color: var(--ink-2); }

.heatmap-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; border: 1px solid var(--hairline); }

.heatmap-table { margin-top: 16px; }
.heatmap-table summary { cursor: pointer; color: var(--ink-2); font-size: 14px; padding: 6px 0; }
.heatmap-table table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.heatmap-table th { text-align: left; color: var(--ink-muted); font-weight: 500; padding: 7px 0; font-size: 13px; }
.heatmap-table td { padding: 7px 0; border-top: 1px solid var(--hairline); color: var(--ink-2); }

/* ── stages & checklist editors ───────────────────────────────────────── */

.stage-row {
  border-top: 1px solid var(--hairline);
  padding: 14px 0 4px;
}
.stage-row:first-child { border-top: 0; }
.stage-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stage-when { font-size: 15px; color: var(--ink); font-weight: 500; }
.stage-when small { display: block; color: var(--ink-muted); font-weight: 400; font-size: 13px; margin-top: 2px; }
.stage-body { margin-top: 10px; }
.stage-body input { margin-bottom: 8px; }
.stage-row[data-enabled='false'] .stage-body { opacity: 0.4; }

/* iOS-style switch, sized for a thumb. */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  transition: background 200ms var(--ease);
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink-muted);
  transition: transform 200ms var(--ease), background 200ms var(--ease);
}
.switch input:checked + .track { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.switch input:checked + .track::after { transform: translateX(20px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.item-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--hairline); }
.item-row:first-child { border-top: 0; }
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--ink-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 8px 10px;
  line-height: 1;
  border-radius: 8px;
  min-height: 40px;
}
.icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.05); }

/* ── layers table ─────────────────────────────────────────────────────── */

.layer { display: flex; gap: 12px; padding: 13px 0; border-top: 1px solid var(--hairline); }
.layer:first-child { border-top: 0; }
.layer-badge {
  flex: 0 0 auto;
  align-self: flex-start;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  color: var(--ink-muted);
  margin-top: 2px;
}
.layer-badge[data-strength='hard'] { color: #86b6ef; border-color: rgba(134, 182, 239, 0.35); }
.layer-badge[data-strength='loud'] { color: #dfae86; border-color: rgba(223, 174, 134, 0.3); }
.layer-name { font-weight: 500; font-size: 15px; }
.layer-does { color: var(--ink-2); font-size: 14px; margin: 3px 0 0; }
.layer-honest { color: var(--ink-muted); font-size: 13px; margin: 4px 0 0; font-style: italic; }

/* ── callouts ─────────────────────────────────────────────────────────── */

.callout {
  border-radius: var(--radius-sm);
  padding: 15px 17px;
  font-size: 15px;
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  margin-bottom: 16px;
}
.callout h2 { font-size: 16px; }
.callout p:last-child { margin-bottom: 0; }
.callout-warn { border-color: rgba(223, 174, 134, 0.35); color: #f0d5bd; }
.callout-action { border-color: rgba(134, 182, 239, 0.3); }

.steps { margin: 10px 0 0; padding-left: 20px; color: var(--ink-2); font-size: 15px; }
.steps li { margin-bottom: 7px; }

/* ── onboarding ───────────────────────────────────────────────────────── */

.onboarding {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.onboard-card { width: 100%; max-width: 460px; }

.onboard-progress { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 28px; }
.onboard-progress li {
  height: 3px;
  flex: 1;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  transition: background 400ms var(--ease);
}
.onboard-progress li.is-current, .onboard-progress li.is-done { background: var(--accent); }

.onboard-step { display: none; animation: rise 420ms var(--ease); }
.onboard-step.is-current { display: block; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.onboard-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

.test-panel { margin: 20px 0; }
.test-status { font-size: 14px; color: var(--ink-2); margin: 12px 0 0; min-height: 1.4em; }
.test-status[data-tone='good'] { color: #86b6ef; }
.test-status[data-tone='warn'] { color: #dfae86; }

/* ── tabbar ───────────────────────────────────────────────────────────── */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  background: none;
  border: 0;
  color: var(--ink-muted);
  font: inherit;
  font-size: 12px;
  padding: 13px 4px 12px;
  cursor: pointer;
  transition: color 180ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.tabbar button[aria-selected='true'] { color: var(--accent); }

/* ── sheet ────────────────────────────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 5, 8, 0.88);
  display: grid;
  align-items: end;
  animation: fade 200ms var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-panel {
  background: var(--surface);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  animation: slide 320ms var(--ease);
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
}
@keyframes slide { from { transform: translateY(20px); } to { transform: none; } }

.sheet-head, .sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  gap: 12px;
}
.sheet-head { border-bottom: 1px solid var(--hairline); }
.sheet-head h2 { margin: 0; }
.sheet-foot { border-top: 1px solid var(--hairline); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.sheet-body { overflow-y: auto; padding: 4px 20px 12px; -webkit-overflow-scrolling: touch; }

.guide-step { padding: 18px 0; border-bottom: 1px solid var(--hairline); }
.guide-step:last-child { border-bottom: 0; }
.guide-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  font-size: 13px;
  color: var(--ink-2);
  margin-right: 9px;
}
.guide-where {
  font-size: 13px;
  color: var(--ink-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 6px 0 10px;
}
.guide-why {
  font-size: 14px;
  color: var(--ink-2);
  border-left: 2px solid var(--hairline);
  padding-left: 12px;
  margin-top: 12px;
}
.caveat { padding: 14px 0; border-top: 1px solid var(--hairline); }
.caveat-claim { color: var(--ink-muted); font-size: 14px; text-decoration: line-through; margin: 0 0 5px; }
.caveat-reality { font-size: 14px; color: var(--ink-2); margin: 0; }

/* ── toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  background: #05070a;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  animation: rise 240ms var(--ease);
  max-width: calc(100vw - 40px);
  text-align: center;
}

/* ── motion ───────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
