:root {
  --bg: #0f1222;
  --bg2: #171b33;
  --card: #1a1f3a;
  --line: #2a3058;
  --text: #eef0ff;
  --muted: #9aa1c8;
  --fast: #7c8cff;
  --eat: #ffaa5c;
  --ok: #4ade80;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(120% 80% at 50% 0%, #22285a 0%, var(--bg) 60%) fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.app { max-width: 460px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 18px 40px; }
.top { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: .2px; margin: 4px 0; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
.icon-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px; cursor: pointer;
}
.icon-btn.on { border-color: var(--fast); box-shadow: 0 0 0 3px #7c8cff33; }

.clock-wrap { position: relative; width: 100%; max-width: 360px; margin: 10px auto 6px; aspect-ratio: 1; }
#clock { width: 100%; height: 100%; display: block; }
.track { fill: none; stroke: #ffffff10; stroke-width: 18; }
.arc { fill: none; stroke-width: 18; stroke-linecap: round; }
.arc.fast { stroke: url(#gFast); }
.arc.eat { stroke: url(#gEat); }
.arc.plan { opacity: .28; filter: none; }
.ring-track { fill: none; stroke: #ffffff0d; stroke-width: 8; }
.ring { fill: none; stroke: var(--fast); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset .6s ease, stroke .3s; }
.ring.eat { stroke: var(--eat); }
.ring.done { stroke: var(--ok); }
.tick { stroke: #ffffff30; stroke-width: 1.5; }
.tick.major { stroke: #ffffff70; stroke-width: 2; }
.hour { fill: var(--muted); font-size: 10.5px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.now { fill: #fff; }
.now-halo { fill: #ffffff30; }

.center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; pointer-events: none;
}
.phase { font-size: 13px; text-transform: uppercase; letter-spacing: 1.6px; color: var(--muted); font-weight: 700; }
.phase.fast { color: #a9b4ff; }
.phase.eat { color: #ffc28a; }
.timer { font-size: clamp(30px, 10vw, 40px); font-weight: 750; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.sub { font-size: 13px; color: var(--muted); max-width: 60%; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; }
.stat span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.stat b { display: block; font-size: 15px; margin-top: 3px; font-variant-numeric: tabular-nums; }

.stage { background: linear-gradient(135deg, #7c8cff22, #4fc3ff14); border: 1px solid #7c8cff44; border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.stage-name { font-weight: 700; font-size: 14px; }
.stage-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }

.actions { display: flex; gap: 10px; margin-bottom: 16px; }
.btn {
  border: 0; border-radius: 14px; padding: 15px 18px; font-size: 16px; font-weight: 700;
  cursor: pointer; color: var(--text); background: var(--card); transition: transform .08s, filter .2s;
}
.btn:active { transform: scale(.98); }
.btn.primary { flex: 1; background: linear-gradient(135deg, #8b7cff, #4f9dff); box-shadow: 0 8px 24px #5b6cff40; }
.btn.primary.stop { background: linear-gradient(135deg, #ff8a5c, #ff5c8a); box-shadow: 0 8px 24px #ff6c7040; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 9px 14px; font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); border-radius: 999px;
  padding: 8px 14px; font-weight: 650; font-size: 14px; cursor: pointer;
}
.chip.active { background: #7c8cff; border-color: #7c8cff; color: #0b0e1f; }
.custom { margin-top: 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
input, select {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 14px; font-family: inherit;
}
#customFast { width: 72px; margin-left: 6px; }
label { font-size: 14px; color: var(--muted); }
select { margin-left: 6px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.between h2 { margin: 0; }
.daily { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.daily input[type="time"]:disabled { opacity: .4; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--text); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.slider { position: relative; flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line); transition: background .2s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .slider { background: #7c8cff; }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px #7c8cff66; }
.switch-label { font-size: 14px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; line-height: 1.45; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; text-decoration: underline; }

.hstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.hstats div { background: var(--bg2); border-radius: 12px; padding: 8px; text-align: center; }
.hstats b { display: block; font-size: 16px; }
.hstats span { font-size: 11px; color: var(--muted); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { display: flex; justify-content: space-between; align-items: center; padding: 10px 2px; border-top: 1px solid var(--line); font-size: 14px; }
.history li .d { color: var(--muted); font-size: 12px; }
.history .badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #ffffff10; color: var(--muted); }
.history .badge.ok { background: #4ade8022; color: var(--ok); }
.history .empty { color: var(--muted); justify-content: center; border: 0; }

.foot { text-align: center; color: #6b7299; font-size: 12px; margin-top: 18px; }

dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: min(92vw, 360px); }
dialog::backdrop { background: #0008; backdrop-filter: blur(3px); }
dialog h3 { margin: 0 0 14px; font-size: 16px; }
dialog input { width: 100%; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: #262c55; border: 1px solid var(--line); color: var(--text); padding: 12px 16px; border-radius: 14px;
  font-size: 14px; max-width: 90vw; box-shadow: 0 10px 30px #0008; transition: transform .3s ease; z-index: 10;
}
.toast.show { transform: translate(-50%, 0); }
