/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --primary: #4f8ef7;
  --primary-dark: #3a72d8;
  --danger: #e05252;
  --success: #3ecf8e;
  --warning: #f5a623;
  --text: #e8eaf0;
  --text-muted: #7b82a0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  padding: 24px 16px 48px;
}

/* ===== Layout ===== */
.container {
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/* ===== Header ===== */
header {
  text-align: center;
  margin-bottom: 32px;
}
.logo { font-size: 48px; margin-bottom: 8px; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { color: var(--text-muted); margin-top: 6px; font-size: 14px; }

/* ===== Badge ===== */
.badge {
  display: inline-block;
  margin-top: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge--loading { background: var(--surface2); color: var(--text-muted); }
.badge--webgpu  { background: #1a3a2a; color: var(--success); border: 1px solid var(--success); }
.badge--webgl   { background: #2a2a1a; color: var(--warning); border: 1px solid var(--warning); }
.badge--cpu     { background: #2a1a1a; color: var(--danger);  border: 1px solid var(--danger); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.tab--active {
  background: var(--surface2);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.tab:hover:not(.tab--active) { color: var(--text); }

/* ===== Panel ===== */
.panel { display: none; }
.panel--active { display: block; }

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface);
}
.drop-zone:hover, .drop-zone--over {
  border-color: var(--primary);
  background: rgba(79,142,247,0.05);
}
.drop-zone__icon { font-size: 40px; margin-bottom: 12px; }
.drop-zone p { color: var(--text-muted); margin-bottom: 4px; }
.drop-zone__hint { font-size: 13px; margin: 8px 0; }
.drop-zone__formats { font-size: 12px; margin-top: 12px; color: var(--text-muted); opacity: 0.6; }

/* ===== File Info ===== */
.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 12px;
}
.file-info__name {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80%;
}

/* ===== Threshold ===== */
.threshold-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  font-size: 14px;
  color: var(--text-muted);
}
.threshold-row input[type=range] {
  flex: 1;
  accent-color: var(--primary);
  cursor: pointer;
}
.threshold-row span {
  min-width: 36px;
  text-align: right;
  color: var(--text);
  font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn--primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--danger  { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #c94444; }
.btn--ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn--ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn--sm  { padding: 5px 10px; font-size: 12px; }
.btn--lg  { width: 100%; padding: 14px; font-size: 16px; margin-top: 8px; }

/* ===== Mic ===== */
.mic-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.mic-indicator {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.3s;
  flex-shrink: 0;
}
.mic-indicator--active {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(62,207,142,0.2);
  animation: pulse 1.2s infinite;
}
.mic-indicator--leak {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(224,82,82,0.3);
  animation: pulse 0.6s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}
.mic-controls { display: flex; gap: 10px; }
.mic-controls .btn--lg { margin-top: 0; }

/* ===== Live Feed ===== */
.live-feed {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.live-feed__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
#live-rows { max-height: 280px; overflow-y: auto; }
.live-row {
  display: grid;
  grid-template-columns: 60px 1fr 80px 80px;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  animation: fadeIn 0.2s ease;
}
.live-row:last-child { border-bottom: none; }
.live-row--leak { background: rgba(224,82,82,0.08); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }
.live-row__time { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.live-row__bar-wrap { background: var(--surface2); border-radius: 4px; height: 6px; overflow: hidden; }
.live-row__bar { height: 100%; border-radius: 4px; transition: width 0.3s; }
.live-row__score { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.live-row__label { text-align: right; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; }

/* ===== Results ===== */
.results { margin-top: 24px; }

.result-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  margin-bottom: 20px;
  transition: all 0.3s;
}
.result-card--leak    { border-color: var(--danger);  background: rgba(224,82,82,0.08); }
.result-card--no-leak { border-color: var(--success); background: rgba(62,207,142,0.08); }
.result-card__icon { font-size: 40px; }
.result-card__label { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.result-card__scores { font-size: 13px; color: var(--text-muted); display: flex; gap: 16px; }
.result-card__scores strong { color: var(--text); }

/* ===== Timeline ===== */
.timeline h3 { font-size: 14px; font-weight: 600; color: var(--text-muted); margin-bottom: 12px; }
#timeline-bars {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.seg-bar {
  width: 28px; height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  cursor: default;
  transition: transform 0.1s;
  position: relative;
}
.seg-bar:hover { transform: scale(1.15); z-index: 1; }
.seg-bar--leak    { background: var(--danger); color: #fff; }
.seg-bar--no-leak { background: var(--surface2); color: var(--text-muted); }

#timeline-events { display: flex; flex-direction: column; gap: 8px; }
.event-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(224,82,82,0.1);
  border: 1px solid rgba(224,82,82,0.3);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.event-row__time { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 100px; }
.event-row__conf { margin-left: auto; font-weight: 700; color: var(--danger); }

/* ===== Loading ===== */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(15,17,23,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--text-muted); font-size: 14px; }

/* ===== Utility ===== */
.hidden { display: none !important; }
