:root {
  --bg: #0b0c14;
  --bg2: #12142a;
  --card: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.08);
  --fg: #ecebf5;
  --dim: #9896ad;
  --faint: #5e5c73;
  --iso: #b49cff;
  --bin: #6fd6c7;
  --accent: #c8b8ff;
  --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
  color: var(--fg);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) 16px calc(110px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

/* soft drifting light behind everything */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.sky i { position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%; filter: blur(80px); opacity: .18; }
.sky i:first-child { background: var(--iso); left: -30vmax; top: -20vmax; animation: float 38s ease-in-out infinite alternate; }
.sky i:last-child { background: var(--bin); right: -35vmax; bottom: -30vmax; animation: float 46s ease-in-out infinite alternate-reverse; }
@keyframes float { to { transform: translate(12vmax, 8vmax) scale(1.15); } }

main { max-width: 460px; margin: 0 auto; }
header { text-align: center; padding: 28px 0 8px; }
h1 { margin: 0; }
h1 button { background: none; border: 0; font: inherit; font-weight: 300; font-size: 22px; letter-spacing: .5em; text-indent: .5em; color: var(--dim); padding: 6px 12px; cursor: pointer; }
#backdrop { position: absolute; inset: 0; width: 100%; height: 100%; }
#backdrop .link { stroke: #c8b8ff; stroke-width: .1; opacity: .16; }
#backdrop .star { opacity: .5; }
#backdrop .recent { opacity: .8; }
body[data-view="run"] #backdrop { opacity: .5; transition: opacity 2s; }

.view { display: none; animation: in .5s ease both; }
body[data-view="setup"] #setup, body[data-view="run"] #run, body[data-view="done"] #done, body[data-view="history"] #history { display: block; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- setup ---------- */
.hero { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 26px 0 22px; }
.big { display: flex; flex-direction: column; align-items: center; }
.big input[type=number] { width: 3.2ch; font-size: 76px; font-weight: 200; line-height: 1; font-variant-numeric: tabular-nums; }
.big span { color: var(--dim); font-size: 13px; letter-spacing: .2em; text-transform: uppercase; margin-top: 4px; }
.round { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 24px; line-height: 1; cursor: pointer; }
.round:active, .stepper button:active { transform: scale(.94); background: rgba(255, 255, 255, .1); }

input[type=number] { background: none; border: 0; color: var(--fg); text-align: center; font: inherit; padding: 0; -moz-appearance: textfield; appearance: textfield; outline: none; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number]:focus { color: var(--accent); }

.strip { position: relative; display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--line); margin: 0 4px; }
.strip span { height: 100%; }
.strip .iso { background: var(--iso); }
.strip .bin { background: var(--bin); }
.strip .toBin { background: linear-gradient(90deg, var(--iso), var(--bin)); }
.strip .toIso { background: linear-gradient(90deg, var(--bin), var(--iso)); }
.summary { text-align: center; color: var(--dim); font-size: 14px; margin: 12px 0 22px; }
.summary b { font-weight: 500; }
.summary .i { color: var(--iso); } .summary .b { color: var(--bin); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 18px; margin-bottom: 14px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; padding: 4px 0; }
.row + .row { border-top: 1px solid var(--line); }
.levels:empty { display: none; }
.card > .levels { margin: 0 -18px; padding: 0 18px; border-top: 1px solid var(--line); }
.row.col { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 0; }
.lbl { color: var(--fg); font-size: 15px; white-space: nowrap; }
.lbl em { display: block; font-style: normal; color: var(--faint); font-size: 12px; }

.stepper { display: flex; align-items: center; gap: 2px; background: rgba(0, 0, 0, .25); border-radius: 99px; padding: 3px; flex-shrink: 0; }
.stepper button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--dim); font-size: 19px; cursor: pointer; }
.stepper input[type=number] { width: 5.2ch; font-size: 16px; font-variant-numeric: tabular-nums; }
.stepper .unit { color: var(--faint); font-size: 12px; margin-right: 4px; min-width: 2.2ch; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: rgba(0, 0, 0, .25); border-radius: 99px; padding: 3px; }
.seg.small { min-width: 150px; }
.seg.grid { grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); border-radius: 20px; row-gap: 2px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 99px; color: var(--dim); font-size: 14px; transition: background .25s, color .25s; }
.seg input:checked + span { background: rgba(255, 255, 255, .12); color: var(--fg); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.slider { -webkit-appearance: none; appearance: none; width: min(58%, 220px); height: 4px; border-radius: 99px; background: linear-gradient(90deg, var(--accent) var(--p, 50%), var(--line) var(--p, 50%)); outline: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--fg); box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
.slider::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--fg); }

.tune summary { list-style: none; cursor: pointer; padding: 16px 0; color: var(--dim); font-size: 15px; display: flex; justify-content: space-between; }
.tune summary::-webkit-details-marker { display: none; }
.tune summary::after { content: "›"; transform: rotate(90deg); transition: transform .25s; font-size: 20px; line-height: 1; }
.tune[open] summary::after { transform: rotate(-90deg); }
.group { border-top: 1px solid var(--line); padding: 6px 0 4px; }
.group h3 { margin: 12px 0 0; font-size: 11px; font-weight: 500; letter-spacing: .18em; text-transform: uppercase; color: var(--faint); }

.switch { cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 46px; height: 28px; border-radius: 99px; background: rgba(0, 0, 0, .35); position: relative; transition: background .25s; flex-shrink: 0; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--dim); transition: transform .25s, background .25s; }
.switch input:checked + i { background: rgba(200, 184, 255, .35); }
.switch input:checked + i::after { transform: translateX(18px); background: var(--fg); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); }
.link { background: none; border: 0; color: var(--faint); font: inherit; font-size: 13px; padding: 14px 0 10px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- running ---------- */
.orb { position: relative; width: min(78vw, 320px); aspect-ratio: 1; margin: 28px auto 30px; }
.orb svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.orb circle { fill: none; stroke-width: 2.5; }
.orb .track { stroke: var(--line); }
.orb .prog { stroke: var(--iso); stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke .8s; }
body.bin .orb .prog { stroke: var(--bin); }
.breath { position: absolute; inset: 14%; border-radius: 50%; background: radial-gradient(circle, rgba(180, 156, 255, .28), rgba(180, 156, 255, 0) 70%); animation: breathe 11s ease-in-out infinite; transition: background 1.5s; }
body.bin .breath { background: radial-gradient(circle, rgba(111, 214, 199, .26), rgba(111, 214, 199, 0) 70%); }
@keyframes breathe { 0%, 100% { transform: scale(.82); opacity: .6; } 45% { transform: scale(1.08); opacity: 1; } }
.center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#clock { font-size: 58px; font-weight: 200; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
#phase { color: var(--fg); opacity: .8; font-size: 15px; margin-top: 2px; }
#detail { color: var(--faint); font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.strip.live { margin-bottom: 26px; height: 6px; }
.strip.live span { opacity: .55; }
#now { position: absolute; top: -4px; width: 2px; height: 14px; border-radius: 2px; background: var(--fg); box-shadow: 0 0 8px var(--fg); left: 0; }

/* ---------- done ---------- */
#done { text-align: center; padding-top: 60px; }
.doneMark { font-size: 34px; color: var(--accent); opacity: .8; }
#done h2 { font-weight: 300; font-size: 26px; margin: 10px 0 0; }
#done { padding-top: 36px; }
.journal { text-align: left; padding: 14px 16px; }
.journal textarea { width: 100%; min-height: 140px; resize: vertical; background: none; border: 0; outline: none; color: var(--fg); font: inherit; font-size: 16px; line-height: 1.5; }
.journal textarea::placeholder { color: var(--faint); }
.actions { display: flex; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 6px; }
.ghost { flex: 1; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); color: var(--fg); border-radius: 99px; padding: 12px; font: inherit; font-size: 15px; cursor: pointer; transition: background .2s, color .2s; }
.ghost:active { transform: scale(.97); }
.ghost.ok { color: var(--bin); border-color: rgba(111, 214, 199, .4); }
.preview { text-align: left; color: var(--faint); font-size: 13px; margin: 4px 4px 0; }
.preview summary { cursor: pointer; padding: 6px 0; }
.preview pre { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, monospace; color: var(--dim); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 6px 0 0; }

/* ---------- presets ---------- */
.presets { display: flex; justify-content: safe center; gap: 8px; overflow-x: auto; margin: -8px -16px 16px; padding: 2px 16px; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--dim); border-radius: 99px; padding: 7px 14px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background .2s, color .2s, border-color .2s; }
.chip.on { color: var(--fg); background: rgba(200, 184, 255, .16); border-color: rgba(200, 184, 255, .4); }
.chip .x { color: var(--faint); font-size: 15px; line-height: 1; margin-right: -4px; padding: 0 2px; }
.chip.add { border-style: dashed; color: var(--faint); }
.chip:active { transform: scale(.96); }

/* ---------- practice sky ---------- */
svg.starmap { display: block; width: 100%; height: auto; overflow: visible; }
.starmap .empty { fill: var(--fg); opacity: .13; }
.starmap .link { stroke: var(--accent); stroke-width: .7; opacity: .35; }
.starmap .star { fill: #f3efff; }
.starmap .wait { fill: none; stroke: var(--accent); stroke-width: .8; opacity: .7; animation: wait 3s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.starmap .new { animation: born 2.4s cubic-bezier(.2, .8, .2, 1) both; transform-box: fill-box; transform-origin: center; }
@keyframes wait { 50% { opacity: .2; transform: scale(.7); } }
@keyframes born { 0% { transform: scale(0); opacity: 0; } 40% { transform: scale(2.2); opacity: 1; } 100% { transform: scale(1); } }
.pline { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--dim); }
.pline b { color: var(--fg); font-weight: 500; font-size: 15px; }
.pline .more { color: var(--faint); white-space: nowrap; }

#done .starmap { max-width: 300px; margin: 6px auto 18px; }
.streakNote { color: var(--accent); font-size: 14px; margin: -10px 0 22px; min-height: 1em; }

.htitle { font-weight: 300; font-size: 24px; text-align: center; margin: 18px 0 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; }
.stats b { display: block; font-size: 20px; font-weight: 300; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--faint); letter-spacing: .06em; text-transform: uppercase; }
.skycard { padding: 16px; }
.skylegend { display: flex; justify-content: space-between; color: var(--faint); font-size: 11px; margin-top: 8px; }
.entries { list-style: none; padding: 0; margin: 0; }
.entries li { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.entries .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.entries .when { font-size: 14px; }
.entries .meta { color: var(--faint); font-size: 12px; margin-top: 2px; }
.entries .note { color: var(--dim); font-size: 14px; margin-top: 8px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.entries .ghost { flex: 0 0 auto; padding: 6px 14px; font-size: 13px; }
.entries .none { text-align: center; color: var(--faint); background: none; border: 0; }

/* ---------- light view ---------- */
.lightBtn { display: flex; align-items: center; gap: 8px; margin: -8px auto 18px; border: 1px solid var(--line); background: var(--card); color: var(--dim); border-radius: 99px; padding: 8px 16px; font: inherit; font-size: 14px; cursor: pointer; }
.lightBtn .dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(90deg, #f4efff 50%, rgba(244, 239, 255, .25) 50%); animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { background: linear-gradient(90deg, rgba(244, 239, 255, .25) 50%, #f4efff 50%); } }
.lightBtn:active { transform: scale(.96); }
#light { display: none; position: fixed; inset: 0; z-index: 50; background: #000; grid-template-columns: 1fr 1fr; gap: 3vw; cursor: pointer; }
body.lit #light { display: grid; }
body.lit { overflow: hidden; }
#light .eye { position: relative; overflow: hidden; }
#light .eye i { position: absolute; inset: 0; background: #fff4e8; opacity: 0; will-change: opacity; }
.lbar { position: absolute; z-index: 1; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); display: flex; align-items: center; gap: 14px; width: min(92vw, 460px); padding: 10px 12px 10px 20px; border-radius: 99px; background: rgba(20, 20, 32, .85); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; cursor: default; }
.lbar.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.lbar .slider { flex: 1; width: auto; }
.lbar .close { flex: 0 0 auto; padding: 8px 16px; }

/* ---------- action button ---------- */
footer { position: fixed; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 40%); }
.primary { position: relative; overflow: hidden; display: block; width: 100%; max-width: 460px; margin: 0 auto; border: 0; border-radius: 99px; padding: 18px; font-family: inherit; font-size: 17px; font-weight: 500; letter-spacing: .04em; color: #17132b; background: linear-gradient(135deg, #d9ceff, #b49cff); box-shadow: 0 10px 30px rgba(180, 156, 255, .25); cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; }
.primary:active { transform: scale(.985); }
.primary .label { position: relative; z-index: 1; }
body[data-view="run"] .primary { background: rgba(255, 255, 255, .07); color: var(--dim); box-shadow: none; border: 1px solid var(--line); }
.primary .hold { position: absolute; inset: 0; background: rgba(255, 255, 255, .12); transform-origin: left; transform: scaleX(0); }
.primary.holding .hold { transform: scaleX(1); transition: transform .9s linear; }

@media (prefers-reduced-motion: reduce) { .sky i, .breath { animation: none; } }
@media (min-height: 820px) { .hero { margin: 40px 0 30px; } }

/* Playback recovery only appears when audio needs attention. */
#audioStatus { font-size: 14px; color: var(--fg); margin: 0 0 10px; text-align: center; }
#resumeAudio { margin-bottom: 10px; width: 100%; }
#go:disabled { opacity: .65; cursor: wait; }
