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

:root {
  --bg:       #060d1a;
  --surface:  #0d1b2e;
  --surface2: #132540;
  --border:   #1e3a5f;
  --primary:  #4f8ef7;
  --danger:   #e05252;
  --success:  #3ecf8e;
  --warning:  #f5a623;
  --text:     #e0eaff;
  --muted:    #5a7a9e;
  --radius:   12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Animated background ── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(30,80,160,0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(10,50,120,0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #0a1628 0%, #0d2040 100%);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: relative; z-index: 10;
}
.header__inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
}
.header__logo { font-size: 36px; }
.header__title { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.header__sub   { font-size: 13px; color: var(--muted); margin-top: 2px; }

.alert-badge {
  margin-left: auto;
  background: rgba(224,82,82,0.15);
  border: 2px solid var(--danger);
  color: var(--danger);
  padding: 8px 18px;
  border-radius: 24px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  animation: alertPulse 1s infinite;
}
@keyframes alertPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(224,82,82,0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(224,82,82,0); }
}

/* ── Main ── */
.main {
  max-width: 1100px; margin: 0 auto;
  padding: 28px 24px 60px;
  position: relative; z-index: 1;
}

/* ── Controls ── */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 24px;
  margin-bottom: 32px;
}
.control-group {
  display: flex; align-items: center; gap: 10px;
}
.control-group label {
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.control-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.control-group select:focus { border-color: var(--primary); }
.control-group input[type=range] {
  width: 80px; accent-color: var(--primary); cursor: pointer;
}
.control-group--actions { gap: 10px; }

.mic-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.mic-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
}
.mic-dot--active { background: var(--success); animation: micPulse 1.2s infinite; }
.mic-dot--leak   { background: var(--danger);  animation: micPulse 0.5s infinite; }
@keyframes micPulse {
  0%,100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.4); opacity: 0.7; }
}

/* ── Buttons ── */
.btn {
  padding: 9px 18px; border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: #3a72d8; }
.btn--danger  { background: var(--danger);  color: #fff; }
.btn--danger:hover  { background: #c94444; }
.btn--ghost   { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn--ghost:hover { color: var(--text); border-color: var(--muted); }
.btn--sm { padding: 5px 12px; font-size: 12px; }

/* ── Scene ── */
.scene {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  position: relative;
  overflow: hidden;
}
.scene::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(30,100,200,0.05) 0%, transparent 70%);
  pointer-events: none;
}
.scene__label {
  font-size: 12px; color: var(--muted);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.scene__label--left  { transform: rotate(180deg); }

.pipe-wrap {
  flex: 1;
  position: relative;
}
.pipe-svg {
  width: 100%; height: auto;
  display: block;
  filter: drop-shadow(0 4px 20px rgba(30,100,200,0.3));
}
.pipe-clickable { cursor: crosshair; }

/* ── Leak point on SVG ── */
.leak-point circle { cursor: pointer; }
.leak-ripple {
  animation: ripple 1.5s ease-out infinite;
  transform-origin: center;
}
@keyframes ripple {
  0%   { r: 8;  opacity: 0.8; }
  100% { r: 22; opacity: 0; }
}

/* ── Water drops ── */
.drops-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.drop {
  position: absolute;
  width: 6px; height: 10px;
  background: radial-gradient(ellipse at 40% 30%, #7ecfff, #1a7fd4);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  animation: dropFall var(--dur, 0.8s) ease-in var(--delay, 0s) infinite;
  opacity: 0;
}
@keyframes dropFall {
  0%   { transform: translateY(0) scaleX(1); opacity: 1; }
  80%  { opacity: 0.8; }
  100% { transform: translateY(var(--fall, 60px)) scaleX(0.7); opacity: 0; }
}

/* ── Waveform ── */
.waveform-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px 16px;
  margin-bottom: 32px;
}
.waveform-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.waveform-title { font-size: 13px; color: var(--muted); font-weight: 500; }
.waveform-score {
  font-size: 13px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 120px; text-align: right;
}
.waveform-canvas {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 6px;
  background: #080f1c;
}

/* ── History ── */
.history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.history__header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.history__header h2 { font-size: 15px; font-weight: 600; }
.history-list { max-height: 280px; overflow-y: auto; }
.history-empty { padding: 20px; color: var(--muted); font-size: 13px; text-align: center; }
.history-item {
  display: grid;
  grid-template-columns: 120px 1fr 80px;
  gap: 12px;
  align-items: start;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  animation: slideIn 0.2s ease;
}
.history-item:last-child { border-bottom: none; }
.history-item--active {
  background: rgba(224,82,82,0.06);
  border-left: 3px solid var(--danger);
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: none; }
}
.history-item__time  { color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 2px; }
.history-item__body  { display: flex; flex-direction: column; gap: 3px; }
.history-item__event { font-weight: 600; }
.history-item__meta  { font-size: 12px; color: var(--muted); line-height: 1.5; }
.history-item__score { color: var(--danger); }
.history-item__badge {
  display: inline-block;
  padding: 3px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px;
  text-align: center; margin-top: 2px;
}
.history-item__badge--ai     { background: rgba(224,82,82,0.15); color: var(--danger); border: 1px solid var(--danger); }
.history-item__badge--manual { background: rgba(245,166,35,0.15); color: var(--warning); border: 1px solid var(--warning); }

.hidden { display: none !important; }
