:root {
  --bg: #121820;
  --ink: #e6eef5;
  --muted: #a9b8c4;
  --card: #1a242c;
  --lamp: #9fd0ff;
  --line: rgba(230, 238, 245, 0.16);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

body[data-level="ready"],
body[data-level="listening"] {
  --bg: #121820;
  --ink: #e6eef5;
  --muted: #a9b8c4;
  --card: #1a242c;
  --lamp: #9fd0ff;
  background:
    radial-gradient(1000px 560px at 50% -12%, #1a3348 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
}

body[data-level="normal"] {
  --bg: #10211e;
  --ink: #e7f6ef;
  --muted: #b7d2c6;
  --card: #17302b;
  --lamp: #8ee0b5;
  background:
    radial-gradient(1100px 640px at 50% -12%, #1d4c44 0%, transparent 52%),
    var(--bg);
  color: var(--ink);
}

body[data-level="caution"] {
  --bg: #f0c84a;
  --ink: #241c00;
  --muted: #4d3d0d;
  --card: #fff8e4;
  --lamp: #241c00;
  --line: rgba(36, 28, 0, 0.18);
  background: #f0c84a;
  color: #241c00;
}

body[data-level="critical"] {
  --bg: #ff2b2b;
  --ink: #1a0000;
  --muted: #4a0000;
  --card: #fff6ee;
  --lamp: #1a0000;
  background: #ff2b2b;
  color: #1a0000;
}

/* About 1 Hz, under the photosensitive flash threshold. */
@keyframes alarm-flash {
  0%, 49% {
    background: #ff2b2b;
    color: #1a0000;
  }
  50%, 100% {
    background: #140000;
    color: #fff7f4;
  }
}

@keyframes caution-pulse {
  0%, 100% { background-color: #e2b326; }
  50% { background-color: #ffe7a0; }
}

@keyframes ripple {
  from { transform: scale(0.72); opacity: 0.55; }
  to { transform: scale(1.35); opacity: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  body[data-level="critical"] {
    animation: alarm-flash 1.1s steps(1, end) infinite;
  }
  body[data-level="caution"] {
    animation: caution-pulse 1.8s ease-in-out infinite;
  }
  #tap-button.is-pulsing .tap-ripple {
    animation: ripple 700ms ease-out;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  #tap-button.is-pulsing {
    outline: 6px solid currentColor;
    outline-offset: -12px;
  }
}

.lamp {
  position: fixed;
  z-index: 3;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  background: var(--lamp);
  pointer-events: none;
}

main[hidden],
section[hidden],
p[hidden],
div[hidden] {
  display: none !important;
}

main {
  width: min(100%, 46rem);
  margin: 0 auto;
  padding: 1.2rem 1.2rem 2rem;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0.2rem 0 1rem;
}

.wordmark {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.disclaimer p,
.fine,
.reason {
  font-size: 1.08rem;
  line-height: 1.45;
}

.disclaimer p { margin: 0 0 0.85rem; }

.fine { color: var(--muted); margin: 0.8rem 0 0; }
.fine.dark { color: #5c4636; }

a.hotline {
  color: inherit;
  font-weight: 800;
}

button, .call { font: inherit; }

.start-button,
.confirm,
#im-ok,
.text-button,
.modes button,
#tap-button {
  touch-action: manipulation;
}

.start-button {
  width: 100%;
  min-height: 5.5rem;
  margin-top: 0.4rem;
  border: 0;
  border-radius: 1.25rem;
  background: #8ee0b5;
  color: #062117;
  font-size: 1.55rem;
  font-weight: 800;
  cursor: pointer;
}

#watch {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.watch-top {
  width: min(100%, 46rem);
  margin: 0 auto;
  padding: 0.85rem 1.15rem 0.35rem;
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.status-pill {
  margin: 0;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.bpm-block {
  display: flex;
  flex-direction: column;
  margin: 0.35rem 0 0.6rem;
}

.bpm-label,
.bpm-unit,
.since-block span {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bpm-num,
.since-block strong {
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  letter-spacing: -0.045em;
  line-height: 0.86;
}

.bpm-num {
  font-size: clamp(5.4rem, 24vw, 10rem);
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
}

.modes button {
  min-height: 3rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-weight: 800;
  cursor: pointer;
}

.modes button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

#stage-tap,
#stage-mic {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#tap-button {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 62vh;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1.5rem;
}

.tap-ripple {
  position: absolute;
  width: min(70vw, 28rem);
  height: min(70vw, 28rem);
  border-radius: 50%;
  border: 3px solid currentColor;
  opacity: 0;
  pointer-events: none;
}

.tap-kicker {
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--muted);
}

.tap-label {
  font-size: clamp(2.2rem, 7vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.tap-hint {
  max-width: 18rem;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
}

.mic-wrap {
  width: min(100%, 46rem);
  margin: 0 auto;
  padding: 0.4rem 1.15rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cal-track {
  height: 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

body[data-level="caution"] .cal-track { background: rgba(0, 0, 0, 0.12); }

#cal-bar {
  width: 0;
  height: 100%;
  background: #1f6b52;
}

.wave-card {
  position: relative;
  min-height: 9rem;
  border-radius: 1.15rem;
  background: #0c1412;
  overflow: hidden;
}

#wave {
  display: block;
  width: 100%;
  height: 9rem;
}

.mic-glow {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(142, 224, 181, 0.9), transparent 68%);
  pointer-events: none;
  opacity: 0.15;
}

.mic-glow[data-level="0"] { opacity: 0.1; }
.mic-glow[data-level="1"] { opacity: 0.18; }
.mic-glow[data-level="2"] { opacity: 0.26; }
.mic-glow[data-level="3"] { opacity: 0.34; }
.mic-glow[data-level="4"] { opacity: 0.42; }
.mic-glow[data-level="5"] { opacity: 0.5; }
.mic-glow[data-level="6"] { opacity: 0.6; }
.mic-glow[data-level="7"] { opacity: 0.7; }
.mic-glow[data-level="8"] { opacity: 0.8; }
.mic-glow[data-level="9"] { opacity: 0.88; }
.mic-glow[data-level="10"] { opacity: 0.96; }

.confidence { margin: 0; font-weight: 750; }

.banner {
  margin: 0;
  padding: 0.9rem 1rem;
  border-radius: 0.95rem;
  background: #fff4cc;
  color: #241c00;
  font-weight: 750;
}

.text-button {
  min-height: 3.25rem;
  border-radius: 999px;
  border: 2px solid currentColor;
  background: transparent;
  color: inherit;
  font-weight: 800;
  cursor: pointer;
}

#checkin, #critical { padding-bottom: 2.5rem; }

.confirm {
  width: 100%;
  min-height: 42vh;
  margin-top: 0.6rem;
  border: 0;
  border-radius: 1.5rem;
  background: #1c1500;
  color: #fff8e0;
  font-size: clamp(2rem, 6vw, 3.3rem);
  font-weight: 850;
  line-height: 1.1;
  cursor: pointer;
}

.kicker {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 850;
  letter-spacing: -0.04em;
  text-transform: uppercase;
}

.since-block {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin: 0 0 0.4rem;
}

.since-block strong {
  font-size: clamp(2.4rem, 8vw, 4rem);
}

.alarm-state {
  margin: 0.2rem 0 0.8rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.action-card,
.info-card {
  background: #fff6ee;
  color: #24180f;
  border-radius: 1.25rem;
  padding: 1rem 1rem 1.15rem;
  margin-top: 0.85rem;
}

.action-card { display: flex; flex-direction: column; gap: 0.75rem; }

.call-row { display: grid; gap: 0.75rem; }

.call {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  min-height: 4.8rem;
  border-radius: 1rem;
  font-weight: 850;
  border: 3px solid #1c0000;
  line-height: 1.15;
}

.call-911 {
  background: #1c0000;
  color: #fff;
  font-size: 2rem;
}

.call-hotline {
  background: #ffe14a;
  color: #1c1500;
  font-size: 1.2rem;
}

#im-ok {
  width: 100%;
  min-height: 4.2rem;
  border-radius: 1rem;
  border: 3px solid #1c0000;
  background: #fff;
  color: #1c0000;
  font-size: 1.35rem;
  font-weight: 850;
  cursor: pointer;
}

.info-card h2 {
  margin: 0 0 0.55rem;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.info-card ol {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 1.12rem;
  line-height: 1.4;
}

.info-card li + li { margin-top: 0.4rem; }

.info-card p { margin: 0.75rem 0 0; }

.recovery-svg {
  width: 100%;
  height: auto;
  display: block;
  margin: 0.2rem 0 0.8rem;
  border-radius: 0.8rem;
  background: #fffdf8;
}

:focus-visible {
  outline: 3px solid #f4fff8;
  outline-offset: 3px;
}

body[data-level="caution"] :focus-visible,
body[data-level="critical"] :focus-visible {
  outline-color: #1c1500;
}

#notices {
  position: fixed;
  z-index: 5;
  left: 1rem;
  right: 1rem;
  top: calc(0.6rem + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: none;
}

.notice {
  margin: 0;
  background: #fff6ee;
  color: #24180f;
  padding: 0.65rem 0.8rem;
  border-radius: 0.75rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 420px) {
  .call-911 { font-size: 1.7rem; }
}
