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

:root {
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --bg: #0f0f13;
  --surface: #1a1a23;
  --surface2: #22222e;
  --text: #f0f0f5;
  --muted: #888;
  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --border: #ffffff10;
  --privacy-bg: #7c3aed18;
  --privacy-border: #7c3aed40;
  --privacy-text: #c4b5fd;
  --toggle-off: #ffffff25;
  --toggle-thumb: #ffffff;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #f0f0f3;
  --text: #111118;
  --muted: #666;
  --border: #00000010;
  --privacy-bg: #ede9fe;
  --privacy-border: #c4b5fd;
  --privacy-text: #6d28d9;
  --toggle-off: #d1d1d6;
  --toggle-thumb: #ffffff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.logo-icon {
  font-size: 1.5rem;
}

.badge {
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

.header-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}

.header-links a:hover { color: var(--text); }

.ext-coming-soon {
  position: relative;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: not-allowed;
  user-select: none;
  opacity: 0.5;
  padding: 2px 4px;
}

.coming-soon-tag {
  position: absolute;
  top: -10px;
  right: -8px;
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--accent);
  color: #fff;
  padding: 2px 5px;
  border-radius: 99px;
  white-space: nowrap;
}

/* ── Theme toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
  line-height: 1;
}
.theme-toggle:hover { background: var(--surface2); }

/* ── Tab hidden warning ── */
.tab-warning {
  text-align: center;
  font-size: 0.78rem;
  padding: 9px 16px;
  background: #f59e0b22;
  color: #f59e0b;
  border-bottom: 1px solid #f59e0b44;
  font-weight: 500;
}

.tab-warning.hidden { display: none; }

/* ── Privacy bar ── */
.privacy-bar {
  text-align: center;
  font-size: 0.78rem;
  padding: 8px 16px;
  background: var(--privacy-bg);
  color: var(--privacy-text);
  border-top: 1px solid var(--privacy-border);
  letter-spacing: 0.1px;
}

/* ── Main layout ── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  padding: 28px 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── Camera panel ── */
.camera-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.video-wrapper {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  overflow: hidden;
  aspect-ratio: 4/3;
  border: 2px solid #ffffff08;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--surface);
}

.video-overlay.hidden { display: none; }

.overlay-icon { font-size: 3rem; }

.video-overlay p {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  max-width: 220px;
  line-height: 1.5;
}

/* Status bar below camera */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 18px;
  border: 2px solid transparent;
  transition: border-color 0.4s, background 0.4s;
}

.status-bar.good  { border-color: var(--good); }
.status-bar.warn  { border-color: var(--warn); }
.status-bar.bad   { border-color: var(--bad);  background: #ef44440d; }

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-bar.good .status-dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.status-bar.warn .status-dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1s infinite; }
.status-bar.bad  .status-dot { background: var(--bad);  box-shadow: 0 0 8px var(--bad);  animation: pulse 0.6s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-text {
  flex: 1;
}

.status-text strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
}

.status-text span {
  font-size: 0.78rem;
  color: var(--muted);
}

.slouch-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.slouch-score label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.score-bar {
  width: 80px;
  height: 6px;
  background: #ffffff15;
  border-radius: 3px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  width: 0%;
  background: var(--good);
  border-radius: 3px;
  transition: width 0.2s, background 0.3s;
}

/* Controls */
.controls {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { opacity: 0.85; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) { background: #2a2a3a; }

/* ── Side panel ── */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid #ffffff08;
}

.card h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 16px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat {
  background: var(--surface2);
  border-radius: 10px;
  padding: 12px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
}

/* Alerts config */
.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #ffffff08;
}

.config-row:last-child { border-bottom: none; }

.config-label {
  font-size: 0.85rem;
}

.config-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Toggle */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--toggle-off);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle input:checked + .toggle-track { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--toggle-thumb);
  border-radius: 50%;
  transition: transform 0.2s;
  pointer-events: none;
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(18px); }

/* Range input */
input[type="range"] {
  -webkit-appearance: none;
  width: 90px;
  height: 4px;
  background: #ffffff20;
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-light);
  cursor: pointer;
}

.range-val {
  font-size: 0.8rem;
  color: var(--accent-light);
  min-width: 30px;
  text-align: right;
}

/* Alert log */
.alert-log {
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alert-log::-webkit-scrollbar { width: 4px; }
.alert-log::-webkit-scrollbar-track { background: transparent; }
.alert-log::-webkit-scrollbar-thumb { background: #ffffff20; border-radius: 2px; }

.log-empty {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  padding: 20px 0;
}

.log-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.log-dot.bad  { background: var(--bad); }
.log-dot.good { background: var(--good); }

.log-time {
  color: var(--muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Slouch alert overlay ── */
#slouch-alert {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--bad);
  color: #fff;
  padding: 16px 22px;
  border-radius: 16px;
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px #ef444455;
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
  z-index: 999;
  pointer-events: none;
}

#slouch-alert.visible {
  transform: translateY(0);
  opacity: 1;
}

/* ── Calibration overlay ── */
#calibration-overlay {
  position: fixed;
  inset: 0;
  background: #0f0f13cc;
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#calibration-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.cal-box {
  background: var(--surface);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  max-width: 360px;
  border: 1px solid #ffffff15;
}

.cal-box h2 { font-size: 1.4rem; margin-bottom: 10px; }
.cal-box p  { color: var(--muted); font-size: 0.9rem; line-height: 1.6; margin-bottom: 28px; }

.cal-countdown {
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 8px;
}

.cal-progress {
  width: 100%;
  height: 4px;
  background: #ffffff15;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 24px;
}

.cal-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.9s linear;
}

/* ── Responsive ── */
@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  header { padding: 14px 16px; }
}
