:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1c211e;
  --muted: #65706a;
  --line: #dfe5e0;
  --accent: #2f6f5e;
  --on-accent: #ffffff;
  --lift: #b4542d;
  --stretch: #2f6f5e;
  --missed: #c9cfca;
  --today-ring: #1c211e;
  --ready: #8a5a00;
  --error: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a18;
    --card: #222724;
    --text: #edf1ee;
    --muted: #9ba69f;
    --line: #353c38;
    --accent: #6cc3a8;
    --on-accent: #0f2a22;
    --lift: #e88a5f;
    --stretch: #6cc3a8;
    --missed: #4a524d;
    --today-ring: #edf1ee;
    --ready: #f0bf5a;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--error); min-height: 1.4em; margin: 0; }

.primary, .secondary {
  display: inline-block; padding: 12px 18px; border-radius: 12px; font-weight: 600; text-align: center; text-decoration: none;
}
.primary { border: 0; background: var(--accent); color: var(--on-accent); }
.secondary { border: 1px solid var(--line); background: var(--card); }
.wide { width: 100%; margin-top: 16px; }
.link { color: var(--accent); background: none; border: 0; padding: 0; text-decoration: none; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: grid; gap: 8px; }

.login { padding-top: 15vh; text-align: center; }
.login form { display: grid; gap: 12px; max-width: 260px; margin: 24px auto 0; }
.login label { color: var(--muted); }
.login input {
  font-size: 1.6rem; text-align: center; letter-spacing: 0.3em;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}

.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 16px; }

.today-label { font-size: 1.15rem; }
.today-status { margin: 4px 0 14px; color: var(--muted); min-height: 1.4em; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  border: 0; border-radius: 14px; padding: 24px 8px; font-size: 1.3rem; font-weight: 700; color: #fff;
  transition: transform 0.08s;
}
.choice:active { transform: scale(0.97); }
.lift { background: var(--lift); }
.stretch { background: var(--stretch); }
@media (prefers-color-scheme: dark) { .choice { color: #111; } }
.choice[aria-pressed="true"]::after, .choice.done::after { content: " ✓"; }

.routines { display: grid; gap: 8px; margin-top: 12px; }
.routine {
  display: flex; justify-content: space-between; align-items: center; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; font-weight: 600;
}
.routine .muted { font-weight: 400; }
.routines .link { justify-self: center; padding: 6px; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.icon-btn {
  width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card); font-size: 1.4rem; line-height: 1;
}
.weekdays, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.weekdays { color: var(--muted); font-size: 0.8rem; margin-bottom: 4px; }
.day {
  aspect-ratio: 1; width: 100%; max-width: 46px; justify-self: center; border: 0; border-radius: 50%; background: none; font-size: 0.95rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.day.outside { opacity: 0.35; }
.day:disabled { color: var(--muted); cursor: default; }
.day.today { box-shadow: inset 0 0 0 2px var(--today-ring); font-weight: 700; }
.day.lift { background: var(--lift); color: #fff; }
.day.stretch { background: var(--stretch); color: #fff; }
.day.both { background: linear-gradient(135deg, var(--lift) 50%, var(--stretch) 50%); color: #fff; }
.day.missed { background: var(--missed); }
@media (prefers-color-scheme: dark) { .day.lift, .day.stretch, .day.both { color: #111; } }
.legend { display: flex; justify-content: center; gap: 16px; margin: 12px 0 4px; font-size: 0.85rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.dot.lift { background: var(--lift); }
.dot.stretch { background: var(--stretch); }
.dot.missed { background: var(--missed); }
#month-count { margin: 4px 0 0; font-size: 0.9rem; }

.reminders p { margin: 6px 0 12px; color: var(--muted); }

.session { display: flex; flex-direction: column; min-height: 100dvh; text-align: center; }
.session-top { display: flex; justify-content: space-between; align-items: center; }
.phase { margin: 28px 0 4px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.session[data-phase="ready"] .phase { color: var(--ready); }
.session[data-phase="paused"] .phase { color: var(--muted); }
.session-name { font-size: 1.8rem; }
.side { margin: 4px 0 0; color: var(--muted); font-size: 1.1rem; min-height: 1.5em; }
.clock { font-size: 5.5rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 12px 0; line-height: 1; }
.session[data-phase="ready"] .clock { color: var(--ready); }
.session[data-phase="paused"] .clock { color: var(--muted); }
.cues { text-align: left; margin: 0 auto 20px; padding-left: 1.3em; max-width: 30em; }
.cues li { margin-bottom: 6px; }
.controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; margin-top: auto; }
.controls button { padding: 16px 8px; }

.finished { text-align: center; padding-top: 20vh; }
.finished p { margin: 12px 0 28px; color: var(--muted); }

fieldset { border: 1px solid var(--line); border-radius: 16px; background: var(--card); margin: 0 0 16px; padding: 8px 16px 12px; }
legend { font-weight: 700; padding: 0 6px; }
.time-field { display: grid; grid-template-columns: 1fr 5em auto; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.time-field:last-child { border-bottom: 0; }
.time-field input { padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); text-align: center; }
.time-field .muted { font-size: 0.85rem; min-width: 6.5em; }

.sheet {
  border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text);
  width: min(92vw, 380px); padding: 20px;
}
.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet h2 { margin-bottom: 14px; }
.sheet label { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.sheet input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.sheet .row { justify-content: flex-end; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
