:root {
  --bg: #0d0f1a;
  --bg-glow: #1a1d33;
  --fg: #eceaf4;
  --muted: #8d8fa6;
  --surface: #171a2b;
  --line: #262a42;
  --idle: #b9b4e6;
  --hold: #ff8f70;
  --rest: #7fb0ff;
  --done: #8fd9b0;
  --on-accent: #10121d;
  --accent: var(--idle);
  --t: 1000ms;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f3ee;
    --bg-glow: #ffffff;
    --fg: #1d1c26;
    --muted: #77748a;
    --surface: #ffffff;
    --line: #e4dfd6;
    --idle: #8f88cf;
    --hold: #f0714f;
    --rest: #4f8fe8;
    --done: #3fae7a;
    --on-accent: #ffffff;
    color-scheme: light;
  }
}

body[data-phase="prep"] { --accent: var(--idle); }
body[data-phase="hold"] { --accent: var(--hold); }
body[data-phase="rest"] { --accent: var(--rest); }
body[data-phase="done"] { --accent: var(--done); }

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 24px env(safe-area-inset-bottom);
  background: radial-gradient(120% 70% at 50% 38%, var(--bg-glow), var(--bg) 70%) var(--bg);
  color: var(--fg);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  flex: none;
}

h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible, .switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 3px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  border-radius: 50%;
  color: var(--muted);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 4vh, 36px);
  min-height: 0;
}

.label {
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--accent);
  transition: color 500ms ease;
}

.stage {
  position: relative;
  width: min(78vw, 44dvh, 340px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring-track { stroke: var(--line); }
.ring-bar {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 904.78;
  stroke-dashoffset: 904.78;
  transition: stroke 500ms ease;
}

.orb {
  position: relative;
  width: 80%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background-color: var(--accent);
  box-shadow:
    0 0 70px -8px color-mix(in srgb, var(--accent) 55%, transparent),
    inset 0 -18px 40px -12px rgb(0 0 0 / 0.22);
  transition:
    transform var(--t) cubic-bezier(0.45, 0, 0.2, 1),
    background-color 500ms ease,
    box-shadow 500ms ease;
}

.orb::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, rgb(255 255 255 / 0.5), transparent 55%);
}

.orb.squeezed { transform: scale(0.66); }

body[data-status="idle"] .orb { animation: breathe 5s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(0.95); } }

.count {
  position: relative;
  font-size: clamp(56px, 20vw, 88px);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--on-accent);
  transition: transform var(--t) cubic-bezier(0.45, 0, 0.2, 1);
}
/* keep number readable while the orb shrinks */
.orb.squeezed .count { transform: scale(1.3); }

.sub {
  min-height: 1.4em;
  font-size: 15px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

footer {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 20px;
}

.main-btn {
  width: 100%;
  max-width: 340px;
  height: 58px;
  border-radius: 29px;
  background: var(--fg);
  color: var(--bg);
  font-size: 17px;
  font-weight: 600;
  transition: transform 120ms ease, opacity 200ms ease;
}
.main-btn:active { transform: scale(0.97); }

.ghost-btn {
  height: 44px;
  padding: 0 20px;
  font-size: 15px;
  color: var(--muted);
  transition: opacity 200ms ease;
}
body[data-status="idle"] .ghost-btn { opacity: 0; pointer-events: none; }

.today { display: flex; align-items: center; gap: 8px; height: 20px; font-size: 12px; color: var(--muted); }
.today i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); }
.today i.on { background: var(--done); border-color: var(--done); }

/* settings sheet */
dialog {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 10px 24px calc(24px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  color: var(--fg);
  overflow-y: auto;
}
dialog[open] { animation: rise 280ms cubic-bezier(0.2, 0.8, 0.2, 1); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
@keyframes rise { from { transform: translateY(100%); } }

.grabber { width: 36px; height: 4px; margin: 0 auto 18px; border-radius: 2px; background: var(--line); }
h2 { font-size: 20px; font-weight: 600; margin-bottom: 20px; }

.field { margin-bottom: 18px; }
.field > span { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chips button {
  height: 46px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.chips button[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--surface); font-weight: 600; }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  font-size: 16px;
  border-top: 1px solid var(--line);
}
.switch input { position: absolute; opacity: 0; }
.switch i { position: relative; width: 48px; height: 28px; border-radius: 14px; background: var(--line); transition: background-color 200ms ease; }
.switch i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 200ms ease;
}
.switch input:checked + i { background: var(--done); }
.switch input:checked + i::after { transform: translateX(20px); }

.hint { margin: 14px 0 20px; font-size: 13px; line-height: 1.5; color: var(--muted); }
dialog .main-btn { max-width: none; }

@media (max-height: 560px) {
  header { height: 48px; }
  footer { padding-bottom: 8px; }
  .main-btn { height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb, .count { transition-duration: 1ms; }
  body[data-status="idle"] .orb { animation: none; }
  dialog[open] { animation: none; }
}
