/* === Theme Variables === */
:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #242424;
  --bg-surface: #0a0a0a;
  --bg-panel: #1e1e1e;
  --accent: #00d9ff;
  --accent-dim: #00698a;
  --accent-glow: rgba(0, 217, 255, 0.3);
  --red: #ff3b3b;
  --yellow: #ffd700;
  --green: #00ff6a;
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --text-dim: #555;
  --border: #333;
  --border-light: #444;
  --shadow-inset: inset 0 2px 8px rgba(0, 0, 0, 0.6);
  --shadow-raised: 0 2px 12px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-sm: 4px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

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

/* === Base === */
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-user-select: none;
  user-select: none;
}

/* === App Layout === */
#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Start Overlay === */
#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.97);
  backdrop-filter: blur(20px);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#start-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-content {
  text-align: center;
}

.start-title {
  font-size: 64px;
  font-weight: 200;
  letter-spacing: 24px;
  padding-left: 24px;
  color: var(--accent);
  text-shadow: 0 0 40px var(--accent-glow);
  margin-bottom: 8px;
}

.start-subtitle {
  font-size: 14px;
  letter-spacing: 6px;
  padding-left: 6px;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 48px;
}

#start-button {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 4px;
  padding: 16px 48px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.3s ease;
}

#start-button:hover {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 30px var(--accent-glow);
}

.start-hint {
  margin-top: 24px;
  font-size: 12px;
  color: #b3b3b3;
  letter-spacing: 1px;
}

.start-error {
  margin-top: 20px;
  font-size: 13px;
  color: var(--red);
  letter-spacing: 1px;
}

/* === Header === */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #222 0%, var(--bg-primary) 100%);
  flex-shrink: 0;
}

.logo {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 6px;
  color: var(--text-primary);
}

.version {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 2px;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all 0.2s ease;
}

.status-led.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.status-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 2px;
}

/* === Camera Video === */
#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  z-index: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#tracking-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* === Main Layout === */
#main {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}

/* === Play Surface === */
#play-surface {
  flex: 1;
  position: relative;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  cursor: crosshair;
  touch-action: none;
  overflow: hidden;
}

#play-surface.playing {
  box-shadow: inset 0 0 60px var(--accent-glow);
}

#visual-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.crosshair {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 0 12px var(--accent-glow);
}

.crosshair.visible {
  opacity: 1;
}

/* === Controls Panel === */
#controls-panel {
  width: 200px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #222 0%, var(--bg-panel) 40%, #1a1a1a 100%);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

/* === Pitch Display === */
.pitch-display {
  text-align: center;
  padding: 12px 0;
}

.note-name {
  font-family: var(--font-mono);
  font-size: 42px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  line-height: 1;
  transition: color 0.1s ease;
}

.frequency {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* === Volume Meter === */
.volume-meter {
  width: 100%;
  height: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-inset);
}

.meter-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(to top, var(--green) 0%, var(--yellow) 70%, var(--red) 100%);
  transition: height 0.05s linear;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.meter-segments {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to top,
    transparent 0px,
    transparent 6px,
    var(--bg-surface) 6px,
    var(--bg-surface) 8px
  );
  pointer-events: none;
}

.meter-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 4px;
}

/* === Dial === */
.dial-row {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.dial-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
}

.dial {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #3a3a3a, #1a1a1a 70%);
  border: 2px solid var(--border-light);
  position: relative;
  cursor: grab;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  touch-action: none;
}

.dial-sm {
  width: 52px;
  height: 52px;
}

.dial:active {
  cursor: grabbing;
}

.dial-track {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.dial-indicator {
  position: absolute;
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 2px;
  left: 50%;
  top: 6px;
  transform-origin: 50% 30px;
  transform: translateX(-50%) rotate(-135deg);
  box-shadow: 0 0 6px var(--accent-glow);
  transition: transform 0.05s ease-out;
}

.dial-sm .dial-indicator {
  height: 12px;
  top: 5px;
  transform-origin: 50% 21px;
}

.dial-sm .dial-track {
  inset: 3px;
}

.dial-name {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-align: center;
}

.dial-value {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
}

/* === Effects === */
.effect-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.effect-name {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.effect-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.effect-indicator.active {
  background: var(--green);
  box-shadow: 0 0 6px rgba(0, 255, 106, 0.5);
}

/* === Signal Chain === */
.signal-chain {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.signal-node {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  width: 100%;
  text-align: center;
}

.signal-arrow {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
}

/* === Surface Title === */
.surface-title {
  position: absolute;
  top: 12px;
  left: 20px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 6px;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  z-index: 10;
}

/* === Surface Stop Button === */
#stop-surface-button {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.7);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 3px;
  padding: 10px 32px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

#stop-surface-button:hover {
  background: rgba(0, 0, 0, 0.85);
  border-color: var(--red);
  color: var(--red);
}

/* === Piano Keys === */
.piano-strip {
  position: absolute;
  left: 0;
  right: 0;
  top: 33.33%;
  bottom: 33.33%;
  pointer-events: none;
  z-index: 6;
  opacity: 0.5;
  transition: opacity 0.3s ease;
}

.piano-strip.hidden {
  opacity: 0;
}

.piano-key {
  position: absolute;
  top: 0;
  bottom: 0;
}

.piano-key-white {
  background: rgba(255, 255, 255, 0.85);
  border-left: 1px solid rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.piano-key-black {
  background: rgba(0, 0, 0, 0.85);
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-left: 1px solid rgba(0, 0, 0, 0.9);
  border-right: 1px solid rgba(0, 0, 0, 0.9);
}

.piano-key-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgba(0, 0, 0, 0.4);
  padding-bottom: 6px;
  letter-spacing: 0;
}

.piano-key-label-black {
  color: rgba(255, 255, 255, 0.6);
}

/* === Finger Prompt === */
.finger-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
  transition: opacity 0.3s ease;
}

.finger-prompt.hidden {
  opacity: 0;
}

.finger-prompt-text {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* === Hidden State === */
#header.hidden,
#main.hidden {
  display: none;
}

/* === Stop Button === */
#stop-button {
  background: transparent;
  border: 1px solid var(--text-dim);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin-left: 12px;
  transition: all 0.2s ease;
}

#stop-button:hover {
  border-color: var(--red);
  color: var(--red);
}
