/* ============ Tempo design system ============
   Phone-first. Dark by default (fasting happens at night).
   Accent: amber (the clock). Eating windows: teal.
   Never color-alone: every status pairs icon + label. */

:root {
  --bg: #101216;
  --bg-soft: #15181d;
  --surface: #1a1e24;
  --surface-2: #22272f;
  --line: #2a3038;
  --ink: #f2f4f1;
  --ink-dim: #c6cdd5;
  --muted: #8b94a0;
  --amber: #ffb224;
  --amber-deep: #e09a12;
  --teal: #5eead4;
  --teal-dim: #2dd4bf;
  --red: #ff6b6b;
  --green: #7ee787;
  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 76px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
}
[data-theme="light"] {
  --bg: #f6f4ee;
  --bg-soft: #efede6;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --line: #e2ded2;
  --ink: #191c1a;
  --ink-dim: #3c4247;
  --muted: #6b7280;
  --amber: #d98a06;
  --amber-deep: #b96f00;
  --teal: #0d9488;
  --teal-dim: #0f766e;
}
/* Fitness Mode: ember theme — always visually obvious which mode you're in */
[data-fmode="on"] { --amber: #ff5a1f; --amber-deep: #c73e0c; }
.fmode-badge {
  font-size: 11px; font-weight: 800; letter-spacing: 1px; color: #181204;
  background: var(--amber); border-radius: 999px; padding: 3px 9px; margin-left: 2px;
}
.pbar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.pbar i { display: block; height: 100%; background: var(--amber); border-radius: 999px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 17px; line-height: 1.45;
  overscroll-behavior-y: none;
}
body.bigtype { font-size: 20.5px; }

/* App frame: phone column centered on desktop */
.app {
  max-width: 480px; margin: 0 auto; min-height: 100dvh;
  padding: calc(12px + var(--sat)) 16px calc(var(--tabbar-h) + 24px + var(--sab));
  position: relative;
}
.view { display: none; animation: fadein .22s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- type ---------- */
h1 { font-size: 30px; letter-spacing: -0.5px; margin: 8px 0 4px; font-weight: 700; }
h2 { font-size: 21px; margin: 22px 0 8px; font-weight: 700; }
h3 { font-size: 17px; margin: 16px 0 6px; font-weight: 700; }
p { margin: 8px 0; color: var(--ink-dim); }
.small { font-size: 14px; color: var(--muted); }
.mono-nums { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 2px 10px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 78%, transparent);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; letter-spacing: -0.3px; }
.brand svg { width: 30px; height: 30px; }
.pulse-pill {
  display: flex; align-items: center; gap: 6px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.pulse-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg-soft) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--sab);
}
.tabbar-inner { max-width: 480px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tab {
  border: 0; background: none; color: var(--muted); font-family: var(--font);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px 12px; font-size: 12px; font-weight: 600; min-height: 64px;
}
.tab svg { width: 25px; height: 25px; }
.tab.active { color: var(--amber); }

/* ---------- buttons / chips / inputs ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; border: 0; border-radius: var(--radius);
  font-family: var(--font); font-size: 17px; font-weight: 700;
  background: var(--amber); color: #181204; padding: 14px 18px; cursor: pointer;
}
.btn:active { transform: scale(.985); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.quiet { background: transparent; color: var(--amber); min-height: 44px; width: auto; padding: 8px 12px; }
.btn.danger-ghost { background: transparent; color: var(--red); border: 1px solid var(--line); }
.btn.sm { min-height: 44px; font-size: 15px; border-radius: var(--radius-sm); }
.btnrow { display: flex; gap: 10px; } .btnrow .btn { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 11px 17px; font-size: 16px; font-weight: 600;
  font-family: var(--font); min-height: 48px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: #181204; }
.chip.teal[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: #04231f; }

.field { margin: 12px 0; }
.field label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 14px; font-size: 17px; font-family: var(--font); min-height: 54px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--amber); }
input[type="range"] { width: 100%; min-height: 48px; accent-color: var(--amber); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; cursor: pointer; }
.check:last-child { border-bottom: 0; }
.check input { width: 22px; height: 22px; margin-top: 1px; flex-shrink: 0; accent-color: var(--amber); }
.seg { display: grid; grid-auto-flow: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; color: var(--muted); font-family: var(--font); font-weight: 700; font-size: 15px; padding: 12px 6px; border-radius: 9px; min-height: 48px; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 12px 0;
}
.card h3 { margin-top: 0; }
.statusline { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.statusline .ico { font-size: 19px; }

/* ---------- timer ---------- */
.timer-hero { text-align: center; padding: 10px 0 4px; }
.ring-wrap { position: relative; width: 248px; height: 248px; margin: 6px auto; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.elapsed { font-size: 52px; font-weight: 800; letter-spacing: -1.5px; font-variant-numeric: tabular-nums; line-height: 1; }
.elapsed-label { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 6px; text-transform: uppercase; letter-spacing: 1.5px; }
.next-event { margin-top: 10px; font-size: 16px; color: var(--ink-dim); font-weight: 600; }
.next-event strong { color: var(--amber); }

/* hour timeline */
.timeline { margin: 14px -16px 0; padding: 6px 16px 10px; overflow-x: auto; scrollbar-width: none; }
.timeline::-webkit-scrollbar { display: none; }
.timeline-track { display: flex; gap: 6px; min-width: max-content; padding: 4px 2px; }
.hour-cell {
  width: 44px; flex: 0 0 44px; text-align: center; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); padding: 8px 0 6px; cursor: pointer;
}
.hour-cell .h { font-size: 12px; color: var(--muted); font-weight: 700; }
.hour-cell .bar { height: 26px; margin: 5px 8px 0; border-radius: 6px; background: var(--surface-2); position: relative; overflow: hidden; }
.hour-cell.past .bar { background: var(--amber); opacity: .85; }
.hour-cell.now .bar { background: var(--amber); box-shadow: 0 0 0 2px var(--amber-deep); }
.hour-cell.sleep .h::after { content: " 🌙"; font-size: 10px; }
.hour-cell.milestone .bar::after { content: ""; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.hour-cell[aria-selected="true"] { border-color: var(--amber); }

/* science card */
.science-card { border-left: 4px solid var(--teal); }
.science-card .src { font-size: 13px; color: var(--muted); margin-top: 8px; }
.phase-tag {
  display: inline-block; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--teal); margin-bottom: 4px;
}

/* milestones */
.milestones { display: flex; gap: 8px; margin: 12px 0; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.milestones::-webkit-scrollbar { display: none; }
.mstone {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); padding: 10px 13px; font-size: 14px; font-weight: 700; color: var(--muted);
}
.mstone.hit { color: var(--ink); border-color: var(--teal); }
.mstone.hit::before { content: "✓ "; color: var(--teal); }

/* drink chips + debrief */
.drinkrow { display: flex; gap: 8px; margin: 10px 0; }
.drinkrow .chip { flex: 1; text-align: center; }
.stars { display: flex; gap: 6px; margin: 8px 0; }
.stars button {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-size: 20px; font-weight: 800; color: var(--muted); font-family: var(--font);
}
.stars button[aria-pressed="true"] { background: var(--amber); color: #181204; border-color: var(--amber); }

/* ---------- history ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin: 10px 0; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; position: relative; font-family: var(--font); color: var(--ink);
}
.cal-day .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 3px; background: transparent; }
.cal-day.kept .dot { background: var(--teal); }
.cal-day.partial .dot { background: var(--amber); }
.cal-day.today { border-color: var(--amber); }
.cal-day.other-month { opacity: .32; }
.daystrip { display: flex; height: 34px; border-radius: 10px; overflow: hidden; margin: 10px 0; border: 1px solid var(--line); }
.daystrip .seg-fast { background: #2b2f36; }
.daystrip .seg-eat { background: var(--teal); opacity: .8; }
.daystrip .seg-now { background: var(--amber); }
.stat-row { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: 0; }
.stat-row .v { font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums; }

/* ---------- sheets / modals / toast ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60;
  display: none; opacity: 0; transition: opacity .2s;
}
.scrim.open { display: block; opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; display: none;
  background: var(--bg-soft); border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 10px 20px calc(22px + var(--sab));
  max-height: 88dvh; overflow-y: auto; transform: translateY(24px); transition: transform .22s ease;
}
.sheet.open { display: block; transform: none; }
.sheet-inner { max-width: 480px; margin: 0 auto; }
.grabber { width: 44px; height: 5px; border-radius: 99px; background: var(--line); margin: 6px auto 12px; }
.modal {
  position: fixed; inset: 0; z-index: 61; display: none; align-items: center; justify-content: center; padding: 22px;
}
.modal.open { display: flex; }
.modal-card { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; max-width: 420px; width: 100%; max-height: 84dvh; overflow-y: auto; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(var(--tabbar-h) + 18px + var(--sab));
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 999px; padding: 12px 20px; font-weight: 600; font-size: 15px; z-index: 70;
  opacity: 0; pointer-events: none; transition: all .25s; display: flex; gap: 12px; align-items: center; max-width: 92vw;
}
.toast.open { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.toast button { background: none; border: 0; color: var(--amber); font-weight: 800; font-size: 15px; font-family: var(--font); }

/* ---------- onboarding ---------- */
.onboard { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: none; overflow-y: auto; }
.onboard.open { display: block; }
.onboard-inner { max-width: 480px; margin: 0 auto; padding: calc(20px + var(--sat)) 22px calc(30px + var(--sab)); min-height: 100dvh; display: flex; flex-direction: column; }
.onboard-step { display: none; } .onboard-step.active { display: block; animation: fadein .25s ease; }
.ob-progress { display: flex; gap: 6px; margin: 8px 0 18px; }
.ob-progress i { flex: 1; height: 4px; border-radius: 99px; background: var(--line); }
.ob-progress i.done { background: var(--amber); }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.preset {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 15px 13px; text-align: left; font-family: var(--font); color: var(--ink); cursor: pointer;
}
.preset[aria-pressed="true"] { border-color: var(--amber); box-shadow: 0 0 0 1px var(--amber); }
.preset .t { font-weight: 800; font-size: 18px; }
.preset .d { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* clock ring (schedule paint) */
.ring24 { width: 100%; max-width: 300px; margin: 6px auto; display: block; touch-action: none; }

/* share card */
.share-preview { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); margin: 12px 0; }
.share-preview canvas { width: 100%; display: block; }

/* misc */
.banner {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; margin: 10px 0; font-size: 15px; display: flex; gap: 10px; align-items: flex-start;
}
.banner.warn { border-color: var(--amber); }
.banner .ico { font-size: 19px; flex: 0 0 auto; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; font-size: 16px; }
.kv .k { color: var(--muted); } .kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--amber); color: #000; padding: 10px; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
