        :root {
            /* Common Colors */
            --chord-color: #e74c3c;
            --selected-btn-bg: #34495e;
            --selected-btn-color: #fff;

            /* Dark Theme (Default) */
            --bg-body: #121212;
            --bg-paper: #1e1e1e;
            --text-main: #e0e0e0;
            --text-muted: #a0a0a0;
            --text-placeholder: #666;
            --border-color: #333;
            --section-bg: #2d2d2d;
            --instr-bg: #252525;
            --instr-border: #444;
            --sidebar-bg: #1e1e1e;
            --sidebar-border: #333;
            --builder-bg: #252525;
            --btn-bg: #2d2d2d;
            --btn-text: #e0e0e0;
            --btn-hover-bg: #3d3d3d;
            --input-bg: #2d2d2d;
            --chord-badge-bg: rgba(45, 45, 45, 0.9);
            --chord-badge-text: #ff6b6b;
            --highlight-bg: rgba(255, 255, 255, 0.1);
            --selected-word-bg: #0d6efd;
            --selected-word-text: #fff;
        }

        [data-theme="light"] {
            --bg-body: #f0f2f5;
            --bg-paper: #fdfbf7;
            --text-main: #2c3e50;
            --text-muted: #666;
            --text-placeholder: #ccc;
            --border-color: #ddd;
            --section-bg: #eee;
            --instr-bg: #f8f9fa;
            --instr-border: #6c757d;
            --sidebar-bg: #ffffff;
            --sidebar-border: #ddd;
            --builder-bg: #f8f9fa;
            --btn-bg: #ffffff;
            --btn-text: #495057;
            --btn-hover-bg: #e9ecef;
            --input-bg: rgba(0,0,0,0.03);
            --chord-badge-bg: rgba(255, 255, 255, 0.9);
            --chord-badge-text: #e74c3c;
            --highlight-bg: rgba(0,0,0,0.05);
            --selected-word-bg: #cfe2ff;
            --selected-word-text: #000;
        }

        body {
            background-color: var(--bg-body);
            color: var(--text-main);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            height: 100vh;
            overflow: hidden; 
        }

        /* Layout */
        .main-container {
            height: calc(100vh - 60px); 
        }

        .scrollable-col {
            height: 100%;
            overflow-y: auto;
            padding: 20px;
        }

        /* Editor Area (The Paper) */
        #sheet-paper {
            background-color: var(--bg-paper);
            color: var(--text-main);
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            min-height: 100%;
            padding: 50px; /* More padding for header */
            padding-bottom: 100px;
            font-size: 16px;
            line-height: 2.8; 
            position: relative;
            max-width: 21cm; /* A4 width approx */
            margin: 0 auto;
        }

        /* Song Header (Title, Key, etc) */
        .song-header {
            border-bottom: 1px solid var(--border-color);
            margin-bottom: 15px;
            padding-bottom: 10px;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }
        
        .song-title-input {
            font-size: 1.5rem;
            font-weight: bold;
            width: auto;
            min-width: 200px;
            border: none;
            background: transparent;
            outline: none;
            margin-bottom: 0;
            color: var(--text-main);
        }

        .song-artist-input {
            font-size: 1.2rem;
            font-weight: normal;
            width: auto;
            min-width: 150px;
            border: none;
            background: transparent;
            outline: none;
            color: var(--text-muted);
        }
        
        .song-title-input::placeholder, .song-artist-input::placeholder { color: var(--text-placeholder); }

        .meta-row {
            display: flex;
            gap: 15px;
            color: var(--text-muted);
            font-size: 0.85rem;
            align-items: center;
        }

        .meta-input-group {
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .meta-input {
            border: 1px solid transparent;
            background: var(--input-bg);
            color: var(--text-main);
            padding: 2px 5px;
            border-radius: 4px;
            width: 80px;
            font-weight: 600;
        }
        .meta-input:hover, .meta-input:focus {
            border-color: var(--border-color);
            background: var(--bg-paper);
            outline: none;
        }

        /* Import Area */
        #import-area {
            display: none; 
        }

        #import-textarea {
            width: 100%;
            height: 300px;
            border: 2px dashed #ccc;
            padding: 15px;
            border-radius: 8px;
            font-family: monospace;
        }

        /* The Lyric/Word System */
        .song-line {
            margin-bottom: 15px;
            display: flex;
            flex-wrap: wrap;
            align-items: flex-end;
            position: relative;
            min-height: 45px;
            padding-right: 60px; 
            border-bottom: 1px solid transparent;
        }
        
        .song-line:hover {
            border-bottom: 1px solid transparent; /* Removed hover border */
        }

        /* Section Header Styles */
        .section-header-line {
            margin-top: 25px;
            margin-bottom: 15px;
            padding: 5px 10px;
            background-color: var(--section-header-bg);
            border-radius: 4px;
            font-weight: bold;
            font-family: sans-serif;
            text-transform: uppercase;
            letter-spacing: 1px;
            position: relative;
            cursor: text;
            color: var(--text-main);
        }
        
        .section-header-line:hover .line-controls { opacity: 1; }

        /* Line Controls (Edit/Delete) */
        .line-controls {
            position: absolute;
            right: 0;
            bottom: 5px;
            opacity: 0;
            transition: opacity 0.2s;
            z-index: 100;
        }
        
        /* Section Header Controls */
        .section-header-line .line-controls {
            top: 50%;
            transform: translateY(-50%);
            bottom: auto;
        }

        .song-line:hover .line-controls {
            opacity: 1;
        }

        .lyric-word {
            display: inline-flex;
            flex-direction: column;
            justify-content: flex-end;
            position: relative;
            cursor: pointer; 
            margin-right: 6px;
            /* padding-top removed to allow flex stacking */
            transition: background 0.2s;
            border-radius: 4px 4px 0 0; /* Rounded top only */
            white-space: pre; 
            vertical-align: bottom;
            color: var(--text-main);
            border-bottom: 1px dashed var(--text-muted); /* Permanent dashed line */
        }

        .lyric-word:hover {
            background-color: var(--highlight-bg);
        }

        .lyric-word.selected-word {
            background-color: var(--selected-word-bg);
            outline: 2px solid var(--selected-word-bg);
            box-shadow: 0 0 5px var(--selected-word-bg);
            z-index: 5;
            color: var(--selected-word-text);
        }

        .lyric-word.ui-droppable-hover {
            background-color: var(--highlight-bg);
            outline: 2px dashed var(--chord-color);
        }

        /* Instrumental Line Styles */
        .instrumental-line {
            background-color: var(--instr-bg);
            border-left: 4px solid var(--instr-border);
            padding: 10px 15px;
            margin-bottom: 20px;
            border-radius: 0 4px 4px 0;
            position: relative;
            display: flex;
            align-items: center;
        }
        
        .instrumental-line:hover {
            background-color: var(--highlight-bg);
        }

        .instr-label {
            font-weight: bold;
            color: var(--instr-border);
            margin-right: 15px;
            font-size: 0.9rem;
            text-transform: uppercase;
            user-select: none;
        }

        .instr-content {
            flex-grow: 1;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        /* Override lyric-word styles inside instrumental line */
        .instrumental-line .lyric-word {
            padding-top: 0;
            margin-right: 0;
            min-width: 30px;
            height: 30px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: var(--bg-paper);
            border: 1px solid var(--border-color);
            border-radius: 4px;
            color: var(--text-main);
        }

        .instrumental-line .lyric-word:hover {
            border-color: var(--instr-border);
        }

        .instrumental-line .chord-badge {
            position: static; /* Not absolute */
            transform: none;
            background: transparent;
            padding: 0;
            border: none;
            box-shadow: none;
            font-size: 1rem;
            color: var(--chord-badge-text);
        }

        /* The Chord Displayed above words */
        .chord-badge {
            position: relative; /* Changed from absolute to relative for flow */
            margin-bottom: 0px; /* Reduced from 2px to 0px */
            align-self: flex-start;
            font-weight: 700;
            color: var(--chord-badge-text);
            font-size: 0.95em;
            background: var(--chord-badge-bg);
            padding: 0 2px;
            border-radius: 3px;
            cursor: grab;
            user-select: none;
            z-index: 10;
            white-space: nowrap;
            line-height: 1.0; /* Tighter line height */
        }
        
        .chord-badge:hover {
            color: #c0392b;
            transform: scale(1.1);
            z-index: 100;
        }

        /* Quick Edit Input (Popup) */
        .quick-chord-input {
            position: absolute;
            top: -30px;
            left: -5px;
            width: 80px;
            font-size: 14px;
            font-weight: bold;
            padding: 2px 5px;
            border: 2px solid var(--chord-color);
            border-radius: 4px;
            z-index: 1000;
            box-shadow: 0 2px 8px rgba(0,0,0,0.2);
            font-family: 'Segoe UI', sans-serif;
            background: var(--bg-paper);
            color: var(--text-main);
        }

        /* Autocomplete Styling Override */
        .ui-autocomplete {
            max-height: 200px;
            overflow-y: auto;
            overflow-x: hidden;
            font-size: 14px;
            z-index: 1001 !important;
            border-radius: 0 0 4px 4px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            background: var(--bg-paper);
            color: var(--text-main);
            border: 1px solid var(--border-color);
        }
        
        .ui-menu-item .ui-menu-item-wrapper.ui-state-active {
            background: var(--selected-btn-bg);
            color: var(--selected-btn-color);
            border: none;
        }

        /* Edit Mode Input (Line Text) */
        .line-edit-input {
            width: 100%;
            font-size: 16px;
            font-family: inherit;
            padding: 5px;
            border: 2px solid #3498db;
            border-radius: 4px;
            outline: none;
            background: var(--input-bg);
            color: var(--text-main);
        }

        /* Sidebar & Chord Palette */
        #sidebar {
            background: var(--sidebar-bg);
            border-left: 1px solid var(--sidebar-border);
        }

        .chord-builder-section {
            background: var(--builder-bg);
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 15px;
        }

        /* Modular Buttons */
        .builder-btn {
            font-size: 0.85rem;
            padding: 4px 8px;
            margin: 2px;
            border: 1px solid var(--border-color);
            background: var(--btn-bg);
            color: var(--btn-text);
            transition: all 0.2s;
        }

        .builder-btn:hover {
            background-color: var(--btn-hover-bg);
        }

        .builder-btn.active {
            background-color: var(--selected-btn-bg);
            color: var(--selected-btn-color);
            border-color: var(--selected-btn-bg);
        }

        /* Specific widths for layout */
        .btn-root { min-width: 30px; font-weight: bold; }
        .btn-acc { min-width: 30px; }
        .btn-qual { min-width: 40px; }
        .btn-ext { min-width: 35px; }

        .section-label {
            font-size: 0.75rem;
            text-transform: uppercase;
            color: var(--text-muted);
            font-weight: 700;
            margin-bottom: 5px;
            display: block;
        }

        /* The Draggable Source Chord */
        #generated-chord {
            font-size: 2rem;
            font-weight: bold;
            color: var(--chord-color);
            background: var(--bg-paper);
            border: 2px solid var(--chord-color);
            border-radius: 8px;
            padding: 10px 0;
            width: 100%;
            text-align: center;
            display: block;
            cursor: grab;
            margin: 10px 0;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }

        #generated-chord:active {
            cursor: grabbing;
        }

        /* Add Line Buttons */
        .add-btn-group {
            margin-top: 20px;
            display: flex;
            gap: 10px;
        }
        
        .btn-dashed {
            border: 2px dashed #ccc;
            color: #888;
            background: transparent;
            flex: 1;
        }
        .btn-dashed:hover {
            border-color: #3498db;
            color: #3498db;
            background: rgba(52, 152, 219, 0.05);
        }

        /* Print Styles */
        @media print {
            body { height: auto; overflow: visible; background: white; }
            #sidebar, .navbar, #import-controls, .line-controls, .add-btn-group { display: none !important; }
            #sheet-paper { box-shadow: none; padding: 0; width: 100%; max-width: 100%; margin: 0; }
            .col-md-9 { width: 100%; flex: 0 0 100%; max-width: 100%; }
            .song-line { border-bottom: none; }
            .song-title-input { border: none; }
            .meta-input { border: none; background: transparent; padding: 0; width: auto; }
        }
