:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e4e0d8;
  --accent: #1f6f5f;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ec;
  --danger: #b3413a;
  --danger-soft: #f8e5e3;
  --ok: #2f8a4b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.05);
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --text: #f1f0ec;
    --muted: #a3a39c;
    --line: #2f3338;
    --accent: #4fb39b;
    --accent-ink: #0f1b18;
    --accent-soft: #1e332d;
    --danger: #e07b74;
    --danger-soft: #3a2422;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
#app.focus { padding-bottom: 24px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 16px;
}
.topbar h1 { font-size: 1.3rem; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.topbar .brand img { width: 30px; height: 30px; border-radius: 8px; }
.topbar .sub { color: var(--muted); font-size: 0.9rem; }

main { flex: 1; display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.card h2 { margin: 4px 0 8px; font-size: 1.35rem; }
.card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.eyebrow { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 0.9rem; }
p { margin: 6px 0; }

.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 12px 18px;
  border: 0; border-radius: 14px; font-size: 1.05rem; font-weight: 650;
  cursor: pointer; text-decoration: none; touch-action: manipulation; user-select: none;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--accent); min-height: 44px; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { min-height: 40px; font-size: 0.95rem; padding: 8px 12px; width: auto; }
.btn-xl { min-height: 64px; font-size: 1.2rem; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted);
}
.icon-btn:disabled { opacity: 0.35; }
.cta { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* Home mission list */
.missions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mission {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.mission .status {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 0.95rem; flex: none; background: var(--line); color: var(--muted);
}
.mission.completed .status { background: var(--accent); color: var(--accent-ink); }
.mission.in_progress .status { background: #f4d27a; color: #4a3600; }
.mission.completed .name { text-decoration: line-through; color: var(--muted); }
.mission .name { font-weight: 600; }
.mission .meta { color: var(--muted); font-size: 0.85rem; }
.mission.next { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.celebrate { text-align: center; font-size: 1.15rem; font-weight: 600; padding: 12px; }

/* Bottom nav */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
}
.bottomnav .inner { display: flex; width: 100%; max-width: 480px; }
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 0.8rem; font-weight: 600;
}
.bottomnav a .ico { display: flex; }
.bottomnav a.active { color: var(--accent); }

/* Run screens */
.step-label { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.action { font-size: 1.5rem; font-weight: 700; margin: 8px 0 4px; line-height: 1.25; }
.timer-preset { color: var(--muted); font-size: 1rem; }
.clock-wrap { display: flex; flex-direction: column; align-items: center; margin: 8px 0 4px; }
.ring { width: 250px; height: 250px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .track { stroke: var(--line); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.2s linear; }
.ring .clock { position: absolute; inset: 0; display: grid; place-items: center; }
.clock {
  font-size: 3.6rem; font-weight: 700; letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.clock.big { font-size: 4.2rem; margin: 12px 0; }
.clock.done { color: var(--ok); }
.hint { text-align: center; color: var(--muted); }
.gap-label { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: -4px; }
.done-badge {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent);
  border-radius: 99px; padding: 6px 12px; font-weight: 700; font-size: 0.9rem; white-space: nowrap; flex: none;
}
textarea.notes {
  width: 100%; min-height: 130px; resize: vertical; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); margin-top: 8px;
}
textarea.notes:focus { outline: 2px solid var(--accent); border-color: transparent; }
.save-status { font-size: 0.8rem; color: var(--muted); min-height: 1.2em; text-align: right; margin-top: 4px; }
.conn { font-size: 0.75rem; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #c9c9c4; }
.conn.on::before { background: var(--ok); }

.steps-overview { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.steps-overview li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.steps-overview li:first-child { border-top: 0; }
.steps-overview .n {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 0.85rem; font-weight: 700; flex: none;
}
.steps-overview .dur { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary .gap { font-weight: 600; }
.summary .notes-text { white-space: pre-wrap; color: var(--muted); font-size: 0.95rem; margin-top: 4px; }

/* Settings */
.tabs { display: flex; gap: 6px; background: var(--line); padding: 4px; border-radius: 14px; }
.tab {
  flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; cursor: pointer; font-weight: 600; color: var(--muted);
}
.tab small { font-weight: 500; font-size: 0.75rem; }
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.badge { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--accent); }
input.text {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
}
input.text:focus, input.num:focus { outline: 2px solid var(--accent); border-color: transparent; }
.step-editor { display: grid; grid-template-columns: 24px 1fr 40px; gap: 8px; align-items: center; margin-top: 8px; }
.step-editor .n { color: var(--muted); font-size: 0.85rem; font-weight: 700; text-align: center; }
.step-editor .dur { grid-column: 2; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.9rem; }
input.num {
  width: 64px; min-height: 42px; padding: 8px; border-radius: 10px; text-align: center;
  border: 1px solid var(--line); background: var(--bg); font-variant-numeric: tabular-nums;
}
.mission-editor .name-row { margin-top: 8px; }
.unsaved { color: #8a5a00; font-weight: 600; font-size: 0.85rem; }
.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); display: flex; gap: 8px;
  background: var(--bg); padding: 8px 0;
}
.empty { text-align: center; padding: 24px 12px; color: var(--muted); }
.link-box { word-break: break-all; background: var(--bg); border-radius: 10px; padding: 10px; font-size: 0.85rem; }

.error { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: #222; color: #fff; padding: 10px 16px; border-radius: 99px; font-size: 0.95rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25); z-index: 10; max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }

@media (min-width: 640px) {
  #app { max-width: 560px; }
  .bottomnav .inner { max-width: 560px; }
  .ring { width: 300px; height: 300px; }
  .clock { font-size: 4.2rem; }
  .clock.big { font-size: 5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .progress > div, .ring .bar { transition: none; }
}

.party { color: var(--accent); display: flex; justify-content: center; margin: 4px 0 8px; }

/* v2: numbered missions, people chips, mark-done sheet */
.mission .body { min-width: 0; }
.mission .first-step { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  background: #f4d27a; color: #4a3600; border-radius: 99px; padding: 2px 8px; vertical-align: middle; margin-left: 4px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px;
  padding: 10px 16px; min-height: 44px; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on::before { content: "✓ "; }
.early-note {
  margin-top: 10px; background: #fdf3d7; color: #4a3600; border-radius: 12px; padding: 10px 12px; font-size: 0.95rem; text-align: left;
}
@media (prefers-color-scheme: dark) { .early-note { background: #3a2f12; color: #f4d27a; } }
.steps-overview li.faded { opacity: 0.55; }
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.sheet {
  background: var(--card); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
}
.sheet h3 { margin: 0 0 6px; font-size: 1.2rem; }
.sheet textarea.notes { min-height: 80px; margin-top: 6px; }

/* home: tappable done/live missions + play buttons */
.mission .mission-link { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.mission .chev { margin-left: auto; color: var(--accent); font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.mission .play {
  margin-left: auto; flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; touch-action: manipulation;
}
.mission.next .play { background: var(--accent); color: var(--accent-ink); }
.mission .play:disabled { opacity: 0.5; }

/* push alerts */
.alerts h3 { margin-bottom: 4px; }
.alerts-on { color: var(--ok); font-weight: 600; margin: 4px 0; }
.install-steps { padding-left: 20px; margin: 6px 0 0; }
.install-steps li { margin: 2px 0; }
.install-block { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/* breadcrumbs, mission page */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--muted); margin: -6px 0 2px; }
.crumbs a { color: var(--accent); text-decoration: none; font-weight: 600; }
.crumbs span[aria-current] { font-weight: 600; color: var(--text); }
.crumbs .sep { color: var(--line); }
.field { display: block; margin-top: 8px; }
.field-label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
input[type="datetime-local"].text { font-variant-numeric: tabular-nums; }
.done-line { color: var(--ok); font-weight: 600; margin: 0; }
.steps-overview .step-body { flex: 1; min-width: 0; }
.steps-overview li.current .n { background: var(--accent); color: var(--accent-ink); }
.steps-overview li.done .n { background: var(--accent-soft); color: var(--accent); }
.steps-overview .dur { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.steps-overview .dur small { font-size: 0.7rem; color: var(--muted); }
.steps-overview .dur.live .mini-clock { font-weight: 700; color: var(--accent); font-size: 1.05rem; }
.pair-code { font-size: 2.4rem; font-weight: 800; letter-spacing: 0.25em; font-variant-numeric: tabular-nums; margin: 6px 0; }
