:root {
  color-scheme: dark light;
  --bg: #0b1220;
  --bg-soft: #121b2e;
  --card: #141d31;
  --line: #26324a;
  --text: #e9eefb;
  --muted: #93a2bd;
  --accent: #6f9bff;
  --ok: #34d399;
  --warn: #fbbf24;
  --cool: #38bdf8;
  --deep: #a78bfa;
  --phase: var(--muted);
  --radius: 16px;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- 설치 안내 ---------- */
.install {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.install p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.install b { color: var(--text); font-weight: 700; }
.install-acts { display: flex; gap: 12px; white-space: nowrap; }
.install .link.mute { color: var(--muted); }
.app.is-standalone .install, .app.is-standalone .only-web { display: none; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.topbar h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.tabs {
  display: flex; gap: 4px; margin-bottom: 14px; padding: 3px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 999px;
}
.tab {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  flex: 1; min-height: 38px;
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 7px 10px; border-radius: 999px; cursor: pointer;
}
.tab.is-on { background: var(--accent); color: #08122b; }

main { flex: 1; }
.panel { display: flex; flex-direction: column; gap: 16px; }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.dial {
  appearance: none; border: 0; padding: 0; background: transparent; color: inherit;
  position: relative; width: min(84vw, 320px); aspect-ratio: 1; cursor: pointer;
  display: grid; place-items: center;
  touch-action: manipulation;
}
.stage.plain .dial-inner { position: static; padding: 26px 0 6px; }

.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring-bg { stroke: var(--line); }
.ring-fg {
  stroke: var(--phase);
  stroke-dasharray: 565.49;
  stroke-dashoffset: 565.49;
  transition: stroke-dashoffset .18s linear, stroke .3s ease;
}

.dial-inner { position: relative; text-align: center; display: grid; gap: 2px; }
.phase { font-size: 15px; font-weight: 700; letter-spacing: .06em; color: var(--phase); }
.clock {
  font-size: clamp(52px, 17vw, 76px); font-weight: 700; line-height: 1.05;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.counter { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta .dot { margin: 0 6px; opacity: .6; }

/* phase colours */
.stage[data-phase="prepare"] { --phase: var(--warn); }
.stage[data-phase="work"]    { --phase: var(--ok); }
.stage[data-phase="rest"]    { --phase: var(--cool); }
.stage[data-phase="setRest"] { --phase: var(--deep); }
.stage[data-phase="done"]    { --phase: var(--accent); }
.stage[data-phase="ready"]   { --phase: var(--accent); }
.stage[data-phase="work"] .clock { color: var(--ok); }
.stage[data-phase="done"] .clock { color: var(--accent); }
.stage[data-phase="ready"] .clock { color: var(--accent); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.stage.is-paused .clock { animation: pulse 1.4s ease-in-out infinite; }

/* ---------- controls ---------- */
.controls { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 10px; }
.controls.one { grid-template-columns: 1fr; }
.controls.two { grid-template-columns: 1fr 1fr; }
.controls.one .btn, .controls.two .btn { min-height: 60px; font-size: 17px; }
.btn {
  appearance: none; font: inherit; font-weight: 700; cursor: pointer;
  min-height: 52px; padding: 0 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08122b; }
.btn.ghost { color: var(--muted); }
.btn[disabled] { opacity: .4; cursor: default; }
.btn.wide { width: 100%; }

/* ---------- setup ---------- */
.app.is-focus .setup { display: none; }

.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.block + .block { margin-top: 12px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.block-head h2 { margin: 0; font-size: 14px; color: var(--muted); font-weight: 700; letter-spacing: .02em; }
.hint { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.link { appearance: none; border: 0; background: none; padding: 0; font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); cursor: pointer; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  appearance: none; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 9px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
}
.preset.is-on { border-color: var(--accent); color: var(--accent); }
.preset small { color: var(--muted); font-weight: 500; }
.preset .x { color: var(--muted); font-size: 15px; line-height: 1; padding: 0 2px; }

.fields { display: grid; gap: 8px; }
.field { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; }
.field-name { font-size: 15px; font-weight: 600; }
.field-unit { font-size: 13px; color: var(--muted); width: 32px; }
.stepper { display: inline-flex; align-items: center; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.step {
  appearance: none; border: 0; background: transparent; color: var(--text);
  width: 44px; height: 44px; font-size: 20px; line-height: 1; cursor: pointer;
  touch-action: manipulation;
}
.step:active { background: var(--line); }
.stepper input {
  appearance: none; border: 0; background: transparent; color: var(--text);
  width: 58px; height: 44px; text-align: center;
  font: inherit; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.stepper input:focus { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
.field.is-off { opacity: .45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  appearance: none; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
}
.chip.is-on { border-color: var(--accent); color: var(--accent); }

.toggles { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; min-height: 32px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.note { margin: 12px 0 0; font-size: 12px; line-height: 1.6; color: var(--muted); }
.note b { color: var(--text); font-weight: 600; }

/* ---------- laps ---------- */
.laps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.laps li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-variant-numeric: tabular-nums; font-size: 15px;
}
.laps li span:first-child { color: var(--muted); }

/* ---------- footer ---------- */
.foot { margin-top: 20px; font-size: 13px; color: var(--muted); }
.foot summary { cursor: pointer; padding: 6px 0; }
.foot ol { margin: 6px 0 0; padding-left: 20px; line-height: 1.7; }
.foot b { color: var(--text); }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb; --bg-soft: #eef1f8; --card: #ffffff; --line: #dde3f0;
    --text: #101725; --muted: #5b6982; --accent: #2a5fd6;
    --ok: #0f9d63; --warn: #b4780b; --cool: #0b82c4; --deep: #6d46d6;
  }
  .btn.primary, .tab.is-on { color: #ffffff; }
}
