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

:root {
  --bg: #0a0a14;
  --surface: rgba(6, 6, 18, 0.8);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8e8f0;
  --dim: #777;
  --accent: #00d4ff;
  --green: #00ff88;
  --red: #ff4466;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }

/* Loading */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 14px;
  background: var(--bg);
}

.loader-ring {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-title { font-size: 22px; font-weight: 700; }
.loader-subtitle { font-size: 13px; color: var(--dim); }
.error-message { color: var(--red); font-size: 15px; }
.error-detail { color: var(--dim); font-size: 13px; margin-top: 6px; }

/* Main layout */
#main {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Top bar — single row, left-to-right workflow */
#top-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 20px 14px 6px;
  flex-shrink: 0;
  z-index: 10;
  min-height: 42px;
}

#top-bar h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.5px;
  white-space: nowrap;
  color: var(--text);
  flex-shrink: 0;
}

.bar-sep {
  width: 1px;
  height: 22px;
  background: rgba(255,255,255,0.08);
  margin: 0 10px;
  flex-shrink: 0;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  position: relative;
}

#song-group { flex-shrink: 1; min-width: 0; }

/* Step labels */
.step-label {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--dim);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s, transform 0.4s;
}

.step-label.step-active {
  color: var(--accent);
  animation: step-bounce 1.2s ease-in-out infinite;
}

.step-label.step-optional {
  color: rgba(255,255,255,0.3);
  font-style: italic;
}

.step-label.step-done {
  opacity: 0;
  transform: translateX(-50%) translateY(-6px);
}

@keyframes step-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}

#top-bar.steps-done {
  padding-top: 6px;
  transition: padding-top 0.3s;
}
#top-bar.steps-done .step-label { display: none; }

/* Bar buttons (shared style) */
#top-bar button.bar-btn {
  background: rgba(255,255,255,0.06);
  color: var(--dim);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
#top-bar button.bar-btn:hover { color: var(--text); border-color: var(--accent); }
#upstrum-btn.active { background: var(--green); color: #000; border-color: var(--green); font-weight: 600; }
#calibrate-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }

.bar-btn-disabled {
  opacity: 0.3;
  cursor: not-allowed !important;
  pointer-events: none;
}

.input-disabled {
  opacity: 0.3;
  pointer-events: none;
}

#custom-song-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.play-disabled {
  opacity: 0.3;
  cursor: not-allowed !important;
}

#calibrate-btn.needs-attention {
  border-color: var(--red);
  color: var(--red);
  animation: pulse-attention 1.5s ease-in-out infinite;
}

@keyframes pulse-attention {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
  50% { box-shadow: 0 0 8px 2px rgba(255, 68, 68, 0.4); }
}

/* Color swatches */
#color-swatches {
  display: flex;
  gap: 4px;
  align-items: center;
}

.color-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  padding: 0;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; box-shadow: 0 0 6px rgba(255,255,255,0.3); }

/* Search */
.song-search-wrap {
  position: relative;
  flex: 1;
  min-width: 120px;
  max-width: 280px;
}

#song-search {
  appearance: none;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 16px;
  padding: 5px 10px 5px 28px;
  font-size: 11px;
  font-family: inherit;
  outline: none;
  width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='11' cy='11' r='7' stroke='%23777' stroke-width='2'/%3E%3Cpath d='M16 16l4 4' stroke='%23777' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center;
  transition: border-color 0.15s, background 0.15s;
}
#song-search:focus {
  border-color: var(--accent);
  background: rgba(255,255,255,0.09);
}
#song-search::placeholder { color: var(--dim); }

#song-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: rgba(16, 16, 28, 0.97);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.song-option {
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.song-option:first-child { border-radius: 8px 8px 0 0; }
.song-option:last-child { border-radius: 0 0 8px 8px; }
.song-option:hover { background: rgba(0, 212, 255, 0.10); }
.song-option .song-artist { color: var(--dim); font-size: 11px; }
.song-option.searching { color: var(--dim); font-style: italic; pointer-events: none; }

/* + Song button */
#custom-song-btn {
  background: rgba(255,255,255,0.06);
  color: var(--dim);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
#custom-song-btn:hover { color: var(--text); border-color: var(--accent); }

/* Pattern label */
#pattern-label { min-width: 80px; text-align: center; }

/* Playback group */
.playback-group {
  display: flex;
  flex-shrink: 0;
}

#play-btn, #auto-btn {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 5px 13px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.1s;
}
#play-btn {
  border-radius: 5px 0 0 5px;
  border-right: 1px solid rgba(0,0,0,0.15);
}
#auto-btn {
  border-radius: 0 5px 5px 0;
}
#play-btn:hover, #auto-btn:hover { filter: brightness(1.15); }
#play-btn.active { background: var(--red); color: #fff; }
#auto-btn.active { background: var(--green); color: #000; }

/* Transport */
.transport {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding-left: 6px;
}

#chord-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  min-width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#beat-dots {
  display: flex;
  gap: 3px;
}

#beat-dots .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  transition: background 0.1s;
}

#beat-dots .dot.on {
  background: var(--accent);
}

#calibrate-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

#calibrate-overlay video {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scaleX(-1);
  opacity: 0.7;
}

#calibrate-canvas {
  position: absolute;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#calibrate-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: var(--accent);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}

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

#chord-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  min-width: 60px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#beat-dots {
  display: flex;
  gap: 5px;
}

#beat-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  transition: background 0.1s;
}

#beat-dots .dot.on {
  background: var(--accent);
}

/* Stage */
#stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#guitar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Camera picture-in-picture */
#camera-pip {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 160px;
  height: 120px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
  opacity: 0.75;
  z-index: 5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

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

/* Bottom bar: chord progression */
#bottom-bar {
  padding: 8px 16px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  white-space: nowrap;
  text-align: center;
}

#progression {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.chord-pill {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.35);
  transition: all 0.15s;
}

.chord-pill.active {
  background: rgba(0, 212, 255, 0.18);
  color: #fff;
  font-weight: 600;
}

.chord-pill.past {
  background: rgba(255,255,255,0.02);
  color: rgba(255,255,255,0.18);
}

.chord-pill.next {
  color: rgba(255,255,255,0.55);
}

/* Onboarding */
#onboarding {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(6, 6, 18, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ob-card {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 420px;
  padding: 36px 32px 28px;
  gap: 16px;
  animation: obFadeIn 0.3s ease;
}

.ob-card.active { display: flex; }

.ob-card-wide { max-width: 560px; }

@keyframes obFadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.ob-card h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.ob-card p {
  font-size: 15px;
  color: rgba(255,255,255,0.7);
  line-height: 1.5;
  max-width: 380px;
}

.ob-small { font-size: 13px; color: var(--green); }

.ob-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 10px 32px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-top: 4px;
}
.ob-primary:hover { filter: brightness(1.1); }
.ob-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: none;
}

.ob-skip {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 8px;
}
.ob-skip:hover { color: var(--text); }

.ob-tips {
  text-align: left;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
}

.ob-tips li {
  font-size: 14px;
  color: rgba(255,255,255,0.75);
  line-height: 1.4;
  padding-left: 20px;
  position: relative;
}

.ob-tips li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
}

.ob-camera-preview {
  width: 320px;
  height: 240px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
}

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

.ob-calibrate-area {
  position: relative;
  width: 480px;
  height: 360px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
}

.ob-calibrate-area video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.ob-calibrate-area canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#ob-cal-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: var(--accent);
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}

.ob-dots {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.ob-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  transition: background 0.2s;
}

.ob-dot.active { background: var(--accent); }
.ob-dot.done { background: rgba(255,255,255,0.35); }

/* Custom song button inherits from #settings-row button */

/* Modal */
#custom-song-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: #141420;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 28px 32px;
  width: 380px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-content h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.modal-content label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-content label span {
  font-size: 12px;
  color: var(--dim);
  font-weight: 500;
}

.modal-content input {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.modal-content input:focus { border-color: var(--accent); }

.modal-hint {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.modal-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.modal-primary:hover { filter: brightness(1.1); }

.modal-secondary {
  background: none;
  color: var(--dim);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.modal-secondary:hover { color: var(--text); border-color: rgba(255,255,255,0.25); }

/* Responsive */
@media (max-width: 700px) {
  #top-bar { flex-wrap: wrap; padding: 22px 10px 6px; gap: 4px; }
  #top-bar.steps-done { padding-top: 6px; }
  .bar-sep { display: none; }
  .step-label { font-size: 8px; top: -15px; }
  #song-group { flex-basis: 100%; order: 10; }
  .song-search-wrap { max-width: none; }
  #camera-pip { width: 120px; height: 90px; top: 8px; right: 8px; }
  .ob-card { padding: 24px 20px 20px; }
  .ob-calibrate-area { width: 100%; height: 280px; }
  .ob-camera-preview { width: 260px; height: 195px; }
}
