:root {
  --bg-deep: #0a0d16;
  --text: #f2f5fb;
  --muted: #9aa5b8;
  --muted-strong: #c3cbdb;

  --accent: #8b9dff;
  --accent-2: #22d3ee;
  --accent-3: #c084fc;

  --pass: #34e5a4;
  --warn: #ffc857;
  --fail: #ff6b81;

  --glass-bg: rgba(255, 255, 255, 0.055);
  --glass-bg-strong: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg-deep);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  position: relative;
  overflow-x: hidden;
}

/* ---- Ambient background: blurred color blobs behind the glass ---- */
.bg-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  z-index: -2;
  pointer-events: none;
  will-change: transform;
}

.blob-1 {
  width: 560px;
  height: 560px;
  top: -180px;
  left: -140px;
  background: radial-gradient(circle at 30% 30%, #6a7bff, transparent 70%);
  animation: drift1 26s ease-in-out infinite alternate;
}

.blob-2 {
  width: 480px;
  height: 480px;
  top: 10%;
  right: -160px;
  background: radial-gradient(circle at 60% 40%, #22d3ee, transparent 70%);
  animation: drift2 22s ease-in-out infinite alternate;
}

.blob-3 {
  width: 520px;
  height: 520px;
  bottom: -200px;
  left: 15%;
  background: radial-gradient(circle at 50% 50%, #c084fc, transparent 70%);
  animation: drift3 30s ease-in-out infinite alternate;
}

.blob-4 {
  width: 380px;
  height: 380px;
  bottom: 5%;
  right: 8%;
  background: radial-gradient(circle at 40% 60%, #ff9fb2, transparent 70%);
  opacity: 0.35;
  animation: drift1 24s ease-in-out infinite alternate-reverse;
}

.bg-grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 3px 3px;
}

@keyframes drift1 {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(60px, 40px) scale(1.08); }
}
@keyframes drift2 {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-50px, 60px) scale(0.95); }
}
@keyframes drift3 {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(40px, -50px) scale(1.1); }
}

header {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 32px 16px;
  position: relative;
  z-index: 1;
}

header h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(120deg, #ffffff 10%, var(--accent) 60%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 32px 72px;
  position: relative;
  z-index: 1;
}

/* Single column by default (mobile/narrow) -- input, report, history all
   stack in document order, same as before. */
.layout-grid {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.col-left,
.col-right {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0; /* let contents (canvas etc.) shrink instead of overflowing */
}

/* On wide screens, show input on the left and results (report + history) on
   the right side by side, so you don't have to scroll past the whole
   upload/record UI just to see the report. */
@media (min-width: 1080px) {
  header,
  main {
    max-width: 1360px;
  }

  .layout-grid {
    display: grid;
    grid-template-columns: minmax(380px, 460px) 1fr;
    align-items: start;
    gap: 26px;
  }

  .col-left {
    position: sticky;
    top: 16px;
    align-self: start;
  }
}

/* ---- Glass panel base ---- */
.panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 22px 24px;
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--glass-shadow);
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted-strong);
}

.hidden { display: none !important; }

/* ---- Tabs: glass segmented control ---- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  width: fit-content;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.tab-btn.active {
  color: var(--text);
  background: var(--glass-bg-strong);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* ---- Buttons ---- */
button {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #0b0d16;
  border: none;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(139, 157, 255, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(139, 157, 255, 0.38);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

button.secondary {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  color: var(--text);
  box-shadow: none;
}

button.secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

/* ---- Inputs / selects ---- */
input[type="file"] {
  color: var(--muted);
  margin-bottom: 12px;
  display: block;
}

select {
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
}

/* ---- Device selection ---- */
.device-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.device-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  flex: 1;
  min-width: 180px;
}

.small { font-size: 12px; }

.record-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

#recordTimer {
  color: var(--muted-strong);
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 14px;
}

audio {
  width: 100%;
  margin: 10px 0;
  border-radius: 12px;
}

#status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

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

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}

.badge.pass { background: rgba(52, 229, 164, 0.14); color: var(--pass); border-color: rgba(52, 229, 164, 0.3); box-shadow: 0 0 14px rgba(52, 229, 164, 0.15); }
.badge.warn { background: rgba(255, 200, 87, 0.14); color: var(--warn); border-color: rgba(255, 200, 87, 0.3); box-shadow: 0 0 14px rgba(255, 200, 87, 0.15); }
.badge.fail { background: rgba(255, 107, 129, 0.14); color: var(--fail); border-color: rgba(255, 107, 129, 0.3); box-shadow: 0 0 14px rgba(255, 107, 129, 0.15); }
.badge.unknown { background: rgba(154, 165, 184, 0.14); color: var(--muted); border-color: rgba(154, 165, 184, 0.25); }

/* ---- Check cards ---- */
.check-card {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 12px;
}

.check-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.check-card-header strong {
  font-size: 14px;
  color: var(--muted-strong);
}

.check-card ul {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13.5px;
  color: var(--muted);
}

.check-card li { margin-bottom: 4px; }

.overall-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 14px;
}

.meta-row {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ---- History table ---- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--glass-border);
}

th { color: var(--muted); font-weight: 500; }

tr.clickable { cursor: pointer; transition: background 0.15s ease; }
tr.clickable:hover { background: rgba(255, 255, 255, 0.05); }

/* ---- Live monitor ---- */
.monitor-panel {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.monitor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.meters-row {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}

.meter-block { width: 100%; }

.meter-label {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.meter-label span { color: var(--text); font-family: "SF Mono", ui-monospace, monospace; font-size: 12px; }

.meter-bar {
  position: relative;
  width: 100%;
  height: 12px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.4);
}

.meter-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pass), var(--warn) 75%, var(--fail) 92%);
  box-shadow: 0 0 10px rgba(139, 157, 255, 0.4);
  transition: width 60ms linear;
}

.meter-fill.floor {
  background: linear-gradient(90deg, var(--accent), var(--accent-2) 60%, var(--warn) 88%);
}

.meter-hold {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
  left: 0%;
}

.loudness-bar {
  height: 16px;
}

.target-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(52, 229, 164, 0.22);
  border-left: 1px solid var(--pass);
  border-right: 1px solid var(--pass);
}

.meter-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
  left: 0%;
  transition: left 80ms linear;
}

.spectrogram-wrap canvas {
  width: 100%;
  height: 220px;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: #000;
  box-shadow: var(--glass-shadow);
}

/* ---- Spectrogram frequency/time axes (shared: live monitor + static/report) ---- */
.spectrogram-row {
  display: flex;
  gap: 0;
  align-items: stretch;
}

.freq-axis {
  position: relative;
  width: 48px;
  flex: 0 0 48px;
  border-radius: 14px 0 0 14px;
  border: 1px solid var(--glass-border);
  border-right: none;
  background: rgba(0, 0, 0, 0.25);
}

.freq-axis span {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--muted);
  font-family: "SF Mono", ui-monospace, monospace;
  white-space: nowrap;
}

.spectrogram-row canvas {
  border-radius: 0 14px 14px 0 !important;
  flex: 1;
  min-width: 0;
}

.time-axis {
  position: relative;
  height: 18px;
  margin-left: 48px;
  margin-top: 4px;
}

.time-axis span {
  position: absolute;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  font-family: "SF Mono", ui-monospace, monospace;
  white-space: nowrap;
}

.spectrogram-static-wrap canvas {
  width: 100%;
  height: 260px;
  display: block;
  background: #000;
}

/* ---- Spectrogram click-to-zoom ---- */
.zoomable {
  cursor: zoom-in;
  transition: box-shadow 0.15s ease;
}

.zoomable:hover {
  box-shadow: 0 0 0 1px var(--accent), var(--glass-shadow);
}

.zoom-hint {
  font-size: 11px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.15s ease;
  font-weight: 500;
}

.zoomable:hover .zoom-hint {
  opacity: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 10, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-content {
  background: rgba(20, 22, 32, 0.85);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 22px 26px;
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: var(--glass-shadow);
  width: min(94vw, 1500px);
  max-height: 92vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted-strong);
}

.modal-spectrogram-row {
  height: min(70vh, 640px);
}

.modal-spectrogram-row canvas {
  width: 100%;
  height: 100%;
}

.modal-spectrogram-row .freq-axis {
  width: 56px;
  flex: 0 0 56px;
}

.modal-spectrogram-row .freq-axis span {
  font-size: 12px;
}

#modalCanvasSlot {
  flex: 1;
  min-width: 0;
  border-radius: 0 14px 14px 0;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-left: none;
  background: #000;
}

#modalCanvasSlot canvas {
  display: block;
}

.modal-content .time-axis {
  margin-left: 56px;
}

/* ---- Live Calibration tab ---- */
.calibrate-hero {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 22px 26px;
  border-radius: 18px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 18px;
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

.calibrate-hero.status-idle {
  box-shadow: none;
}

.calibrate-hero.status-pass {
  border-color: rgba(52, 229, 164, 0.4);
  box-shadow: 0 0 26px rgba(52, 229, 164, 0.18);
}

.calibrate-hero.status-warn {
  border-color: rgba(255, 200, 87, 0.45);
  animation: cardPulseWarn 2.4s ease-in-out infinite;
}

.calibrate-hero.status-fail {
  border-color: rgba(255, 107, 129, 0.5);
  animation: cardPulseFail 1.3s ease-in-out infinite;
}

@keyframes cardPulseWarn {
  0%, 100% { box-shadow: 0 0 14px rgba(255, 200, 87, 0.15); }
  50% { box-shadow: 0 0 30px rgba(255, 200, 87, 0.38); }
}

@keyframes cardPulseFail {
  0%, 100% { box-shadow: 0 0 16px rgba(255, 107, 129, 0.22); }
  50% { box-shadow: 0 0 34px rgba(255, 107, 129, 0.5); }
}

.level-orb-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  flex: 0 0 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--glass-border);
  animation: orbBreathe 2.6s ease-in-out infinite;
}

@keyframes orbBreathe {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.06); }
}

.level-orb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.5), var(--accent) 60%, var(--accent-3) 100%);
  box-shadow: 0 0 20px rgba(139, 157, 255, 0.5);
  transition: transform 90ms ease-out, background 0.4s ease, box-shadow 0.4s ease;
  transform: scale(1);
}

.status-pass .level-orb {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), var(--pass) 65%, #1c9c6b 100%);
  box-shadow: 0 0 22px rgba(52, 229, 164, 0.55);
}

.status-warn .level-orb {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), var(--warn) 65%, #b8791f 100%);
  box-shadow: 0 0 22px rgba(255, 200, 87, 0.55);
}

.status-fail .level-orb {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), var(--fail) 65%, #a5293c 100%);
  box-shadow: 0 0 26px rgba(255, 107, 129, 0.6);
}

.level-orb-icon {
  position: absolute;
  font-size: 26px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  transition: transform 0.25s ease;
  animation: iconPop 0.3s ease;
}

@keyframes iconPop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.calibrate-message h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  transition: color 0.3s ease;
}

.calibrate-message p {
  margin: 0;
  font-size: 13.5px;
  max-width: 480px;
}

.calibrate-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.calibrate-metric {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
}

.calibrate-metric-icon {
  font-size: 20px;
  line-height: 1;
  margin-top: 2px;
}

.calibrate-metric-body {
  flex: 1;
  min-width: 0;
}

.calibrate-metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted-strong);
  margin-bottom: 4px;
}

@media (max-width: 640px) {
  .calibrate-hero {
    flex-direction: column;
    text-align: center;
  }
  .calibrate-message p {
    max-width: none;
  }
}
