:root {
  color-scheme: dark;
  --bg: #0d1018;
  --panel: #171d28;
  --panel-strong: #202837;
  --text: #f5f7fb;
  --muted: #aab4c2;
  --line: #2d3748;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #fb4f58;
  --blue: #78a8ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -15%, rgba(120, 168, 255, 0.24), transparent 38%),
    linear-gradient(180deg, #111827 0%, var(--bg) 38%, #0a0c12 100%);
}

button,
input,
select {
  font: inherit;
}

button,
summary,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 620px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.hero-panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 16px;
}

.eyebrow,
.meter-label,
.section-heading p,
.settings-note,
.range-labels,
.meter-scale {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 5px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 12vw, 3.75rem);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
}

.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-weight: 800;
  white-space: nowrap;
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(170, 180, 194, 0.12);
}

.state-pill[data-state="listening"] .state-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.state-pill[data-state="loud"] .state-dot,
.state-pill[data-state="blocked"] .state-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(251, 79, 88, 0.18);
}

.state-pill[data-state="paused"] .state-dot {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.18);
}

.meter-section {
  display: grid;
  gap: 14px;
}

.meter-readout {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  min-height: 120px;
}

.meter-readout strong {
  display: block;
  font-size: clamp(5.2rem, 28vw, 9rem);
  line-height: 0.78;
  letter-spacing: 0;
}

#coachText {
  max-width: 11rem;
  padding-bottom: 8px;
  color: var(--text);
  font-size: 1.18rem;
  font-weight: 900;
  text-align: right;
}

.meter-card,
.panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.meter-card {
  padding: 16px;
}

.meter-track {
  position: relative;
  height: 180px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(0deg, rgba(52, 211, 153, 0.28), rgba(52, 211, 153, 0.16) 44%, rgba(251, 191, 36, 0.2) 64%, rgba(251, 79, 88, 0.3)),
    #101722;
}

.meter-fill {
  position: absolute;
  inset: auto 0 0;
  height: 0%;
  background: linear-gradient(0deg, var(--green), var(--yellow), var(--red));
  opacity: 0.92;
  transition: height 90ms linear, filter 160ms ease;
}

.threshold-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 55%;
  z-index: 2;
  height: 2px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 0 16px rgba(255, 255, 255, 0.4);
}

.meter-scale,
.range-labels {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.controls-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.controls-row.compact {
  grid-template-columns: 1fr auto;
  align-items: center;
}

button {
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary-button {
  color: #07120e;
  background: var(--green);
}

.secondary-button {
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.text-button {
  min-height: 44px;
  padding: 0 4px;
  color: var(--blue);
  background: transparent;
}

.panel {
  margin-top: 14px;
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-heading output {
  min-width: 48px;
  text-align: right;
  font-size: 1.4rem;
  font-weight: 900;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.calibration-step {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #111722;
}

.calibration-step span {
  padding: 7px 10px;
  border-radius: 999px;
  color: #07120e;
  background: var(--yellow);
  font-weight: 900;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 50px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111722;
}

.history-list time,
.history-list span {
  color: var(--muted);
  font-size: 0.88rem;
}

details.panel {
  margin-bottom: 8px;
}

summary {
  min-height: 48px;
  cursor: pointer;
  font-weight: 900;
}

.settings-grid {
  display: grid;
  gap: 14px;
}

.settings-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.settings-grid select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-strong);
}

.toggle-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.toggle-row input {
  width: 24px;
  height: 24px;
}

.settings-note {
  padding-top: 4px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.app-shell.alerting .meter-card {
  animation: alertPulse 520ms ease-out;
}

.app-shell.alerting::before {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  content: "";
  background: rgba(251, 79, 88, 0.34);
  animation: screenFlash 620ms ease-out forwards;
}

@keyframes alertPulse {
  0% {
    transform: scale(1);
    border-color: rgba(251, 79, 88, 0.9);
  }
  45% {
    transform: scale(1.02);
    border-color: rgba(251, 79, 88, 1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes screenFlash {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (min-width: 560px) {
  .app-shell {
    padding-inline: 22px;
  }

  .meter-track {
    height: 230px;
  }
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f7fb;
    --panel: #ffffff;
    --panel-strong: #eef2f7;
    --text: #111827;
    --muted: #5c6675;
    --line: #d7dde7;
    --shadow: 0 14px 36px rgba(28, 39, 59, 0.12);
  }

  body {
    background:
      radial-gradient(circle at 50% -15%, rgba(120, 168, 255, 0.26), transparent 36%),
      linear-gradient(180deg, #eef5ff 0%, var(--bg) 35%, #ffffff 100%);
  }

  .calibration-step,
  .history-list li {
    background: #f8fafc;
  }

  .meter-card,
  .panel {
    border-color: rgba(17, 24, 39, 0.09);
  }
}
