/* ==========================================================================
   Typographic Music Composer - Modern Web App Design System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:ital,wght@0,400;0,500;0,700;1,400&family=Outfit:wght@400;600;700;800&display=swap');

:root {
  /* Color Palette - Cyber Dark (Default) */
  --bg-main: #0b0d14;
  --bg-card: rgba(18, 22, 34, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-hover: rgba(26, 32, 48, 0.85);
  --bg-input: #07090e;
  
  --primary: #00f0ff;
  --primary-glow: rgba(0, 240, 255, 0.35);
  --primary-dark: #0099b8;
  
  --accent: #ff007f;
  --accent-glow: rgba(255, 0, 127, 0.35);
  
  --secondary: #7000ff;
  --secondary-glow: rgba(112, 0, 255, 0.3);
  
  --success: #00ff9d;
  --warning: #ffb700;
  
  --text-main: #f0f4f8;
  --text-muted: #8a99ad;
  --text-dim: #4c586e;
  
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-code: 'JetBrains Mono', monospace;
  
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 240, 255, 0.05);
  --shadow-glow: 0 0 25px var(--primary-glow);
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-main: #f4f6fa;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-border: rgba(0, 0, 0, 0.08);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --bg-input: #eef2f7;
  
  --primary: #0070f3;
  --primary-glow: rgba(0, 112, 243, 0.2);
  --primary-dark: #0051b3;
  
  --accent: #d9006c;
  --accent-glow: rgba(217, 0, 108, 0.2);
  
  --text-main: #1a202c;
  --text-muted: #4a5568;
  --text-dim: #a0aec0;
  
  --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.08);
}

/* Emerald Theme */
[data-theme="emerald"] {
  --bg-main: #061410;
  --bg-card: rgba(12, 33, 26, 0.8);
  --bg-card-border: rgba(0, 255, 157, 0.15);
  --primary: #00ff9d;
  --primary-glow: rgba(0, 255, 157, 0.35);
  --accent: #00e5ff;
  --secondary: #00b36b;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(0, 240, 255, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(255, 0, 127, 0.04) 0%, transparent 45%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header & Top Navbar */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.75rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--bg-card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.2rem;
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--text-main), var(--text-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(0, 240, 255, 0.12);
  color: var(--primary);
  border: 1px solid rgba(0, 240, 255, 0.2);
}

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

/* Control Buttons & Selects */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.55rem 1.1rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #001e2b;
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
  filter: brightness(1.1);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #cc0066);
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-accent:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.btn-icon-only {
  padding: 0.55rem;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
}

.select-custom {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.select-custom:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

/* App Main Layout Grid */
.app-container {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr auto;
  gap: 1.25rem;
  padding: 1.25rem 1.75rem;
  flex: 1;
  max-width: 1700px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 1100px) {
  .app-container {
    grid-template-columns: 1fr;
  }
}

/* Top Toolbar Bar */
.toolbar-panel {
  grid-column: 1 / -1;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow-main);
}

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

.synth-quick-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-item label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.number-input {
  background: var(--bg-input);
  border: 1px solid var(--bg-card-border);
  color: var(--primary);
  font-family: var(--font-code);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  width: 65px;
  text-align: center;
  outline: none;
}

.number-input:focus {
  border-color: var(--primary);
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  outline: none;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 8px var(--primary-glow);
  transition: transform 0.1s;
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

/* Left Section: Editor & Visualizer */
.main-stage {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Visualizer Card */
.visualizer-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-main);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  color: var(--primary);
}

.canvas-container {
  position: relative;
  width: 100%;
  height: 140px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(5, 7, 12, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

#visCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Code Editor Card */
.editor-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 380px;
  box-shadow: var(--shadow-main);
  position: relative;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.85rem;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid var(--bg-card-border);
  flex-wrap: wrap;
  gap: 10px;
}

.editor-quick-helper {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-code);
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-btn:hover {
  background: rgba(0, 240, 255, 0.12);
  color: var(--primary);
  border-color: rgba(0, 240, 255, 0.3);
}

/* Custom Editor Area with Sync Line Highlighting */
.editor-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
  overflow: hidden;
}

.line-numbers {
  width: 42px;
  padding: 1rem 0;
  background: rgba(0, 0, 0, 0.25);
  border-right: 1px solid var(--bg-card-border);
  color: var(--text-dim);
  font-family: var(--font-code);
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: right;
  padding-right: 10px;
  user-select: none;
}

.line-numbers .active-line-num {
  color: var(--primary);
  font-weight: bold;
}

.editor-area-container {
  position: relative;
  flex: 1;
  overflow: hidden;
}

/* Textarea & Overlay */
.code-editor {
  width: 100%;
  height: 100%;
  min-height: 320px;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-code);
  font-size: 0.92rem;
  line-height: 1.6;
  padding: 1rem;
  border: none;
  outline: none;
  resize: none;
  white-space: pre;
  overflow-x: auto;
  overflow-y: auto;
  position: relative;
  z-index: 2;
  caret-color: var(--primary);
}

.editor-highlight-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem;
  font-family: var(--font-code);
  font-size: 0.92rem;
  line-height: 1.6;
  pointer-events: none;
  white-space: pre;
  z-index: 1;
  color: transparent;
}

.highlight-step {
  background: rgba(0, 240, 255, 0.25);
  border-radius: 3px;
  box-shadow: 0 0 10px var(--primary-glow);
  color: #fff !important;
}

/* Right Sidebar: Synth Controls & Presets */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.synth-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-main);
}

.synth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.85rem;
}

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

.synth-control-group.full-width {
  grid-column: 1 / -1;
}

.synth-control-group label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
}

.synth-control-group label span {
  color: var(--primary);
  font-family: var(--font-code);
}

/* Virtual Piano Keyboard */
.keyboard-card {
  grid-column: 1 / -1;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-main);
}

.piano-keys-container {
  display: flex;
  justify-content: center;
  position: relative;
  height: 100px;
  margin-top: 0.5rem;
  user-select: none;
  overflow-x: auto;
  padding-bottom: 5px;
}

.piano-key {
  position: relative;
  cursor: pointer;
  transition: background var(--transition-fast), transform 0.08s;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  font-family: var(--font-code);
  font-size: 0.65rem;
  font-weight: 700;
}

.piano-key.white {
  width: 38px;
  height: 90px;
  background: #e2e8f0;
  color: #4a5568;
  border: 1px solid #cbd5e0;
  border-radius: 0 0 6px 6px;
  z-index: 1;
}

.piano-key.white:hover {
  background: #fff;
}

.piano-key.black {
  width: 24px;
  height: 56px;
  background: #1a202c;
  color: #a0aec0;
  border: 1px solid #000;
  border-radius: 0 0 4px 4px;
  margin-left: -12px;
  margin-right: -12px;
  z-index: 2;
}

.piano-key.black:hover {
  background: #2d3748;
}

.piano-key.active {
  background: var(--primary) !important;
  color: #001e2b !important;
  box-shadow: 0 0 15px var(--primary-glow);
  transform: translateY(2px);
}

.piano-key.black.active {
  background: var(--accent) !important;
  color: #fff !important;
  box-shadow: 0 0 15px var(--accent-glow);
}

/* Footer Status Bar */
.app-footer {
  padding: 0.65rem 1.75rem;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--bg-card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

.status-dot.playing {
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
  animation: pulse-dot 1.2s infinite alternate;
}

@keyframes pulse-dot {
  0% { opacity: 0.6; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1.1); }
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.15);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}
