* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0d1a;
  --surface: #111827;
  --surface2: #1a2235;
  --accent: #4f7cff;
  --accent2: #7c5cff;
  --green: #34d399;
  --red: #f87171;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(255,255,255,0.07);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79,124,255,0.15), transparent),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(124,92,255,0.08), transparent);
}

.container {
  max-width: 440px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* Video */
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  background: #000;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
}

#video { width: 100%; height: 100%; object-fit: cover; }
#canvas { display: none; }

.cover-status {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: color 0.3s;
}

/* BPM overlay on video */
.bpm-overlay {
  position: absolute;
  bottom: 16px;
  right: 16px;
  text-align: right;
}

.bpm-overlay .bpm-value {
  font-size: 52px;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
  text-shadow: 0 0 30px rgba(52,211,153,0.4);
}

.bpm-overlay .bpm-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* Controls */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

button {
  padding: 14px;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.15s;
}

button:active::after { background: rgba(255,255,255,0.1); }

#startBtn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  box-shadow: 0 4px 20px rgba(79,124,255,0.35);
}

#startBtn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(79,124,255,0.45);
}

#startBtn:disabled {
  background: var(--surface2);
  color: var(--muted);
  box-shadow: none;
}

#stopBtn {
  background: rgba(248,113,113,0.15);
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.25);
}

#stopBtn:hover:not(:disabled) {
  background: rgba(248,113,113,0.25);
}

#stopBtn:disabled {
  background: var(--surface2);
  color: var(--muted);
  border-color: transparent;
}

.torch-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.torch-row label {
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border-radius: 20px;
  transition: background 0.2s;
  border: 1px solid var(--border);
}

.toggle input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }

.toggle-track::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* Progress */
.progress-wrap {
  margin-bottom: 16px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.progress-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

#status {
  font-size: 12px;
  color: var(--muted);
}

.progress {
  width: 100%;
  height: 4px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Waveform */
.waveform-wrap {
  background: var(--surface);
  border-radius: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.waveform-title {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

#waveform {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 8px;
}

/* Tips */
.tips {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.tips summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 14px 16px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.tips summary::after {
  content: '›';
  font-size: 18px;
  color: var(--muted);
  transition: transform 0.2s;
}

.tips[open] summary::after { transform: rotate(90deg); }

.tips-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.tips ul {
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  margin-top: 12px;
}

.tips li b { color: var(--text); font-weight: 600; }
