:root {
  --bg-dark: #0a0a12;
  --panel-bg: rgba(22, 33, 62, 0.8);
  --accent: #e94560;
  --secondary: #4ecdc4;
  --text: #ffffff;
  --lane-1: #00ff00;
  --lane-2: #ff0000;
  --lane-3: #ffff00;
  --lane-4: #0066ff;
  --lane-5: #ff6600;
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}

body { 
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
  background: var(--bg-dark); 
  color: var(--text); 
  display: flex;
  flex-direction: column;
}

/* Header */
.header { 
  background: linear-gradient(90deg, #16213e, #1a1a2e); 
  padding: 15px 25px; 
  display: flex; 
  justify-content: space-between;
  align-items: center; 
  border-bottom: 2px solid var(--accent);
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  flex-wrap: wrap;
  gap: 15px;
}
.header-left { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.header h1 { font-size: 1.5rem; letter-spacing: 2px; color: var(--accent); text-transform: uppercase; margin: 0; }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn { 
  padding: 8px 16px; 
  border: none; 
  border-radius: 6px; 
  cursor: pointer; 
  font-weight: 600; 
  font-size: 0.85rem; 
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #ff6b6b; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3); }
.btn-secondary { background: #333; color: #ccc; }
.btn-secondary:hover { background: #444; color: white; }
.btn-success { background: #00aa00; color: white; }
.btn-success:hover { background: #00cc00; }
.speed-btn { padding: 4px 10px; font-size: 0.75rem; min-width: 40px; }
.speed-btn.active { background: var(--accent); color: white; }

.help-links a { color: var(--secondary); text-decoration: none; font-weight: bold; font-size: 0.8rem; }

/* Config Bar */
.config-bar {
  background: var(--panel-bg);
  padding: 10px 25px;
  display: flex;
  gap: 20px;
  border-bottom: 1px solid #222;
  font-size: 0.8rem;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
  align-items: flex-end;
  flex-shrink: 0;
  max-height: 30vh;
  overflow-y: auto;
}
.config-field { display: flex; flex-direction: column; gap: 4px; }
.config-field label { color: #888; font-weight: bold; text-transform: uppercase; font-size: 0.7rem; }
.config-field input { 
  background: #1a1a2e; 
  border: 1px solid #333; 
  border-radius: 4px; 
  color: white; 
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.2s;
  font-size: 0.8rem;
}
.config-field input:focus { border-color: var(--accent); }
.config-field input.short { width: 80px; min-width: 60px; }

/* IDE Area */
.main-workspace { flex: 1; display: flex; background: #0f0f1a; position: relative; overflow: hidden; }

/* Left Sidebar */
.lane-selector { 
  width: 60px; 
  background: #16213e; 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  padding: 20px 0; 
  gap: 15px;
  border-right: 1px solid #333;
  flex-shrink: 0;
}
.lane-btn { 
  width: 40px; 
  height: 40px; 
  border-radius: 50%; 
  border: 2px solid transparent; 
  cursor: pointer; 
  font-weight: bold; 
  font-size: 1.1rem;
  transition: all 0.1s;
  position: relative;
}
.lane-btn:hover { transform: scale(1.1); }
.lane-btn.active { border-color: white; box-shadow: 0 0 15px currentColor; transform: scale(1.15); }
.lane-btn::after {
  content: '';
  position: absolute;
  top: -4px; right: -4px; bottom: -4px; left: -4px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
}
.lb-1 { background: var(--lane-1); color: #000; }
.lb-2 { background: var(--lane-2); color: #fff; }
.lb-3 { background: var(--lane-3); color: #000; }
.lb-4 { background: var(--lane-4); color: #fff; }
.lb-5 { background: var(--lane-5); color: #fff; }

/* Editor Canvas */
.editor-viewport { flex: 1; overflow: auto; position: relative; padding-bottom: 20px; scroll-behavior: smooth; }
.lanes-grid { display: flex; flex-direction: column; padding: 20px; min-width: max-content; }

.lane-row { display: flex; height: 50px; margin-bottom: 5px; align-items: center; }
.lane-id { width: 40px; font-weight: bold; color: #444; font-size: 1.2rem; text-align: center; flex-shrink: 0; }
.lane-track { 
  display: flex; 
  background: rgba(255,255,255,0.03); 
  border-radius: 8px; 
  height: 100%; 
  border: 1px solid rgba(255,255,255,0.05);
  position: relative;
}

.measure-separator {
  position: absolute;
  top: 0;
  height: 100%;
  width: 2px;
  background: rgba(255,255,255,0.1);
  pointer-events: none;
}
.measure-label {
  position: absolute;
  top: -20px;
  font-size: 0.7rem;
  color: #666;
  font-weight: bold;
}

.beat-cell { 
  width: 40px; 
  flex-shrink: 0;
  height: 100%; 
  border-right: 1px solid rgba(255,255,255,0.05); 
  cursor: pointer; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  transition: background 0.1s;
}
.beat-cell:hover { background: rgba(255,255,255,0.1); }
.beat-cell.measure-start { border-left: 2px solid rgba(255,255,255,0.2); }
.beat-cell.current { background: rgba(233, 69, 96, 0.2) !important; position: relative; }
.beat-cell.current::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0; right: 0;
  border: 1px solid var(--accent);
}

.note-marker { 
  width: 24px; 
  height: 24px; 
  border-radius: 50%; 
  box-shadow: 0 0 10px rgba(0,0,0,0.5), inset 0 0 5px rgba(255,255,255,0.5);
  transition: transform 0.1s;
  position: relative;
}
.note-l1 { background: var(--lane-1); box-shadow: 0 0 15px var(--lane-1); }
.note-l2 { background: var(--lane-2); box-shadow: 0 0 15px var(--lane-2); }
.note-l3 { background: var(--lane-3); box-shadow: 0 0 15px var(--lane-3); }
.note-l4 { background: var(--lane-4); box-shadow: 0 0 15px var(--lane-4); }
.note-l5 { background: var(--lane-5); box-shadow: 0 0 15px var(--lane-5); }

.playhead { 
  position: absolute; 
  top: 0; bottom: 0; 
  width: 2px; 
  background: var(--accent); 
  z-index: 50; 
  pointer-events: none;
  box-shadow: 0 0 10px var(--accent);
}
.playhead-tip {
  position: absolute;
  top: -10px;
  left: -6px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

/* Footer */
.footer {
  background: #16213e;
  padding: 15px 25px;
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #333;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.playback-controls { display: flex; gap: 8px; align-items: center; }
.play-btn { width: 50px; height: 50px; border-radius: 50%; background: var(--accent); border: none; color: white; cursor: pointer; font-size: 1.5rem; display: flex; align-items: center; justify-content: center; }
.play-btn:hover { transform: scale(1.05); background: #ff6b6b; }

.time-stats { display: flex; flex-direction: column; align-items: center; min-width: 150px; }
.time-now { font-family: 'JetBrains Mono', monospace; font-size: 1.4rem; color: var(--secondary); font-weight: bold; }
.beat-now { color: #888; font-size: 0.8rem; font-weight: bold; }

.yt-panel { display: flex; gap: 8px; border-left: 1px solid #333; padding-left: 20px; align-items: center; }
.yt-id-input { background: #0f0f1a; border: 1px solid #444; border-radius: 4px; color: white; padding: 8px; width: 120px; font-size: 0.8rem; }

/* Floating Player */
.floating-player {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 320px;
  height: 180px;
  background: #000;
  border: 3px solid #16213e;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
  z-index: 1000;
  transition: all 0.3s;
}
.floating-player:hover { transform: scale(1.05); border-color: var(--accent); }
.player-header { background: #16213e; height: 20px; width: 100%; cursor: move; }

/* Overlay */
.loading-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10,10,18,0.95);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999;
  visibility: hidden; opacity: 0; transition: 0.3s;
}
.loading-overlay.active { visibility: visible; opacity: 1; }
.spinner { width: 50px; height: 50px; border: 5px solid #333; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Stats Panel */
.stats-card {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--panel-bg);
  padding: 15px;
  border-radius: 12px;
  border: 1px solid #333;
  font-size: 0.8rem;
  min-width: 150px;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  pointer-events: none;
}
.stats-card h4 { color: var(--secondary); margin-bottom: 8px; border-bottom: 1px solid #444; padding-bottom: 4px; }
.stats-row { display: flex; justify-content: space-between; margin-bottom: 4px; color: #aaa; }
.stats-value { color: white; font-weight: bold; }

/* Responsive adjustments */
@media (max-width: 800px) {
  body {
    min-height: 100dvh;
  }

  .header {
    padding: 12px;
  }

  .header h1 {
    font-size: 1.15rem;
  }

  .controls {
    gap: 6px;
  }

  .btn {
    padding: 7px 10px;
    font-size: 0.75rem;
  }

  .config-bar {
    padding: 8px 12px;
    gap: 10px;
    max-height: none;
  }

  .config-field {
    min-width: 120px;
  }

  .main-workspace {
    overflow: auto;
    min-height: 44vh;
  }

  .lane-selector {
    width: 50px;
    padding: 12px 0;
    gap: 10px;
  }

  .lane-btn {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .lanes-grid {
    padding: 14px;
  }

  .lane-row {
    height: 44px;
  }

  .lane-id {
    width: 30px;
    font-size: 1rem;
  }

  .beat-cell {
    width: 32px;
  }

  .note-marker {
    width: 18px;
    height: 18px;
  }

  .floating-player {
    width: 240px; height: 135px;
    bottom: 120px; right: 10px;
  }
  .yt-panel { border-left: none; padding-left: 0; width: 100%; justify-content: center; }
  .footer { justify-content: center; padding: 10px; }
  .stats-card { display: none; }
}

@media (max-width: 520px) {
  .header-left {
    width: 100%;
  }

  .controls {
    width: 100%;
  }

  .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .config-field {
    min-width: 100px;
    flex: 1 1 42%;
  }

  .config-field input.short {
    width: 100%;
  }

  .footer {
    gap: 8px;
    padding: 8px;
  }

  .time-now {
    font-size: 1.1rem;
  }

  .beat-now {
    font-size: 0.72rem;
  }

  .play-btn {
    width: 42px;
    height: 42px;
    font-size: 1.25rem;
  }

  .floating-player {
    width: min(62vw, 220px);
    height: auto;
    aspect-ratio: 16 / 9;
    bottom: 138px;
    right: 8px;
  }
}
