:root {
  --bg: #0b1020;
  --bg2: #10172d;
  --card: #141c36;
  --card2: #1a2444;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8ecff;
  --muted: rgba(232, 236, 255, 0.58);
  --accent: #7c8cff;
  --accent2: #4fd1c5;
  --warn: #f6ad55;
  --danger: #f56577;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(120% 60% at 50% -10%, #1b2552 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 6px; letter-spacing: -0.01em; }
h3 { font-size: 13px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 18px; }
.pad { padding: 10px 0; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 12px; }
.gap { gap: 18px; }
.gap-s { gap: 8px; }

.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 18px) 16px calc(var(--safe-b) + 96px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.head { display: flex; align-items: flex-end; gap: 10px; padding: 8px 2px 4px; }
.head.sub { align-items: center; }
.head.sub h1 { font-size: 24px; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 500; margin-bottom: 2px; }
.back { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--card); flex: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: block;
}
.card.empty { text-align: center; padding: 28px 18px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.card.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #0b1020; font-weight: 600;
  padding: 10px 16px; border-radius: 999px; min-height: 40px; white-space: nowrap;
}
.btn .i { width: 17px; height: 17px; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: rgba(245, 101, 119, 0.15); color: var(--danger); }
.link { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-weight: 500; font-size: 14px; }
.link .i { width: 16px; height: 16px; }

/* hero */
.hero { text-align: center; padding: 28px 16px 20px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.start {
  width: 168px; height: 168px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #9aa6ff, #5a68e8 60%, #3d49c4);
  color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 20px; font-weight: 700; letter-spacing: 0.02em;
  box-shadow: 0 0 0 10px rgba(124, 140, 255, 0.10), 0 0 0 22px rgba(124, 140, 255, 0.05), 0 20px 40px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s;
}
.start:active { transform: scale(0.96); }
.start .i { width: 40px; height: 40px; }
.hero-sub { color: var(--muted); font-size: 14px; margin-top: 14px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line);
  font-size: 14px; display: inline-flex; align-items: center; gap: 4px;
}
.chip.on { background: rgba(124, 140, 255, 0.22); border-color: var(--accent); color: #fff; }
.chip.add { color: var(--muted); border-style: dashed; }
.chip .i { width: 15px; height: 15px; }

.tips ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); display: grid; gap: 6px; }
.tips b { color: var(--text); }

/* score */
.ring { position: relative; flex: none; }
.ring svg { width: 100%; height: 100%; }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.08); stroke-width: 10; }
.ring-fg { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray 0.6s; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-label b { line-height: 1; }
.ring-label span { font-size: 11px; color: var(--muted); margin-top: 3px; }
.score-card { display: flex; align-items: center; gap: 18px; }
.score-side { flex: 1; min-width: 0; }
.band { font-weight: 700; font-size: 18px; margin-bottom: 8px; }
.mini-stats { margin: 0; display: grid; gap: 6px; flex: 1; }
.mini-stats div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.mini-stats div:last-child { border-bottom: 0; }
.mini-stats dt { color: var(--muted); font-size: 13px; }
.mini-stats dd { margin: 0; font-weight: 600; font-size: 14px; text-align: right; white-space: nowrap; }
.mini-stats small { color: var(--muted); font-weight: 500; }
.mini-stats.two { margin-top: 8px; }
.night-link { display: flex; flex-direction: column; gap: 12px; }
.night-link .row.gap > .ring { flex: none; }

.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin: 10px 0 12px; background: rgba(255, 255, 255, 0.04); }
.stack i { display: block; min-width: 3px; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 13px; }
.legend span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.legend b { color: var(--text); margin-left: auto; }
.legend em { font-style: normal; color: var(--muted); width: 34px; text-align: right; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend.compact { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; }

canvas { display: block; width: 100%; }
.strip { height: 34px; border-radius: 6px; margin: 10px 0 6px; }
.night-chart { height: 190px; margin-top: 8px; cursor: pointer; touch-action: manipulation; }
.trend-chart { height: 210px; margin: 12px 0 8px; cursor: pointer; }

/* lists */
.list { display: flex; flex-direction: column; gap: 12px; }
.night-row b { font-size: 16px; }
.score-pill { display: flex; flex-direction: column; align-items: flex-end; }
.score-pill b { font-size: 24px; line-height: 1; color: var(--c); }
.score-pill span { font-size: 12px; color: var(--muted); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(124, 140, 255, 0.2); color: var(--accent); vertical-align: 2px; font-weight: 600; }

/* segmented */
.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin: 10px 0 4px; overflow-x: auto; }
.seg button { flex: 1; padding: 7px 8px; border-radius: 9px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card2); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.seg.wide { margin: 0; }

/* clips */
.clip-list { display: flex; flex-direction: column; margin-top: 8px; }
.clip { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.clip:last-child { border-bottom: 0; }
.clip.playing .playbtn { background: #fff; color: var(--bg); }
.playbtn { width: 42px; height: 42px; border-radius: 50%; background: var(--card2); display: grid; place-items: center; flex: none; }
.playbtn .i { width: 18px; height: 18px; fill: currentColor; }
.clip-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.clip-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.tag { color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.wave { height: 26px; }
.clip-tools { display: flex; flex: none; }
.clip-tools button { width: 34px; height: 38px; display: grid; place-items: center; color: var(--muted); }
.clip-tools .i { width: 18px; height: 18px; }
.fav.on { color: #ffd166; }
.fav.on .i { fill: currentColor; }
.archived { margin-top: 10px; color: var(--muted); font-size: 13px; }
.archived summary { cursor: pointer; padding: 6px 0; }
.arch-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 10px; }

textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: vertical; margin-top: 6px;
}
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.rested { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.rested button { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rested b { font-size: 18px; }
.rested span { font-size: 11px; color: var(--muted); }

.warn { color: var(--warn); margin-top: 8px; }

/* trends */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.tile span { color: var(--muted); font-size: 13px; }
.tile b { font-size: 26px; letter-spacing: -0.02em; }
.tile a { color: var(--accent); font-size: 12px; }
.impact { display: flex; flex-direction: column; margin-top: 8px; }
.impact-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.impact-row:last-child { border-bottom: 0; }
.impact-row > div:first-child { display: flex; flex-direction: column; }
.impact-val { font-weight: 700; font-size: 17px; text-align: right; }
.impact-val.better { color: var(--accent2); }
.impact-val.worse { color: var(--danger); }

/* settings */
.form { display: flex; flex-direction: column; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; padding-bottom: 2px; }
.field > div { min-width: 0; }
select { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; max-width: 130px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; transition: 0.2s; }
.switch span::after { content: ''; position: absolute; width: 24px; height: 24px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.link-field .i { color: var(--muted); }
.arch-night { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: rgba(11, 16, 32, 0.86); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(var(--safe-b) + 6px);
}
.tabbar a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabbar a.on { color: var(--text); }
.tabbar a.on svg { stroke: var(--accent); }
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.recording .tabbar, body.recording .view { display: none; }

/* recorder */
.recorder { position: fixed; inset: 0; z-index: 50; background: #05070f; display: flex; }
.rec-inner {
  margin: auto; width: 100%; max-width: 480px; min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: calc(var(--safe-t) + 20px) 22px calc(var(--safe-b) + 24px); text-align: center;
}
.rec-status { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); font-size: 14px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.rec-clock { font-size: 76px; font-weight: 200; letter-spacing: -0.03em; line-height: 1; margin-top: 18px; font-variant-numeric: tabular-nums; }
.rec-elapsed { color: var(--muted); font-variant-numeric: tabular-nums; }
.meter { position: relative; width: 100%; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.06); margin-top: 26px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: #3a4a80; transition: width 0.1s linear; border-radius: 6px; }
.meter-fill.on { background: var(--accent2); }
.meter-thr { position: absolute; top: -2px; bottom: -2px; width: 2px; background: rgba(255, 255, 255, 0.7); }
.meter-cap { font-size: 12px; color: var(--muted); }
.rec-stats { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin-top: 18px; gap: 8px; }
.rec-stats div { background: rgba(255, 255, 255, 0.04); border-radius: 14px; padding: 12px 4px; display: flex; flex-direction: column; }
.rec-stats b { font-size: 26px; font-variant-numeric: tabular-nums; }
.rec-stats span { font-size: 12px; color: var(--muted); }
.rec-last { color: var(--muted); font-size: 14px; min-height: 20px; }
.rec-actions { display: flex; gap: 10px; margin-top: 8px; }
.hold {
  position: relative; overflow: hidden; margin-top: 18px; width: 100%; max-width: 320px; height: 58px; border-radius: 999px;
  background: rgba(245, 101, 119, 0.14); color: var(--danger); font-weight: 700; font-size: 16px;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.hold-fill { position: absolute; inset: 0; width: 0; background: rgba(245, 101, 119, 0.35); }
.hold.holding .hold-fill { width: 100%; transition: width 1.2s linear; }
.hold-text { position: relative; }
.dim-layer { position: fixed; inset: 0; background: #000; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #4a2a2a; }
.recorder.dim .dim-layer { display: flex; }
.dim-clock { font-size: 64px; font-weight: 200; color: #5a2e2e; font-variant-numeric: tabular-nums; }
.dim-layer p { font-size: 12px; color: #3a2020; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 84px); transform: translateX(-50%); z-index: 100;
  background: #eef1ff; color: #0b1020; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

@media (max-width: 380px) {
  .score-card { flex-direction: column; align-items: stretch; }
  .score-card .ring { align-self: center; }
  .legend { grid-template-columns: 1fr; }
  .clip-tools button { width: 30px; }
}
