:root {
  --bg: #0a0f1c;
  --card: #121a2e;
  --card-2: #18223a;
  --line: rgb(255 255 255 / 0.08);
  --text: #eef1f8;
  --muted: #8f9ab7;
  --faint: #5f6a88;
  --calm: 121 214 195;   /* rgb triplets so we can vary alpha */
  --warm: 255 196 122;
  --alert: 255 143 126;
  --off: 74 86 120;
  --ok: #6fdc9b;
  --bad: #ff7a6e;
  --radius: 22px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(120% 55% at 50% -5%, #1a2650 0%, rgb(26 38 80 / 0) 70%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 17px; letter-spacing: 0.2px; }
.brand svg { width: 20px; height: 20px; fill: rgb(var(--warm)); }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 999px;
  background: rgb(255 255 255 / 0.05); box-shadow: inset 0 0 0 1px var(--line);
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.chip[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.chip[data-state="warn"] .dot { background: rgb(var(--warm)); }
.chip[data-state="bad"] .dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); }

.banner {
  margin: 12px 0 0; padding: 12px 14px; border-radius: 14px;
  background: rgb(var(--alert) / 0.12); box-shadow: inset 0 0 0 1px rgb(var(--alert) / 0.35);
  color: #ffd2cb; font-size: 14px; line-height: 1.4;
}

/* hero: the sound orb */
.hero { text-align: center; padding: 18px 0 8px; }
.orb { --lvl: 0; --c: var(--calm); position: relative; width: min(60vw, 228px); aspect-ratio: 1; margin: 6px auto 22px; }
.orb[data-state="sound"] { --c: var(--warm); }
.orb[data-state="noise"] { --c: var(--alert); }
.orb[data-state="off"] { --c: var(--off); }
.orb-glow {
  position: absolute; inset: -22%; border-radius: 50%;
  background: radial-gradient(closest-side, rgb(var(--c) / 0.42), rgb(var(--c) / 0));
  opacity: calc(0.35 + var(--lvl) * 0.65);
  transform: scale(calc(0.8 + var(--lvl) * 0.38));
  transition: transform 0.15s linear, opacity 0.15s linear;
}
.orb-ring {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgb(var(--c) / 0.55), 0 0 0 1px rgb(var(--c) / 0.12);
  transform: scale(calc(1 + var(--lvl) * 0.14));
  transition: transform 0.12s linear;
}
.orb[data-state="noise"] .orb-ring { animation: ring 1.4s ease-out infinite; }
@keyframes ring { 0% { box-shadow: inset 0 0 0 2px rgb(var(--c) / 0.7), 0 0 0 0 rgb(var(--c) / 0.45); } 100% { box-shadow: inset 0 0 0 2px rgb(var(--c) / 0.7), 0 0 0 26px rgb(var(--c) / 0); } }
.orb-core {
  position: absolute; inset: 13%; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 34% 28%, #23315c, #10182c 72%);
  box-shadow: inset 0 0 0 1px var(--line), 0 24px 60px rgb(0 0 0 / 0.5);
}
.ico { grid-area: 1 / 1; width: 38%; height: 38%; transition: opacity 0.3s, transform 0.3s; }
.ico-moon { fill: rgb(var(--c)); }
.ico-wave { fill: none; stroke: rgb(var(--c)); stroke-width: 2.2; stroke-linecap: round; opacity: 0; transform: scale(0.8); }
.orb[data-state="sound"] .ico-moon, .orb[data-state="noise"] .ico-moon { opacity: 0; transform: scale(0.8); }
.orb[data-state="sound"] .ico-wave, .orb[data-state="noise"] .ico-wave { opacity: 1; transform: scale(1); }

.hero h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.3px; font-variant-numeric: tabular-nums; }
.hero p { margin: 8px auto 0; max-width: 32ch; color: var(--muted); font-size: 15px; line-height: 1.4; min-height: 21px; }

/* main button */
.listen {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 62px; margin-top: 18px; border: 0; border-radius: 999px;
  font-size: 19px; font-weight: 650; color: #241606;
  background: linear-gradient(180deg, #ffd9a3, #ffb45e);
  box-shadow: 0 12px 32px rgb(255 180 94 / 0.22), inset 0 1px 0 rgb(255 255 255 / 0.5);
  transition: transform 0.1s, background 0.2s, box-shadow 0.2s;
}
.listen:active { transform: scale(0.98); }
.listen-ico { width: 24px; height: 24px; }
.listen-ico.play { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.listen-ico.stop { fill: currentColor; display: none; }
.listen.on { color: var(--text); background: rgb(255 255 255 / 0.06); box-shadow: inset 0 0 0 1.5px rgb(255 255 255 / 0.14); }
.listen.on .play { display: none; }
.listen.on .stop { display: block; }
.listen.alarm { color: #fff; background: linear-gradient(180deg, #ff8a7a, #f05a4a); box-shadow: 0 12px 32px rgb(240 90 74 / 0.35); }
.note { margin: 12px 4px 0; text-align: center; color: var(--faint); font-size: 13px; line-height: 1.4; }

/* cards */
.card { margin-top: 18px; padding: 16px; border-radius: var(--radius); background: var(--card); box-shadow: inset 0 0 0 1px var(--line); }
.card h2 { margin: 0; font-size: 16px; font-weight: 650; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.text-btn { min-height: 40px; border: 0; background: none; padding: 8px 0 8px 12px; color: var(--muted); font-size: 14px; }

.chart { display: block; width: 100%; height: 96px; }
.legend { display: flex; gap: 14px; margin-top: 10px; color: var(--faint); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw.calm { background: rgb(var(--calm) / 0.8); }
.sw.warm { background: rgb(var(--warm) / 0.9); }
.sw.line { height: 0; border-top: 2px dashed rgb(var(--alert) / 0.8); border-radius: 0; }

/* events */
.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.events li:first-child { border-top: 0; padding-top: 2px; }
.events time { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.events time small { display: block; font-size: 11px; font-weight: 500; color: var(--faint); margin-top: 2px; }
.ev-main { min-width: 0; }
.ev-bar { height: 6px; border-radius: 3px; background: rgb(255 255 255 / 0.06); overflow: hidden; }
.ev-bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, rgb(var(--warm) / 0.7), rgb(var(--alert))); }
.ev-label { margin-top: 6px; font-size: 13px; color: var(--muted); }
.ev-dur { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.events li.live time { color: rgb(var(--alert)); }
.events li.live .ev-label { color: rgb(var(--alert)); }
.events .empty { display: block; padding: 6px 0 2px; color: var(--faint); font-size: 14px; line-height: 1.45; border: 0; }

/* 24-hour timeline */
.seg { display: inline-flex; padding: 2px; border-radius: 10px; background: rgb(255 255 255 / 0.06); }
.seg button { min-height: 36px; border: 0; background: none; padding: 8px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg button.on { background: rgb(255 255 255 / 0.12); color: var(--text); }
.day { display: block; width: 100%; height: 132px; cursor: pointer; touch-action: manipulation; }
.ev-play { width: 36px; height: 36px; border: 0; border-radius: 50%; display: grid; place-items: center; background: rgb(255 255 255 / 0.07); }
.ev-play svg { width: 14px; height: 14px; fill: var(--text); margin-left: 2px; }
.events li { grid-template-columns: 58px 1fr auto 36px; }
.events li.no-rec { grid-template-columns: 58px 1fr auto; }

/* recording player */
.recbar {
  position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 15;
  transform: translateX(-50%); width: min(500px, calc(100% - 20px));
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: 20px; background: #1d2742; box-shadow: 0 16px 40px rgb(0 0 0 / 0.55), inset 0 0 0 1px var(--line);
}
.rb-main { flex: none; width: 46px; height: 46px; border: 0; border-radius: 50%; display: grid; place-items: center; color: #241606; background: linear-gradient(180deg, #ffd9a3, #ffb45e); }
.rb-main svg { grid-area: 1 / 1; width: 20px; height: 20px; fill: currentColor; }
.rb-main .i-play { display: none; }
.recbar.paused .i-play { display: block; }
.recbar.paused .i-pause { display: none; }
.rb-info { flex: 1; min-width: 0; }
.rb-top { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; overflow: hidden; }
.rb-top b { font-size: 17px; font-variant-numeric: tabular-nums; }
.rb-top span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.rb-info input[type="range"] { margin: 4px 0 0; height: 20px; }
.rb-btn { flex: none; min-width: 36px; height: 36px; padding: 0 6px; border: 0; border-radius: 10px; background: rgb(255 255 255 / 0.07); font-size: 13px; font-variant-numeric: tabular-nums; }
body.has-recbar .app { padding-bottom: 110px; }
body.has-recbar .toast { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 84px); }

/* settings */
.settings summary { display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform 0.2s; }
.settings[open] summary svg { transform: rotate(180deg); }
.settings[open] summary { margin-bottom: 8px; }
.field { padding: 14px 0; border-bottom: 1px solid var(--line); }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field label { font-weight: 600; font-size: 15px; }
.field output { color: rgb(var(--warm)); font-variant-numeric: tabular-nums; font-size: 15px; }
.help { margin: 8px 0 0; color: var(--faint); font-size: 13px; line-height: 1.4; }
input[type="range"] { width: 100%; margin: 14px 0 2px; accent-color: rgb(var(--warm)); height: 28px; }
.range-labels { display: flex; justify-content: space-between; color: var(--faint); font-size: 12px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle:last-child { border-bottom: 0; padding-bottom: 2px; }
.toggle b { display: block; font-weight: 600; font-size: 15px; }
.toggle small { display: block; margin-top: 4px; color: var(--faint); font-size: 13px; line-height: 1.4; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { position: relative; flex: none; width: 50px; height: 30px; border-radius: 999px; background: rgb(255 255 255 / 0.12); transition: background 0.2s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 0.3); transition: transform 0.2s; }
.toggle input:checked + i { background: rgb(var(--calm) / 0.85); }
.toggle input:checked + i::after { transform: translateX(20px); }
.toggle input:focus-visible + i { outline: 2px solid rgb(var(--warm)); outline-offset: 2px; }
.toggle:has(input:disabled) { opacity: 0.45; cursor: default; }

.tips ul { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.tips li + li { margin-top: 6px; }

.foot { margin-top: 18px; text-align: center; color: var(--faint); font-size: 12px; line-height: 1.6; font-variant-numeric: tabular-nums; white-space: pre-line; }

/* access gate */
.gate { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.gate-box { width: 100%; max-width: 360px; text-align: center; }
.gate-box svg { width: 44px; height: 44px; fill: rgb(var(--warm)); }
.gate-box h2 { margin: 12px 0 8px; font-size: 24px; }
.gate-box p { margin: 0 0 20px; color: var(--muted); line-height: 1.45; }
.gate form { display: flex; gap: 8px; }
.gate input { flex: 1; min-width: 0; height: 52px; padding: 0 16px; border: 0; border-radius: 14px; background: var(--card-2); box-shadow: inset 0 0 0 1px var(--line); font-size: 20px; letter-spacing: 2px; text-align: center; }
.gate button { height: 52px; padding: 0 20px; border: 0; border-radius: 14px; font-weight: 650; color: #241606; background: linear-gradient(180deg, #ffd9a3, #ffb45e); }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 20; pointer-events: none;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 14px;
  background: #222d48; box-shadow: 0 10px 30px rgb(0 0 0 / 0.45), inset 0 0 0 1px var(--line);
  font-size: 14px; text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .orb-glow, .orb-ring, .ico, .listen { transition: none; }
  .orb[data-state="noise"] .orb-ring { animation: none; }
}
