:root {
    --bg-primary: #09090b;
    --bg-secondary: #121217;
    --bg-tertiary: #1a1a24;
    --glass-bg: rgba(18, 18, 24, 0.65);
    --glass-border: rgba(255, 255, 255, 0.07);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --secondary: #a855f7;
    --secondary-glow: rgba(168, 85, 247, 0.4);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.4);
    --danger: #ef4444;
    
    --font-sans: 'Outfit', sans-serif;
    --font-mono: 'Space Grotesk', sans-serif;
    
    --sidebar-width: 340px;
    --header-height: 70px;
    --piano-key-width: 60px;
    --piano-key-height: 20px; /* height of a semitone note row */
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* BACKGROUND GLOWS */
.glow-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-sphere {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
    animation: float 20s infinite alternate ease-in-out;
}

.sphere-1 {
    width: 400px;
    height: 400px;
    background: var(--primary);
    top: -100px;
    left: -100px;
    animation-delay: 0s;
}

.sphere-2 {
    width: 500px;
    height: 500px;
    background: var(--secondary);
    bottom: -150px;
    right: -100px;
    animation-delay: 5s;
}

.sphere-3 {
    width: 300px;
    height: 300px;
    background: var(--success);
    top: 40%;
    left: 50%;
    animation-delay: 10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 30px) scale(1.1); }
}

/* SCROLLBARS */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* GLASS PANEL UTILITY */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: var(--glass-shadow);
}

.gradient-text {
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.text-glow {
    text-shadow: 0 0 10px var(--primary-glow);
}

/* 1. WELCOME SCREEN */
.welcome-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
    transition: opacity 0.5s ease;
}

.welcome-card {
    max-width: 650px;
    width: 100%;
    padding: 40px;
    text-align: center;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 30px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.logo-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 3.5rem;
    color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 15px var(--primary-glow));
    margin-bottom: 10px;
}

.app-title {
    font-family: var(--font-mono);
    font-size: 2.8rem;
    letter-spacing: -1px;
    font-weight: 800;
}

.app-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.setup-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 10px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 10px;
}

@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.custom-select {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.custom-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.btn-glow:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.6), 0 0 30px rgba(168, 85, 247, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
    border-radius: 6px;
}

.footer-note {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* 2. LOADING OVERLAY */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(9, 9, 11, 0.9);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.loader-content {
    text-align: center;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.music-note-loader {
    display: flex;
    gap: 15px;
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 10px;
}

.music-note-loader i {
    animation: bounce 1s infinite alternate;
}

.music-note-loader .note-1 { animation-delay: 0s; }
.music-note-loader .note-2 { animation-delay: 0.2s; color: var(--secondary); }
.music-note-loader .note-3 { animation-delay: 0.4s; color: var(--success); }

@keyframes bounce {
    0% { transform: translateY(0); filter: drop-shadow(0 0 2px transparent); }
    100% { transform: translateY(-20px); filter: drop-shadow(0 0 10px var(--primary-glow)); }
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 3px;
    animation: fillProgress 3.5s forwards linear;
}

@keyframes fillProgress {
    0% { width: 0%; }
    100% { width: 100%; }
}

.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* 3. MAIN WORKSPACE (DORICO STYLE) */
.main-workspace {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* HEADER */
.workspace-header {
    height: var(--header-height);
    margin: 10px;
    margin-bottom: 5px;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    z-index: 10;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-family: var(--font-mono);
    font-weight: 700;
}

.badge {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid var(--primary);
    color: var(--text-primary);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-family: var(--font-sans);
    margin-left: 10px;
}

/* PLAYBACK CONTROLS */
.playback-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 6px 20px;
    border-radius: 30px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.control-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}

#btn-play:hover {
    color: var(--success);
    background: var(--success-glow);
}

.control-btn:active {
    transform: scale(0.95);
}

.divider {
    width: 1px;
    height: 20px;
    background: var(--glass-border);
}

.tempo-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.tempo-control input {
    width: 50px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 3px 5px;
    font-family: var(--font-mono);
    font-weight: bold;
    outline: none;
    text-align: center;
}

.time-signature-badge {
    display: flex;
    flex-direction: column;
    line-height: 1;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    border: 1px solid var(--text-muted);
    padding: 2px 4px;
    border-radius: 3px;
    align-items: center;
}

.time-display {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* HEADER ACTIONS */
.header-actions {
    display: flex;
    gap: 10px;
}

.action-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.primary-btn {
    background: var(--primary);
    color: white;
}
.primary-btn:hover { background: #5053e6; }

.secondary-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}
.secondary-btn:hover { background: rgba(255, 255, 255, 0.08); }

.success-btn {
    background: var(--success);
    color: white;
}
.success-btn:hover { background: #0ea5e9; } /* tealish */

/* WORKSPACE LAYOUT */
.workspace-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 0 10px 10px 10px;
    gap: 10px;
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    overflow-y: auto;
}

.section-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 6px;
}

.meta-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.meta-label {
    color: var(--text-secondary);
}

.meta-input {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 4px 8px;
    width: 60%;
    outline: none;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    text-align: right;
}

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

.meta-value {
    font-weight: 600;
    color: var(--text-primary);
}

.harmony-card {
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.03);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.harmony-card h5 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.chord-progression-container {
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.chord-badge {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 6px 2px;
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--secondary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.chord-badge:hover {
    transform: scale(1.05);
    border-color: var(--secondary);
}

.flexible-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 250px;
}

.lyrics-editor-wrapper {
    flex: 1;
    position: relative;
    margin-bottom: 10px;
    min-height: 100px;
}

.lyrics-textarea {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 10px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    outline: none;
}

.lyrics-textarea:focus {
    border-color: var(--primary);
}

/* EDITOR AREA */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

/* SCORE PANEL */
.score-panel {
    flex: 4; /* occupies 4 parts */
    display: flex;
    flex-direction: column;
    padding: 15px;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hint-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.score-viewport {
    flex: 1;
    background: #18181c; /* Studio Grey dark style */
    border-radius: 8px;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#vexflow-container {
    padding: 20px;
    min-width: 800px;
    transform-origin: top center;
}

/* Make VexFlow SVG dark-theme readable */
#vexflow-container svg path, 
#vexflow-container svg rect,
#vexflow-container svg text {
    fill: #e4e4e7 !important;
    stroke: #e4e4e7 !important;
}

#vexflow-container svg text {
    stroke: none !important;
    font-family: var(--font-sans) !important;
}

/* Style lyrics in VexFlow specifically */
#vexflow-container svg .vf-lyric {
    fill: var(--text-secondary) !important;
    font-weight: 500;
}

#vexflow-container svg .vf-notehead path {
    fill: #e4e4e7 !important;
}

/* Active Highlight classes inside Vexflow SVG */
#vexflow-container svg .note-highlight path,
#vexflow-container svg .note-highlight rect {
    fill: var(--primary) !important;
    stroke: var(--primary) !important;
    filter: drop-shadow(0 0 4px var(--primary));
}

#vexflow-container svg .note-highlight .vf-lyric {
    fill: var(--primary) !important;
    font-weight: bold;
}

/* PIANO ROLL PANEL */
.piano-roll-panel {
    flex: 3; /* occupies 3 parts */
    display: flex;
    flex-direction: column;
    padding: 15px;
    overflow: hidden;
}

.panel-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.2s ease;
}

.panel-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

.divider-v {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 0 5px;
}

.piano-roll-viewport {
    flex: 1;
    background: #0d0d11;
    border-radius: 8px;
    overflow: auto;
    position: relative;
    border: 1px solid rgba(255,255,255,0.05);
}

.piano-roll-container {
    display: flex;
    position: relative;
    height: 100%;
}

.piano-keys-wrapper {
    width: var(--piano-key-width);
    flex-shrink: 0;
    background: #121216;
    border-right: 2px solid #222;
    z-index: 5;
    position: sticky;
    left: 0;
}

.piano-key {
    height: var(--piano-key-height);
    width: 100%;
    border-bottom: 1px solid #1f1f26;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 0.65rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    position: relative;
    user-select: none;
    box-sizing: border-box;
}

.piano-key.white {
    background: #ffffff;
    color: #333333;
}

.piano-key.black {
    background: #1e1e24;
    color: #888888;
}

.piano-key.active {
    background: var(--primary) !important;
    color: white !important;
}

.piano-grid-wrapper {
    flex: 1;
    position: relative;
    overflow: visible;
}

#piano-roll-canvas {
    display: block;
    cursor: crosshair;
}

.playhead-cursor {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background-color: var(--danger);
    box-shadow: 0 0 8px var(--danger);
    pointer-events: none;
    z-index: 4;
}

/* TOAST NOTIFICATIONS */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background: rgba(18, 18, 24, 0.9);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    font-size: 0.9rem;
    transform: translateY(50px);
    opacity: 0;
    animation: toastIn 0.3s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-left: 4px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.info { border-left-color: var(--primary); }
.toast.danger { border-left-color: var(--danger); }

@keyframes toastIn {
    to { transform: translateY(0); opacity: 1; }
}

.toast.fade-out {
    animation: toastOut 0.3s forwards ease-in;
}

@keyframes toastOut {
    to { transform: translateY(-20px); opacity: 0; }
}
