:root {
  /* Zone colors (vivid) */
  --green: #22c55e;
  --yellow: #f5b301;
  --red: #ef4444;
  --idle: #64748b;

  /* Surface */
  --bg: #0b0f12;
  --bg-tint: #0b0f12;          /* animated toward zone color */
  --fg: #e7edf2;
  --fg-dim: #8595a1;
  --panel: #151b21;
  --line: #232c34;

  --accent: var(--idle);        /* current zone color, set by JS */

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;   /* kill iOS double-tap-to-zoom (the "jump"); pinch-zoom still works */
}

body {
  background: var(--bg-tint);
  color: var(--fg);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background-color 500ms ease;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) 20px calc(var(--safe-bottom) + 20px);
  max-width: 640px;
  margin: 0 auto;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 0;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
  font-size: 15px;
}
.icon-btn {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  font-size: 22px;
  line-height: 1;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:active { background: var(--panel); }

/* Stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.status-word {
  font-size: clamp(30px, 9vw, 52px);
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--accent);
  transition: color 400ms ease;
  text-transform: none;
  line-height: 1.05;
  min-height: 1.1em;
}

.readout {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: -4px;
}
.db-value {
  font-size: clamp(84px, 30vw, 168px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 0.9;
  color: var(--fg);
  transition: color 400ms ease;
}
.db-unit {
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 700;
  color: var(--fg-dim);
}
.db-unit small { font-size: 0.7em; opacity: 0.8; }

/* Meter */
.meter {
  width: 100%;
  max-width: 440px;
  margin-top: 18px;
}
.meter-track {
  position: relative;
  height: 26px;
  border-radius: 999px;
  background: #0e141a;
  border: 1px solid var(--line);
  overflow: hidden;
}
.meter-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 90ms linear, background-color 400ms ease;
}
.peak-tick {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 3px;
  background: #ffffff;
  opacity: 0.9;
  border-radius: 2px;
  transform: translateX(-50%);
}
.threshold-mark {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  transform: translateX(-50%);
  opacity: 0.55;
}
.mark-yellow { background: var(--yellow); }
.mark-red { background: var(--red); }

.meter-scale {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--fg-dim);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.substats {
  display: flex;
  gap: 28px;
  margin-top: 20px;
}
.substat { display: flex; flex-direction: column; gap: 2px; }
.substat-label { font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.substat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Controls */
.controls { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 8px; }
.primary-btn {
  appearance: none;
  border: none;
  background: var(--fg);
  color: #0b0f12;
  font-size: 19px;
  font-weight: 700;
  padding: 16px 34px;
  border-radius: 16px;
  cursor: pointer;
  min-width: 240px;
  transition: transform 80ms ease, opacity 200ms ease;
}
.primary-btn:active { transform: scale(0.97); }
.primary-btn.stop { background: transparent; color: var(--fg-dim); border: 1px solid var(--line); }
.primary-btn.ack { background: var(--red); color: #fff; }
.primary-btn.ack:active { background: #d63c3c; }

.message {
  text-align: center;
  color: var(--fg-dim);
  font-size: 14px;
  min-height: 1.2em;
  margin: 12px 0 0;
  padding: 0 4px;
}
.message.error { color: #fca5a5; }

/* Settings sheet */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.overlay[hidden] { display: none; }
.sheet {
  background: var(--panel);
  width: 100%;
  max-width: 640px;
  border-radius: 22px 22px 0 0;
  padding: 18px 20px calc(var(--safe-bottom) + 24px);
  max-height: 88dvh;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h2 { font-size: 20px; margin: 0; }
.sheet hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

.setting { margin: 18px 0; }
.setting > label { display: block; font-size: 16px; font-weight: 600; margin-bottom: 10px; }
.setting b { color: var(--accent); font-variant-numeric: tabular-nums; }
.hint { font-size: 13px; color: var(--fg-dim); margin: 8px 0 0; line-height: 1.4; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px; background: var(--line);
}
input[type="range"]::-moz-range-track { height: 8px; border-radius: 999px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--fg); margin-top: -11px; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 30px; height: 30px; border: none; border-radius: 50%;
  background: var(--fg); cursor: pointer;
}

.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch-row input { width: 22px; height: 22px; }

.msg-field { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.msg-dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; }
.dot-green { background: var(--green); }
.dot-yellow { background: var(--yellow); }
.dot-red { background: var(--red); }
input[type="text"] {
  flex: 1;
  min-width: 0;
  background: #0e141a;
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;              /* 16px keeps iOS from zooming on focus */
  font-family: inherit;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--fg-dim); }

.ghost-btn {
  appearance: none;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 12px;
}
.ghost-btn:active { background: #1c242c; }
.ghost-btn.danger { color: #fca5a5; }

.fineprint {
  font-size: 12px;
  color: var(--fg-dim);
  line-height: 1.5;
  margin-top: 22px;
}
.version {
  text-align: center;
  opacity: 0.75;
  margin-top: 14px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* Zone tints on <body> */
body[data-zone="green"]  { --accent: var(--green);  --bg-tint: #0a140d; }
body[data-zone="yellow"] { --accent: var(--yellow); --bg-tint: #161207; }
body[data-zone="red"]    { --accent: var(--red);    --bg-tint: #1a0c0c; }
body[data-zone="idle"]   { --accent: var(--idle);   --bg-tint: #0b0f12; }

/* When red, gently pulse the background to draw the eye */
@keyframes redpulse {
  0%, 100% { background-color: #1a0c0c; }
  50%      { background-color: #260f0f; }
}
body[data-zone="red"] { animation: redpulse 1.1s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  body[data-zone="red"] { animation: none; }
}
