:root {
  --bg: #0a0b0f;
  --surface: #14161c;
  --surface-hover: #1c1f2a;
  --border: #22263a;
  --text: #e0e4ea;
  --text-muted: #8891a0;
  --text-dim: #555d6e;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(100, 120, 180, 0.06) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(140, 100, 160, 0.04) 0%, transparent 60%);
  animation: drift 20s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift {
  0% { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.1) translate(-2%, 3%); }
}

a { color: var(--accent-hover); text-decoration: none; }

/* Overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 11, 15, 0.97);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-content { text-align: center; max-width: 420px; padding: 2rem; }
.logo-large {
  font-size: 2.2rem; font-weight: 300;
  letter-spacing: 0.3em; text-transform: lowercase;
  color: var(--text); margin-bottom: 1.5rem;
}
.overlay-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 1rem; }
.progress-bar { width: 100%; height: 4px; background: var(--surface); border-radius: 2px; overflow: hidden; margin-bottom: 0.75rem; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); border-radius: 2px; transition: width 0.3s; }
.progress-text { color: var(--text-dim); font-size: 0.8rem; }
.privacy-note-small { color: var(--text-dim); font-size: 0.75rem; margin-top: 1.5rem; opacity: 0.7; }

/* Header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative; z-index: 1;
}
.header-left { display: flex; align-items: center; gap: 1rem; }
header h1 { font-size: 1.3rem; font-weight: 300; letter-spacing: 0.2em; text-transform: lowercase; }
.status { font-size: 0.8rem; padding: 0.25rem 0.6rem; border-radius: 20px; font-weight: 500; }
.status.offline { color: var(--text-muted); background: var(--surface-hover); }
.status.active { color: var(--success); background: var(--success-bg); }
.status.paused { color: var(--warning); background: rgba(245, 158, 11, 0.1); }
.alert-badge {
  background: var(--danger); color: white; font-size: 0.7rem; font-weight: 600;
  padding: 0.15rem 0.5rem; border-radius: 10px;
}

/* Main layout */
main {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 0; min-height: calc(100vh - 52px - 300px);
  position: relative; z-index: 1;
}

/* Panels */
.panel {
  padding: 1.25rem; overflow-y: auto; max-height: calc(100vh - 52px);
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }
.panel h2 { font-size: 0.95rem; font-weight: 500; margin-bottom: 0.25rem; }
.panel-desc { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 1rem; }
.panel-divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0 0.75rem; }

/* Rule list */
#rule-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
#rule-list li {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.65rem; background: var(--surface-hover);
  border-radius: var(--radius-sm); font-size: 0.82rem;
}
#rule-list li .rule-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
#rule-list li .rule-dot.active { background: var(--success); box-shadow: 0 0 6px var(--success); }
#rule-list li .rule-text { flex: 1; }
#rule-list li .remove-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1rem; padding: 0 4px; opacity: 0; transition: opacity 0.2s;
}
#rule-list li:hover .remove-btn { opacity: 1; }
#rule-list li .remove-btn:hover { color: var(--danger); }

/* Add rule */
.add-rule { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; }
.add-rule input {
  flex: 1; padding: 0.45rem 0.7rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 0.82rem; font-family: inherit; outline: none;
}
.add-rule input:focus { border-color: var(--accent); }
.add-rule button {
  width: 34px; height: 34px; background: var(--accent); border: none;
  border-radius: var(--radius-sm); color: white; font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.add-rule button:hover { background: var(--accent-hover); }

/* Settings */
.setting-group { margin-bottom: 0.75rem; }
.setting-group label { font-size: 0.75rem; color: var(--text-muted); display: block; margin-bottom: 0.25rem; }
.setting-group select {
  padding: 0.35rem 0.6rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 0.8rem; font-family: inherit; outline: none; cursor: pointer;
}
.interval-row { display: flex; align-items: center; gap: 0.5rem; }
.interval-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.interval-row span { font-size: 0.7rem; color: var(--text-muted); min-width: 28px; text-align: right; }

/* Volume meter */
.volume-meter { height: 4px; background: var(--border); border-radius: 2px; margin-top: 0.35rem; overflow: hidden; }
.volume-bar { height: 100%; width: 0%; background: var(--success); border-radius: 2px; transition: width 0.1s, background 0.2s; }
.volume-bar.loud { background: var(--danger); }

/* Buttons */
.btn-primary {
  padding: 0.6rem 1.5rem; background: var(--accent); border: none;
  border-radius: var(--radius-sm); color: white; font-size: 0.9rem;
  font-weight: 500; cursor: pointer; font-family: inherit; transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  padding: 0.6rem 1.5rem; background: var(--surface-hover);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 0.9rem; font-weight: 500;
  cursor: pointer; font-family: inherit;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small {
  padding: 0.35rem 0.75rem; background: var(--surface-hover);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 0.8rem; font-family: inherit; cursor: pointer;
}
.btn-small:hover { background: var(--border); }
.btn-small:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small.btn-enabled { color: var(--success); border-color: var(--success); background: var(--success-bg); }
.btn-text {
  background: none; border: none; color: var(--text-muted); font-size: 0.75rem;
  cursor: pointer; font-family: inherit; padding: 0.5rem 0;
}
.btn-text:hover { color: var(--danger); }

/* Feed section */
.feed-section {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 1.25rem; position: relative;
}
.feed-container {
  position: relative; width: 100%; max-width: 720px;
  aspect-ratio: 16 / 9; background: var(--surface);
  border-radius: var(--radius); overflow: hidden; border: 2px solid var(--border);
}
.feed-container video { width: 100%; height: 100%; object-fit: contain; }
.feed-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.5rem; cursor: pointer;
}
.feed-placeholder p { color: var(--text-muted); }
.feed-placeholder .small { font-size: 0.8rem; opacity: 0.6; text-align: center; max-width: 300px; }
.placeholder-explainer {
  margin-top: 1.25rem; text-align: left; max-width: 380px;
  background: rgba(255,255,255,0.02); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.9rem 1rem;
}
.placeholder-explainer p { font-size: 0.75rem; color: var(--text-dim); line-height: 1.7; margin-bottom: 0.5rem; }
.placeholder-explainer p:last-child { margin-bottom: 0; }
.placeholder-explainer strong { color: var(--text-muted); font-weight: 500; }
.feed-placeholder.hidden { display: none; }
.alert-flash {
  position: absolute; inset: 0; border: 4px solid var(--danger);
  border-radius: var(--radius); pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.alert-flash.active { opacity: 1; animation: flash 0.6s ease-in-out 3; }
@keyframes flash { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }
.detecting-indicator {
  position: absolute; top: 0.75rem; left: 0.75rem;
  font-size: 0.7rem; color: var(--success); background: rgba(10, 11, 15, 0.8);
  padding: 0.25rem 0.6rem; border-radius: 20px; display: flex; align-items: center; gap: 0.35rem;
}
.detecting-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.feed-controls { display: flex; gap: 0.75rem; margin-top: 1rem; }

/* Alert list */
.alert-list { display: flex; flex-direction: column; gap: 2px; max-height: 400px; overflow-y: auto; }
.empty-state { color: var(--text-muted); font-size: 0.8rem; text-align: center; padding: 2rem 1rem; line-height: 1.7; }
.alert-count { font-size: 0.75rem; background: var(--danger-bg); color: var(--danger); padding: 0.1rem 0.45rem; border-radius: 10px; font-weight: 600; }
.alert-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.6rem; background: var(--surface-hover);
  border-radius: var(--radius-sm); border-left: 3px solid var(--danger);
  cursor: pointer; transition: background 0.15s; animation: slideIn 0.25s ease;
}
.alert-item.noise { border-left-color: var(--warning); }
.alert-item:hover { background: var(--border); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.alert-item-time { font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.alert-item-rule { font-weight: 500; font-size: 0.75rem; color: var(--danger); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-item.noise .alert-item-rule { color: var(--warning); }
.alert-item-score { font-size: 0.6rem; color: var(--text-dim); flex-shrink: 0; }

/* Preview overlay */
.preview-overlay {
  position: fixed; z-index: 500; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  width: 360px; overflow: hidden; opacity: 0;
  pointer-events: none; transform: scale(0.95); transition: opacity 0.15s, transform 0.15s;
}
.preview-overlay.visible { opacity: 1; pointer-events: auto; transform: scale(1); }
.preview-overlay img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.preview-info { padding: 0.5rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; }
.preview-info span:first-child { font-weight: 500; font-size: 0.8rem; color: var(--danger); }
.preview-info span:last-child { font-size: 0.7rem; color: var(--text-muted); }

/* Footer ad */
.footer-ad { max-width: 728px; margin: 0 auto; padding: 1rem 2rem 0; }

/* Footer */
footer { position: relative; z-index: 1; border-top: 1px solid var(--border); background: var(--surface); }
.privacy-section { max-width: 900px; margin: 0 auto; padding: 2rem 2rem 1.5rem; text-align: center; }
.privacy-section h3 { font-size: 1.1rem; font-weight: 400; margin-bottom: 0.5rem; }
.privacy-main { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1.5rem; max-width: 600px; margin-left: auto; margin-right: auto; }
.privacy-proofs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; text-align: left; }
.proof { background: var(--bg); padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border); }
.proof h4 { font-size: 0.85rem; margin-bottom: 0.4rem; }
.proof p { font-size: 0.75rem; color: var(--text-muted); line-height: 1.6; }
.footer-bottom { text-align: center; padding: 1rem; border-top: 1px solid var(--border); }
.footer-bottom a { color: var(--text-dim); font-size: 0.7rem; letter-spacing: 0.1em; }

/* Responsive */
@media (max-width: 1024px) {
  main { grid-template-columns: 1fr; }
  .panel { border: none; border-bottom: 1px solid var(--border); max-height: none; }
  .panel-right { border-left: none; border-top: 1px solid var(--border); }
}
@media (max-width: 600px) {
  header { padding: 0.5rem 1rem; }
  .panel { padding: 1rem; }
  .privacy-proofs { grid-template-columns: 1fr; }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
