:root {
  --bg: #070b16;
  --bg-2: #0b1020;
  --panel: #0f172a;
  --line: rgba(255, 255, 255, 0.09);
  --txt: #e9eefc;
  --muted: #7f8daa;
  --accent: #4fd1ff;
  --accent-2: #7c8cff;
  --ok: #34d399;
  --warn: #fbbf24;
  --hot: #fb7185;
  --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; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 70% at 50% -10%, #16224a 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  color: var(--txt);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- barre du haut ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-t)) 18px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b9c6e4;
}

.led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34405c;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.5);
  transition: background 0.2s;
}

.led.on {
  background: var(--ok);
  box-shadow: 0 0 12px 1px rgba(52, 211, 153, 0.8);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  50% { box-shadow: 0 0 4px 0 rgba(52, 211, 153, 0.35); }
}

.bar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:active { background: rgba(255, 255, 255, 0.06); }

/* ---------- mesure ---------- */

main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 14px;
  min-height: 0;
}

.readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-height: 0;
}

.value-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: -6px;
}

.value {
  font-size: clamp(58px, 21vw, 104px);
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 42px rgba(79, 209, 255, 0.28);
  transition: color 0.25s;
}

.value.calm { color: #e9eefc; }
.value.loud { color: var(--warn); }
.value.very-loud { color: var(--hot); }

.unit {
  font-size: 17px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.unit em { font-style: normal; }

#gauge {
  width: 100%;
  max-height: 34vh;
  aspect-ratio: 12 / 6.4;
  display: block;
}

.chips {
  display: flex;
  gap: 6px;
  margin-top: -2px;
  min-height: 22px;
}

.chip {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(124, 140, 255, 0.13);
  color: #a9b6ff;
  border: 1px solid rgba(124, 140, 255, 0.22);
}

.chip.muted {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  color: var(--muted);
}

.chip.set {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.3);
  color: #6ee7b7;
}

.chip.warn {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.3);
  color: #fcd34d;
}

/* ---------- statistiques ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 8px 10px 12px;
}

.stat { display: flex; flex-direction: column; gap: 2px; }

.stat .k {
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat .k sub { font-size: 9px; }

.stat .v {
  font-size: 19px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: #dbe4fb;
}

.reset {
  align-self: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

/* ---------- spectre ---------- */

.spectrum { min-height: 0; flex: 1; display: flex; flex-direction: column; }

#spectrum {
  width: 100%;
  flex: 1;
  min-height: 74px;
  display: block;
}

.axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: #556178;
  padding: 1px 2px 4px;
}

/* ---------- contrôles ---------- */

.controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: linear-gradient(180deg, rgba(7, 11, 22, 0), rgba(7, 11, 22, 0.9) 30%);
}

.seg {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.seg button.on {
  background: rgba(79, 209, 255, 0.16);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(79, 209, 255, 0.28);
}

.power {
  height: 52px;
  border: 0;
  border-radius: 15px;
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #04101f;
  background: linear-gradient(135deg, var(--accent), #7bd8ff 45%, var(--accent-2));
  box-shadow: 0 8px 26px -8px rgba(79, 209, 255, 0.65);
  cursor: pointer;
  transition: transform 0.1s, filter 0.2s;
}

.power:active { transform: scale(0.98); }

.power.running {
  color: #ffd9de;
  background: linear-gradient(135deg, #7f1d33, #b4264a);
  box-shadow: 0 8px 26px -8px rgba(251, 113, 133, 0.5);
}

/* ---------- réglages ---------- */

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--txt);
  width: min(100vw - 24px, 520px);
  max-height: 88dvh;
}

dialog::backdrop { background: rgba(3, 6, 14, 0.7); backdrop-filter: blur(3px); }

.sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 88dvh;
  overflow: auto;
}

.sheet h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.field, fieldset { display: flex; flex-direction: column; gap: 8px; margin: 0; }

fieldset {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
}

legend {
  padding: 0 6px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

label { font-size: 14px; color: #c6d2ee; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

input[type="number"] {
  width: 92px;
  padding: 9px 10px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--txt);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
}

input[type="number"]:focus { outline: 2px solid rgba(79, 209, 255, 0.45); outline-offset: 1px; }

.hint { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.muted { color: var(--muted); }

.ghost {
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 600;
  color: #cfe0ff;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.ghost:disabled { opacity: 0.45; cursor: not-allowed; }

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }

.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.legal {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: #6d7a96;
  border-left: 2px solid rgba(251, 191, 36, 0.4);
  padding-left: 10px;
}

.sheet-actions { display: flex; justify-content: flex-end; }

.primary {
  padding: 11px 22px;
  font-size: 14.5px;
  font-weight: 700;
  color: #04101f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px);
  padding: 11px 16px;
  border-radius: 12px;
  background: rgba(18, 26, 45, 0.97);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.45;
  color: #d7e1f8;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 660px) {
  #gauge { max-height: 26vh; }
  .value { font-size: clamp(48px, 17vw, 82px); }
}
