:root {
  color-scheme: dark;
  --bg: #0b0d0f;
  --bg-elev: #111519;
  --card: #151a1f;
  --card-hi: #1c2229;
  --surface: #1e252d;
  --border: #252e37;
  --border-hi: #35424f;
  --specular: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45), inset 0 1px 0 var(--specular);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.38), inset 0 1px 0 var(--specular);
  --text: #edf0f3;
  --text-2: #b8c1cb;
  --muted: #7f8b98;

  --sage: #7fb08a;
  --sage-hi: #92c49d;
  --sage-ink: #08120a;
  --sage-dim: rgba(127, 176, 138, 0.14);
  --sage-ring: rgba(127, 176, 138, 0.36);

  --amber: #d8a66c;
  --amber-hi: #e5b77f;
  --amber-dim: rgba(216, 166, 108, 0.14);
  --amber-ring: rgba(216, 166, 108, 0.38);

  --sky: #7ba9c4;
  --sky-dim: rgba(123, 169, 196, 0.14);
  --sky-ring: rgba(123, 169, 196, 0.36);

  --rose: #d47d7d;
  --rose-dim: rgba(212, 125, 125, 0.14);
  --rose-ring: rgba(212, 125, 125, 0.38);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f5f3;
  --bg-elev: #e8efeb;
  --card: #ffffff;
  --card-hi: #f5f9f6;
  --surface: #edf2ef;
  --border: #d2ddd6;
  --border-hi: #afc3b8;
  --specular: rgba(255, 255, 255, 0.85);
  --shadow-sm: 0 1px 2px rgba(15, 31, 24, 0.06), inset 0 1px 0 var(--specular);
  --shadow-md: 0 8px 22px rgba(15, 31, 24, 0.08), inset 0 1px 0 var(--specular);
  --text: #101e19;
  --text-2: #2e423b;
  --muted: #566b63;

  --sage: #0f766e;
  --sage-hi: #0d645d;
  --sage-ink: #ffffff;
  --sage-dim: rgba(15, 118, 110, 0.11);
  --sage-ring: rgba(15, 118, 110, 0.32);

  --amber: #b45309;
  --amber-hi: #9a4507;
  --amber-dim: rgba(180, 83, 9, 0.11);
  --amber-ring: rgba(180, 83, 9, 0.32);

  --sky: #0369a1;
  --sky-dim: rgba(3, 105, 161, 0.11);
  --sky-ring: rgba(3, 105, 161, 0.32);

  --rose: #be123c;
  --rose-dim: rgba(190, 18, 60, 0.1);
  --rose-ring: rgba(190, 18, 60, 0.3);
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px; line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: 92px; }

.wrap { max-width: 820px; margin: 0 auto; padding: 14px 16px 24px; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* View Transitions */
@keyframes vtFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes vtFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
::view-transition-old(root) { animation: 150ms cubic-bezier(0.4, 0, 1, 1) both vtFadeOut; }
::view-transition-new(root) { animation: 230ms var(--ease-spring) both vtFadeIn; }

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -12px) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes sheetIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes checkPop {
  0% { transform: scale(0.82); }
  55% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes pulseHalo {
  0%, 100% { opacity: 0.22; }
  50% { opacity: 0.48; }
}

/* Icons */
.ico { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.85; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.ico-lg { width: 20px; height: 20px; }

/* Razor-Sharp Button System */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
  line-height: 1.2; white-space: nowrap;
  color: var(--text); background: var(--card-hi);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 14px; min-height: 38px;
  box-shadow: var(--shadow-sm);
  cursor: pointer; user-select: none;
  transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), color 140ms var(--ease-out), transform 110ms var(--ease-out), box-shadow 140ms var(--ease-out);
}
button:hover, .btn:hover { background: var(--surface); border-color: var(--border-hi); }
button:active, .btn:active { transform: translateY(1px) scale(0.98); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--sage); outline-offset: 2px;
}

.btn-primary {
  background: var(--sage); color: var(--sage-ink);
  border-color: var(--sage);
  box-shadow: 0 2px 10px var(--sage-dim), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.btn-primary:hover { background: var(--sage-hi); border-color: var(--sage-hi); }

.btn-amber {
  background: var(--amber-dim); color: var(--amber);
  border-color: var(--amber-ring);
}
.btn-amber:hover { background: rgba(216, 166, 108, 0.22); border-color: var(--amber); color: var(--amber-hi); }
[data-theme="light"] .btn-amber:hover { background: rgba(180, 83, 9, 0.17); color: var(--amber-hi); }

.btn-rose {
  background: var(--rose-dim); color: var(--rose);
  border-color: var(--rose-ring);
}
.btn-rose:hover { background: rgba(212, 125, 125, 0.22); border-color: var(--rose); }

.btn-ghost {
  background: transparent; border-color: transparent;
  color: var(--muted); box-shadow: none;
}
.btn-ghost:hover { background: var(--card-hi); border-color: var(--border); color: var(--text); }

.btn-sm { padding: 6px 11px; min-height: 34px; font-size: 12.5px; border-radius: 8px; }
.btn-icon {
  padding: 0; width: 38px; height: 38px; min-height: 38px;
  border-radius: 9px;
}

/* Top Bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0 14px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: grid; place-items: center; flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 17px; font-weight: 750; letter-spacing: -0.025em; margin: 0; line-height: 1.15; }
.brand-text small { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-top: 14px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-title {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 0;
  display: inline-flex; align-items: center; gap: 6px;
}

/* Stats Grid */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px; margin-top: 14px;
}
.stat-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 13px;
  box-shadow: var(--shadow-sm);
}
.stat-val { font-size: 20px; font-weight: 750; letter-spacing: -0.03em; line-height: 1.15; }
.stat-lbl { font-size: 11px; color: var(--muted); margin-top: 4px; font-weight: 500; }
.stat-val.accent-sage { color: var(--sage); }
.stat-val.accent-amber { color: var(--amber); }

/* Capacity / Burnout Guard */
.cap-bar-wrap {
  height: 8px; border-radius: 999px; background: var(--bg-elev);
  border: 1px solid var(--border); overflow: hidden; display: flex;
}
.cap-focus { background: var(--sage); transition: width 320ms var(--ease-spring); }
.cap-rest { background: var(--sky); transition: width 320ms var(--ease-spring); }
.cap-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.cap-warn {
  margin-top: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--amber-dim); border: 1px solid var(--amber-ring);
  color: var(--amber); font-size: 12.5px; display: flex; align-items: center; gap: 8px;
}

/* Tough Day Banner */
.tough-banner {
  margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--sage-dim); border: 1px solid var(--sage-ring);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 13px; color: var(--text);
}

/* Timer Hero */
.timer-shell {
  display: grid; grid-template-columns: 184px minmax(0, 1fr);
  gap: 20px; align-items: center;
}
.ring-box {
  position: relative; width: 176px; height: 176px; margin: 0 auto;
  display: grid; place-items: center;
}
.ring-halo {
  position: absolute; inset: 12px; border-radius: 50%;
  background: radial-gradient(circle, var(--sage-dim) 0%, transparent 70%);
  opacity: 0; pointer-events: none; transition: opacity 300ms ease;
}
.ring-box.running .ring-halo { animation: pulseHalo 2.6s ease-in-out infinite; }
.ring-box svg { width: 176px; height: 176px; transform: rotate(-90deg); position: relative; z-index: 1; }
.ring-bg { fill: none; stroke: var(--bg-elev); stroke-width: 9; }
.ring-fg {
  fill: none; stroke: var(--sage); stroke-width: 9; stroke-linecap: round;
  transition: stroke-dashoffset 450ms var(--ease-spring), stroke 250ms ease;
}
.ring-center { position: absolute; z-index: 2; text-align: center; }
.timer-time { font-size: 34px; font-weight: 750; letter-spacing: -0.04em; line-height: 1.05; }
.timer-phase {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--sage); margin-top: 5px;
}

.timer-meta { min-width: 0; }
.timer-meta h2 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.02em;
  margin: 0 0 4px; line-height: 1.3; word-break: break-word;
}
.timer-next { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.timer-controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* Ambient Audio Strip */
.ambient-strip {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.seg-group {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 9px; padding: 3px;
}
.seg-btn {
  border: 1px solid transparent; background: transparent; box-shadow: none;
  color: var(--muted); padding: 5px 10px; min-height: 28px;
  font-size: 12px; font-weight: 600; border-radius: 6px;
}
.seg-btn:hover { color: var(--text); background: transparent; border-color: transparent; }
.seg-btn.active {
  background: var(--card-hi); color: var(--text);
  border-color: var(--border-hi); box-shadow: var(--shadow-sm);
}
.vol-wrap { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.vol-wrap input[type="range"] { width: 84px; accent-color: var(--sage); cursor: pointer; }

/* Quick Add Bar */
.quick-add {
  display: grid; grid-template-columns: minmax(0, 1fr) 86px 68px auto;
  gap: 8px; margin-bottom: 12px;
}
.quick-add input { padding: 9px 11px; min-height: 40px; }

/* Task List */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md);
  background: var(--bg-elev); border: 1px solid var(--border);
  transition: border-color 150ms var(--ease-out), background-color 150ms var(--ease-out), opacity 180ms ease;
}
.task-item:hover { border-color: var(--border-hi); }
.task-item.active {
  border-color: var(--sage); background: var(--card-hi);
  box-shadow: 0 0 0 1px var(--sage-ring);
}
.task-item.done { opacity: 0.52; }
.task-item.done .task-name { text-decoration: line-through; color: var(--muted); }
.task-item.is-break {
  margin-left: 18px; padding: 8px 11px;
  border-style: dashed; border-color: var(--sky-ring);
  background: var(--sky-dim);
}

/* 44px Accessible Check Target */
.chk-wrap {
  width: 40px; height: 40px; margin: -6px 0 -6px -6px;
  display: grid; place-items: center; flex-shrink: 0;
  background: transparent; border: none; box-shadow: none; padding: 0; border-radius: 10px;
}
.chk-wrap:hover { background: var(--card-hi); border: none; }
.chk-box {
  width: 22px; height: 22px; border-radius: 7px;
  border: 2px solid var(--border-hi); background: var(--card);
  display: grid; place-items: center; color: transparent;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out);
}
.task-item.done .chk-box {
  background: var(--sage); border-color: var(--sage); color: var(--sage-ink);
  animation: checkPop 240ms var(--ease-spring);
}

.task-body { flex: 1; min-width: 0; cursor: pointer; padding: 2px 0; }
.task-name { font-size: 14px; font-weight: 600; color: var(--text); word-break: break-word; line-height: 1.35; }
.task-sub {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted); margin-top: 4px;
}
.task-actions { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.act-btn {
  width: 34px; height: 34px; min-height: 34px; padding: 0;
  background: transparent; border-color: transparent; box-shadow: none;
  color: var(--muted); border-radius: 8px;
}
.act-btn:hover { background: var(--card-hi); border-color: var(--border); color: var(--text); }
.act-btn.del:hover { color: var(--rose); border-color: var(--rose-ring); background: var(--rose-dim); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 6px; font-size: 10.5px;
  font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase;
}
.b-easy { background: var(--sage-dim); color: var(--sage); }
.b-medium { background: var(--amber-dim); color: var(--amber); }
.b-hard { background: var(--rose-dim); color: var(--rose); }
.b-rest, .b-break { background: var(--sky-dim); color: var(--sky); }
.b-challenge { background: var(--amber-dim); color: var(--amber); border: 1px solid var(--amber-ring); }
.b-now { background: var(--sage); color: var(--sage-ink); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-full { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-2); }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 14px;
  color: var(--text); background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 11px; min-height: 40px;
  transition: border-color 140ms var(--ease-out), background-color 140ms var(--ease-out);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-hi); }
textarea { resize: vertical; min-height: 78px; }

/* Week & Packs Tab */
.day-pills { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.day-pill {
  flex: 1; min-width: 68px; flex-direction: column; gap: 2px;
  padding: 8px 10px; min-height: 48px;
}
.day-pill.active {
  background: var(--sage-dim); border-color: var(--sage); color: var(--sage);
}
.pack-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pack-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  transition: border-color 150ms var(--ease-out);
}
.pack-card:hover { border-color: var(--border-hi); }
.pack-card h4 { margin: 0 0 4px; font-size: 14.5px; font-weight: 700; }
.pack-card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* Heatmap & History */
.heatmap { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 6px; margin: 10px 0 6px; }
.hm-cell {
  aspect-ratio: 1; border-radius: 6px; background: var(--bg-elev);
  border: 1px solid var(--border); position: relative;
}
.hm-cell.lvl-1 { background: rgba(127, 176, 138, 0.22); border-color: rgba(127, 176, 138, 0.35); }
.hm-cell.lvl-2 { background: rgba(127, 176, 138, 0.5); border-color: rgba(127, 176, 138, 0.65); }
.hm-cell.lvl-3 { background: var(--sage); border-color: var(--sage); }

.rate-row { display: flex; gap: 8px; }
.rate-btn { flex: 1; min-height: 44px; font-size: 15px; font-weight: 700; }
.rate-btn.selected {
  background: var(--sage); color: var(--sage-ink); border-color: var(--sage);
}

.hist-item {
  padding: 11px 13px; border-radius: var(--radius-md);
  background: var(--bg-elev); border: 1px solid var(--border);
  margin-bottom: 8px;
}
.hist-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.hist-text { margin-top: 5px; font-size: 13.5px; color: var(--text); }

/* Bottom Navigation */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.nav-btn {
  flex-direction: column; gap: 3px; padding: 6px 4px; min-height: 50px;
  font-size: 11px; font-weight: 650; border-radius: 10px;
  background: transparent; border-color: transparent; box-shadow: none;
  color: var(--muted);
}
.nav-btn:hover { background: var(--card-hi); color: var(--text); border-color: transparent; }
.nav-btn.active {
  background: var(--sage-dim); color: var(--sage);
  border-color: var(--sage-ring);
}

/* Toast with Undo */
.toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 80; display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-radius: 11px;
  background: var(--card-hi); color: var(--text);
  border: 1px solid var(--border-hi); box-shadow: var(--shadow-md);
  font-size: 13px; font-weight: 600; max-width: calc(100vw - 24px);
  animation: toastIn 220ms var(--ease-spring) both;
}

/* Modal Sheet */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(5, 7, 9, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.modal-sheet {
  width: 100%; max-width: 480px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--card); border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg); padding: 18px 18px 0;
  box-shadow: var(--shadow-md);
  animation: sheetIn 220ms var(--ease-spring) both;
}
.modal-foot {
  position: sticky; bottom: 0;
  background: var(--card);
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 14px; padding: 12px 0 16px;
  border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timer-shell { grid-template-columns: 1fr; text-align: center; }
  .timer-controls { justify-content: center; }
  .quick-add { grid-template-columns: 1fr 1fr; }
  .quick-add input:first-child { grid-column: 1 / -1; }
  .pack-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .task-item.is-break { margin-left: 10px; }
}

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

/* v2.1 Setup & Editable Week Additions */
.setup-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
}
.setup-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
}
.starter-opt {
  text-align: left; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 11px 12px; height: auto; white-space: normal;
}
.starter-opt.selected {
  background: var(--sage-dim); border-color: var(--sage); color: var(--text);
}
.starter-opt strong { font-size: 13.5px; }
.starter-opt span { font-size: 11.5px; color: var(--muted); font-weight: 450; }
@media (max-width: 540px) {
  .setup-grid { grid-template-columns: 1fr; }
}

/* v2.2 Editable Time Pill & Timer Nudge */
.time-pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 6px; border-radius: 5px;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer;
  transition: border-color 140ms var(--ease-out), color 140ms var(--ease-out);
}
.time-pill:hover { border-color: var(--sage); color: var(--sage); }
