:root {
  --bg: #07080b;
  --card: #111318;
  --card-hi: #15181e;
  --card-2: #1c2028;
  --border: rgb(255 255 255 / 0.07);
  --hair: rgb(255 255 255 / 0.06);
  --edge: inset 0 1px 0 rgb(255 255 255 / 0.06);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;
  --accent: #22d3ee;
  --amber: #fbbf24;
  --red: #f43f5e;
  --green: #34d399;
  --gap: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  /* Clear of the status bar and of the blur iOS draws below it. */
  --top: calc(env(safe-area-inset-top) + 14px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

/* A faint glow from the top; cards are opaque, so it only shows between them. */
body {
  background:
    radial-gradient(90% 45% at 50% -8%, rgb(34 211 238 / 0.09), transparent 70%),
    radial-gradient(70% 40% at 100% 105%, rgb(244 63 94 / 0.05), transparent 70%), var(--bg);
}

/* Native feel: scrolling yes, zooming (pinch, double tap) no. */
html {
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  color: var(--text);
  font:
    15px / 1.3 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button {
  transition:
    background-color 0.15s,
    color 0.15s,
    transform 0.15s var(--ease);
}

button:active:not(:disabled) {
  transform: scale(0.94);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

.glyph {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  height: 100dvh;
  /* Android Chrome can report 100dvh taller than the visible area (seen in an
     installed PWA after a reload: 872 vs 815 px), pushing content off screen. */
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom)
    max(14px, env(safe-area-inset-left));
}

/* --- Top bar --- */

.top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
}

.brand {
  margin: 0 auto 0 2px;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: -0.035em;
  background: linear-gradient(100deg, #fff 30%, #a5f3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.status {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted);
  margin-right: 4px;
}

.status.running::before,
.status.rec::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--green);
  vertical-align: 1px;
  box-shadow: 0 0 0 0 rgb(52 211 153 / 0.6);
  animation: pulse 2s infinite;
}

.status.rec {
  color: var(--red);
}

.status.rec::before {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% {
    opacity: 0.2;
  }
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 6px rgb(52 211 153 / 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgb(52 211 153 / 0);
  }
}

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
}

.actions {
  display: flex;
  padding: 2px;
  border-radius: 22px;
  background: rgb(255 255 255 / 0.04);
  border: 1px solid var(--hair);
  box-shadow: var(--edge);
}

.actions .icon-btn {
  width: 38px;
  height: 38px;
}

@media (hover: hover) {
  .top .icon-btn:hover {
    color: var(--text);
  }
}

.icon-btn .i-fill {
  fill: currentColor;
  stroke: none;
}

.badge {
  position: absolute;
  top: 3px;
  right: 1px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
  color: #042f35;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.icon-btn:active {
  background: var(--card-2);
}

.record .glyph {
  color: var(--red);
  filter: drop-shadow(0 0 6px rgb(244 63 94 / 0.55));
}

.recording .record {
  background: rgb(244 63 94 / 0.14);
}

.record .i-rec {
  fill: var(--red);
  stroke: none;
}

.record .i-stop,
.recording .record .i-rec {
  display: none;
}

.recording .record .i-stop {
  display: inline;
  fill: var(--red);
  stroke: none;
}

#toggle .i-play,
[data-state='paused'] #toggle .i-pause {
  display: none;
}

[data-state='paused'] #toggle .i-play {
  display: inline;
  fill: currentColor;
}

#toggle .i-play {
  fill: currentColor;
}

/* --- Views --- */

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.card {
  background: linear-gradient(180deg, var(--card-hi), var(--card) 60%);
  border: 1px solid var(--hair);
  border-radius: 22px;
  padding: 10px 14px;
  box-shadow:
    var(--edge),
    0 10px 30px -18px rgb(0 0 0 / 0.8);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.card-title {
  margin-right: auto;
  font-size: 11px;
  font-weight: 650;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.card-note {
  font-size: 12px;
  color: var(--faint);
}

.chip {
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  background: var(--card-2);
  border: 1px solid var(--border);
  box-shadow: var(--edge);
  font-size: 14px;
  font-weight: 600;
}

.chip.small {
  height: 24px;
  padding: 0 10px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--accent);
  background: rgb(34 211 238 / 0.1);
  border-color: rgb(34 211 238 / 0.2);
  box-shadow: none;
}

.chip:active {
  background: #262b35;
}

/* --- Level --- */

.hero {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 168px) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.dial {
  position: relative;
  cursor: zoom-in;
}

/* Enlarged: the gauge as big as the screen allows, the reading below it. */
.dial.max {
  position: fixed;
  z-index: 5;
  inset: var(--top) max(14px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 14px)
    max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  box-shadow: 0 0 0 100vmax var(--bg);
  cursor: zoom-out;
  animation: grow 0.22s var(--ease);
}

.dial.max .gauge {
  width: min(100%, 62dvh);
}

.dial.max .readout {
  position: static;
  margin-top: -9vmin;
}

.dial.max .now {
  font-size: clamp(56px, 18vw, 96px);
}

.dial.max .class {
  margin-top: 8px;
  font-size: 17px;
}

.dial.max .gauge-ticks text {
  font-size: 8px;
}

.gauge {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  fill: none;
}

.gauge-zones path {
  stroke-width: 10;
  opacity: 0.3;
}

.gauge-zones .track {
  stroke: #fff;
  stroke-linecap: round;
  opacity: 0.04;
}

.gauge-range {
  stroke: #fff;
  stroke-width: 3.5;
  stroke-linecap: round;
  opacity: 0.9;
  filter: drop-shadow(0 0 3px rgb(255 255 255 / 0.6));
}

.gauge-ticks path {
  stroke: var(--faint);
  stroke-width: 1;
  opacity: 0.7;
}

.gauge-ticks path.major {
  stroke: var(--muted);
  stroke-width: 1.5;
  opacity: 1;
}

.gauge-ticks text {
  fill: var(--faint);
  font-size: 10px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: middle;
}

.gauge-avg {
  fill: var(--accent);
  filter: drop-shadow(0 0 4px var(--accent));
}

.gauge-needle .hub {
  fill: var(--bg);
  stroke: currentColor;
  stroke-width: 2.5;
}

.gauge-needle {
  fill: currentColor;
  color: var(--muted);
  filter: drop-shadow(0 0 5px currentColor);
  transform-box: view-box;
  transform-origin: 100px 100px;
  transform: rotate(-120deg);
  transition: transform 0.1s linear;
}

.readout {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  text-align: center;
  pointer-events: none;
}

.now {
  font-size: clamp(26px, 8.5vw, 34px);
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.045em;
  white-space: nowrap;
  text-shadow: 0 0 24px rgb(255 255 255 / 0.15);
}

.now .unit {
  margin-left: 4px;
  font-size: 0.34em;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--faint);
  text-shadow: none;
}

.class {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history {
  flex: 1 1 0;
  min-height: 120px;
  max-height: 230px;
  display: flex;
  flex-direction: column;
  padding-bottom: 6px;
}

.history {
  cursor: zoom-in;
}

.history.max {
  cursor: zoom-out;
}

.chart {
  position: relative;
  flex: 1;
  min-height: 0;
}

#history {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Average, maximum, minimum and peak on the chart's dB scale; level-view.js
   places value and fill from the chart's scale. */
.bars {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 128px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.bar {
  position: relative;
  color: var(--muted);
}

.bar i {
  position: absolute;
  left: 5px;
  right: 5px;
  top: 100%;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, currentColor, color-mix(in srgb, currentColor 25%, transparent));
  box-shadow: 0 0 10px -2px currentColor;
  transition:
    top 0.25s var(--ease),
    color 0.25s;
}

.bar.leq {
  color: var(--accent);
}

.bar .v {
  position: absolute;
  left: -4px;
  right: -4px;
  text-align: center;
  font-size: 11px;
  font-weight: 650;
  color: var(--text);
  transition: top 0.25s var(--ease);
}

.bar .k {
  position: absolute;
  left: -4px;
  right: -4px;
  bottom: 0;
  text-align: center;
  font-size: 10px;
  line-height: 14px;
  color: var(--faint);
}

.bar.empty i {
  display: none;
}

.bar.empty .v {
  top: auto !important;
  bottom: 16px;
  color: var(--faint);
}

.card-head .card-note {
  margin-right: 2px;
}

/* A tapped card fills the screen; the shadow covers everything around it. */
.card.max {
  position: fixed;
  z-index: 5;
  inset: var(--top) max(14px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 14px)
    max(14px, env(safe-area-inset-left));
  max-height: none;
  box-shadow:
    var(--edge),
    0 0 0 100vmax var(--bg);
  animation: grow 0.22s var(--ease);
}

@keyframes grow {
  from {
    opacity: 0.4;
    transform: scale(0.97);
  }
}

.peaks {
  cursor: zoom-in;
}

.peaks.max {
  cursor: zoom-out;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.peaks.max .peak-list li {
  padding: 10px;
  grid-template-columns: 30px 1fr auto auto;
}

.peaks.max .hz {
  font-size: 26px;
}

.peaks.max .rank {
  width: 26px;
  height: 26px;
  font-size: 14px;
}

.peaks.max .meta,
.peaks.max .db {
  font-size: 16px;
}

/* --- Frequencies --- */

/* Beside the gauge: frequency and level; note or harmonic when enlarged. */
.peaks {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 8px 8px 6px;
}

.peaks .card-head {
  margin: 0 2px 4px 4px;
}

.peaks .card-title {
  min-width: 0;
  letter-spacing: 0.03em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peaks .chip {
  flex: none;
  white-space: nowrap;
}

.peaks:not(.max) .peak-list li {
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 6px;
  padding: 2px 4px;
}

.peaks:not(.max) .meta {
  display: none;
}

.peaks:not(.max) .hz {
  font-size: 15px;
  white-space: nowrap;
}

.peaks:not(.max) .db {
  min-width: 0;
  font-size: 11px;
}

.peak-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.peak-list li {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  align-items: baseline;
  gap: 10px;
  padding: 2px 6px;
  border-radius: 9px;
  overflow: hidden;
}

/* Presence: a wash that gets stronger to the right. */
.peak-list li::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--w, 0) * 100%);
  background: linear-gradient(90deg, rgb(251 191 36 / 0.03), rgb(251 191 36 / 0.18));
  border-radius: inherit;
  transition: width 0.3s var(--ease);
}

.peak-list .rank {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(160deg, #fde68a, var(--amber) 60%, #f59e0b);
  box-shadow: 0 0 8px rgb(251 191 36 / 0.35);
  color: #1c1917;
  font-size: 11px;
  font-weight: 700;
  align-self: center;
}

.peak-list .empty .rank {
  background: var(--card-2);
  box-shadow: none;
  color: var(--faint);
}

.peak-list .empty .hz {
  color: var(--faint);
}

.peak-list .hz {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.peak-list .meta {
  font-size: 12px;
  color: var(--muted);
}

.peak-list .db {
  min-width: 60px;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
}

.scope {
  position: relative;
  flex: 2 1 0;
  min-height: 170px;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #0e1015, #090a0e);
}

.scope canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#scope-overlay {
  touch-action: none;
}

.no-gl-text {
  display: none;
  margin: 16px;
  color: var(--muted);
}

.no-gl .no-gl-text {
  display: block;
}

/* --- Recordings sheet --- */

.sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.rec-list {
  max-height: 55dvh;
  overflow-y: auto;
  list-style: none;
  margin: 0 -6px;
  padding: 0;
}

.rec {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 2px;
  padding: 8px;
  border-radius: 14px;
}

.rec + .rec {
  border-top: 1px solid var(--border);
}

.rec-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rec-date {
  font-weight: 600;
}

.rec-meta {
  font-size: 13px;
  color: var(--muted);
}

.rec audio {
  grid-column: 1 / -1;
  width: 100%;
  height: 40px;
  margin-top: 6px;
}

.rec.playing {
  background: var(--card-2);
}

.icon-btn.danger.confirm {
  color: var(--red);
  background: rgb(244 63 94 / 0.14);
}

.rec-empty {
  color: var(--muted);
  margin: 8px 2px;
}

/* --- Start overlay --- */

.start {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60% 40% at 50% 38%, rgb(34 211 238 / 0.12), transparent 70%), rgb(7 8 11 / 0.95);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  text-align: center;
}

.start-box {
  max-width: 340px;
}

.start-icon {
  width: 76px;
  height: 76px;
  padding: 18px;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(34 211 238 / 0.22), rgb(34 211 238 / 0.06));
  box-shadow:
    inset 0 0 0 1px rgb(34 211 238 / 0.35),
    0 0 40px rgb(34 211 238 / 0.25);
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  animation: ring 2.4s var(--ease) infinite;
}

@keyframes ring {
  0% {
    box-shadow:
      inset 0 0 0 1px rgb(34 211 238 / 0.35),
      0 0 40px rgb(34 211 238 / 0.25),
      0 0 0 0 rgb(34 211 238 / 0.3);
  }
  100% {
    box-shadow:
      inset 0 0 0 1px rgb(34 211 238 / 0.35),
      0 0 40px rgb(34 211 238 / 0.25),
      0 0 0 22px rgb(34 211 238 / 0);
  }
}

.start h2 {
  margin: 16px 0 4px;
  font-size: 32px;
  font-weight: 750;
  letter-spacing: -0.04em;
  background: linear-gradient(100deg, #fff 30%, #a5f3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.start p {
  color: var(--muted);
}

.primary {
  width: 100%;
  height: 52px;
  margin-top: 12px;
  border-radius: 26px;
  background: linear-gradient(180deg, #67e8f9, var(--accent) 55%, #06b6d4);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.4),
    0 8px 24px -8px rgb(34 211 238 / 0.6);
  color: #042f35;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.error {
  color: #fda4af !important;
}

.hint {
  font-size: 13px;
}

/* --- Settings sheet --- */

.sheet {
  width: min(520px, 100%);
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 24px 18px calc(env(safe-area-inset-bottom) + 16px);
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 28px 28px 0 0;
  background: linear-gradient(180deg, #171a21, var(--card) 120px);
  box-shadow: 0 -20px 60px rgb(0 0 0 / 0.5);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}

.sheet[open] {
  animation: rise 0.28s var(--ease);
}

/* Grabber, as on native bottom sheets. */
.sheet::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 2px;
  background: rgb(255 255 255 / 0.18);
}

@keyframes rise {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.sheet h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.sheet h3 {
  margin: 16px 0 4px;
  font-size: 15px;
}

.sheet p,
.sheet dd {
  margin: 4px 0;
  font-size: 14px;
  color: var(--muted);
}

.sheet dt {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
}

.sheet dd {
  margin-left: 0;
}

.cal-state {
  margin-left: 6px;
  font-weight: 400;
  font-size: 13px;
  color: var(--amber);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.row > :first-child {
  margin-right: auto;
}

.row input {
  width: 96px;
  height: 34px;
  padding: 0 12px;
  border-radius: 12px;
  outline: none;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.row input:focus {
  border-color: rgb(34 211 238 / 0.6);
  box-shadow: 0 0 0 3px rgb(34 211 238 / 0.15);
}

.row output {
  min-width: 92px;
  text-align: center;
  font-weight: 600;
}

.link {
  margin-top: 8px;
  font-size: 14px;
  color: var(--accent);
}

.about {
  margin-top: 16px !important;
  font-size: 13px !important;
}

.about a {
  color: var(--accent);
}

/* Short screens (iPhone SE and the like): the history chart gives way to
   the spectrum; its header with duration and reset stays. */
/* Very short screens: the history chart gives way to the spectrum; its
   header with the duration stays. */
@media (max-height: 560px) {
  .history:not(.max) {
    flex: none;
    min-height: 0;
  }

  .history:not(.max) .card-head {
    margin-bottom: 0;
  }

  .history:not(.max) .chart {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
