:root {
  --bg: #000;
  --card: #1c1c1e;
  --control: #2c2c2e;
  --text: #fff;
  --muted: #8e8e93;
  --separator: #38383a;
  --accent: #00d1dc;
  --green: #30d158;
  color-scheme: dark;
}

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

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Home ---------- */

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

h1 { font-size: 34px; font-weight: 700; margin: 0 4px 12px; letter-spacing: -0.5px; }

h2 { font-size: 20px; font-weight: 600; color: var(--muted); margin: 28px 20px 8px; }

.start {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--accent); color: #000;
  font-weight: 600; font-size: 19px;
  padding: 20px; border-radius: 28px;
}
.start svg { width: 26px; height: 26px; }
.start:active { opacity: 0.8; }

.footnote { color: var(--muted); font-size: 14px; margin: 8px 20px 0; }

.card { background: var(--card); border-radius: 24px; padding: 0 20px; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 60px; padding: 8px 0;
  border-bottom: 1px solid var(--separator);
}
.row:last-child { border-bottom: 0; }
.row b { font-weight: 400; font-variant-numeric: tabular-nums; }

.stepper { display: flex; background: var(--control); border-radius: 20px; flex-shrink: 0; }
.stepper button { width: 52px; height: 36px; font-size: 22px; line-height: 1; }
.stepper button + button { border-left: 1px solid var(--separator); }
.stepper button:active { background: #3a3a3c; }
.stepper button:first-child:active { border-radius: 20px 0 0 20px; }
.stepper button:last-child:active { border-radius: 0 20px 20px 0; }

.segmented { flex: 1; display: flex; background: var(--control); border-radius: 20px; padding: 3px; }
.segmented button { flex: 1; padding: 6px 0; border-radius: 17px; font-size: 15px; }
.segmented button[aria-checked="true"] { background: #636366; font-weight: 600; }
.segmented.compact { flex: 0 0 auto; }
.segmented.compact button { flex: 0 0 auto; padding: 6px 14px; }

.switch {
  appearance: none; -webkit-appearance: none; margin: 0;
  width: 51px; height: 31px; border-radius: 16px;
  background: #39393d; position: relative; flex-shrink: 0;
  transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  transition: transform 0.2s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

.empty { color: var(--muted); padding: 18px 0; }

.history-item { padding: 12px 0; border-bottom: 1px solid var(--separator); display: flex; gap: 12px; align-items: center; }
.history-item:last-child { border-bottom: 0; }
.history-item .info { flex: 1; min-width: 0; }
.history-item .top { display: flex; justify-content: space-between; }
.history-item .times { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.history-item .delete { color: var(--muted); width: 32px; height: 32px; flex-shrink: 0; }
.history-item .delete svg { width: 16px; height: 16px; }

details summary { list-style: none; cursor: pointer; color: var(--accent); }
details summary::-webkit-details-marker { display: none; }
details[open] summary { border-bottom: 1px solid var(--separator); }

.note { color: var(--muted); font-size: 14px; padding: 16px 20px; margin-top: 28px; }
.note b { color: var(--text); font-weight: 600; }
.note p { margin: 6px 0 8px; }
.note ul { margin: 0; padding-left: 18px; }
.note li + li { margin-top: 6px; }
.version { color: var(--muted); font-size: 12px; text-align: center; margin: 16px 0 0; opacity: 0.7; }

.debug {
  position: fixed; left: 8px; right: 8px; z-index: 100;
  bottom: calc(env(safe-area-inset-bottom) + 8px);
  background: rgba(255, 230, 0, 0.94); color: #000;
  font: 12px/1.35 ui-monospace, Menlo, monospace;
  padding: 8px 10px; border-radius: 10px;
  -webkit-user-select: text; user-select: text;
}
.debug pre { margin: 0 0 6px; white-space: pre-wrap; font: inherit; }
.debug button { background: #000; color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 13px; }

/* ---------- Session ---------- */

#session {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(#0d1433, #000);
  overflow: hidden;
}
#session[hidden] { display: none; }

#session header { display: flex; justify-content: space-between; align-items: center; }
#roundLabel { color: rgba(255, 255, 255, 0.7); font-weight: 600; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; stroke-width: 2.5; }

.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 40px; }
.stage[hidden] { display: none; }

.orb-wrap { position: relative; width: min(80vw, 320px); aspect-ratio: 1; display: grid; place-items: center; }
.ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.12); }
.orb { position: absolute; inset: 0; border-radius: 50%; transform: scale(0.5); will-change: transform; }
.layer { position: absolute; inset: 0; border-radius: 50%; opacity: 0; transition: opacity 1.2s ease; }
.layer.breathe { background: radial-gradient(circle, #80f2f2, #0d7399); box-shadow: 0 0 60px rgba(128, 242, 242, 0.45); }
.layer.hold { background: radial-gradient(circle, #8c73ff, #331a80); box-shadow: 0 0 60px rgba(140, 115, 255, 0.45); }
.layer.recover { background: radial-gradient(circle, #ffcc73, #d96633); box-shadow: 0 0 60px rgba(255, 204, 115, 0.45); }

#session:not([data-phase="retention"]):not([data-phase="recovery"]) .layer.breathe,
#session[data-phase="retention"] .layer.hold,
#session[data-phase="recovery"] .layer.recover { opacity: 1; }

.big {
  position: relative;
  font: 300 64px/1 -apple-system, BlinkMacSystemFont, "SF Pro Rounded", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.instruction {
  min-height: 3em; margin: 0; text-align: center;
  font-size: 20px; color: rgba(255, 255, 255, 0.85);
}

.pill {
  background: var(--accent); color: #000; font-weight: 600;
  padding: 14px 36px; border-radius: 999px;
}
.pill:active { opacity: 0.8; }
#breatheIn { visibility: hidden; }
#session[data-phase="retention"] #breatheIn { visibility: visible; }

.summary { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; }
.summary[hidden] { display: none; }
.summary h2 { color: var(--text); font-size: 34px; margin: 0; }
.summary .card { width: 100%; max-width: 360px; font-size: 20px; padding: 6px 20px; }
.summary .card .row { min-height: 48px; }
.summary .card .row span:first-child { color: var(--muted); }
.summary .card .row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.check { width: 64px; height: 64px; color: var(--accent); stroke-width: 1.2; }
