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

:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --surface2: #1e1e2e;
  --border: #2a2a3e;
  --text: #e0e0e8;
  --text-dim: #888899;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --sidebar-w: 240px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: 0.5px;
}

#nav-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

#nav-list li {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}

#nav-list li:hover { background: var(--surface2); }
#nav-list li.active {
  background: var(--surface2);
  border-left-color: var(--accent);
  color: var(--accent2);
}

#nav-list li .icon { font-size: 18px; width: 24px; text-align: center; }
#nav-list li .badge {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--green);
  color: #000;
  font-weight: 600;
}
#nav-list li .badge.unsupported { background: var(--red); color: #fff; }

/* Main content */
#content {
  margin-left: var(--sidebar-w);
  height: 100%;
  overflow-y: auto;
  padding: 24px;
}

.sensor-page {
  display: none;
  max-width: 900px;
  margin: 0 auto;
}

.sensor-page.active { display: block; }

.sensor-page h2 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--accent2);
}

.sensor-page .description {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 20px;
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
}

.mode-btn {
  padding: 8px 20px;
  background: var(--surface);
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

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

/* Sensor display */
.sensor-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  min-height: 300px;
}

.sensor-display canvas {
  width: 100%;
  border-radius: 8px;
  background: #000;
}

.sensor-display video {
  width: 100%;
  max-height: 60vh;
  border-radius: 8px;
  background: #000;
  object-fit: cover;
}

/* Data readouts */
.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.readout-item {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
}

.readout-item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.readout-item .value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.readout-item .value.small { font-size: 14px; font-weight: 400; }

/* Permission prompt */
.permission-prompt {
  text-align: center;
  padding: 40px 20px;
}

.permission-prompt p {
  color: var(--text-dim);
  margin-bottom: 16px;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Support grid (welcome) */
#support-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.support-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.support-card:hover { border-color: var(--accent); }
.support-card .sc-icon { font-size: 28px; margin-bottom: 8px; }
.support-card .sc-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.support-card .sc-status {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.support-card .sc-status .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }

/* Spectrograph */
.spectro-canvas { image-rendering: pixelated; }

/* Level / spirit level */
.level-container {
  width: 260px; height: 260px;
  margin: 0 auto;
  position: relative;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
}

.level-bubble {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.1s ease-out;
  box-shadow: 0 0 12px var(--accent);
}

.level-crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 20px; height: 20px;
  border: 2px solid var(--text-dim);
  border-radius: 50%;
}

/* Compass */
.compass-ring {
  width: 260px; height: 260px;
  margin: 0 auto;
  position: relative;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--surface2);
  transition: transform 0.2s ease-out;
}

.compass-needle {
  position: absolute;
  top: 10%; left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 40%;
  background: linear-gradient(to bottom, var(--red), var(--red) 50%, #fff 50%);
  border-radius: 2px;
  transform-origin: bottom center;
}

.compass-label {
  position: absolute;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
}

.compass-label.n { top: 8px; left: 50%; transform: translateX(-50%); color: var(--red); }
.compass-label.s { bottom: 8px; left: 50%; transform: translateX(-50%); }
.compass-label.e { right: 8px; top: 50%; transform: translateY(-50%); }
.compass-label.w { left: 8px; top: 50%; transform: translateY(-50%); }

/* Touch visualizer */
.touch-area {
  width: 100%;
  height: 400px;
  border-radius: 8px;
  background: var(--surface2);
  position: relative;
  touch-action: none;
  overflow: hidden;
}

.touch-point {
  position: absolute;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(99, 102, 241, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent2);
}

/* Fingerprint table */
.fp-table {
  width: 100%;
  border-collapse: collapse;
}
.fp-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.fp-table td:first-child {
  color: var(--text-dim);
  width: 40%;
  font-weight: 500;
}
.fp-table td:last-child {
  font-family: 'SF Mono', 'Fira Code', monospace;
  word-break: break-all;
}

/* Storage bar */
.storage-bar {
  height: 24px;
  background: var(--surface2);
  border-radius: 12px;
  overflow: hidden;
  margin: 8px 0;
}

.storage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 12px;
  transition: width 0.5s ease;
}

/* Hamburger */
#menu-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  width: 40px; height: 40px;
  border-radius: 8px;
  cursor: pointer;
}

/* Error msg */
.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
}

/* Tuner */
.tuner-note {
  font-size: 72px;
  font-weight: 800;
  text-align: center;
  color: var(--accent2);
  line-height: 1;
}
.tuner-freq {
  font-size: 18px;
  text-align: center;
  color: var(--text-dim);
  margin-top: 4px;
}
.tuner-cents {
  width: 200px;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  margin: 16px auto;
  position: relative;
}
.tuner-needle {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
  left: 50%;
  transform: translateX(-50%);
  transition: left 0.1s ease-out;
}

/* Mobile */
@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  #content { margin-left: 0; padding: 60px 16px 16px; }
  #menu-toggle { display: flex; align-items: center; justify-content: center; }
}
