* {
    box-sizing: border-box;
}

:root {
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #212529;
    --accent-color: #4a90e2;
    --border-color: #e9ecef;
    --font-ui: 'Outfit', sans-serif;
    --font-music: 'Times New Roman', serif;

    --music-font-size: 1rem;
    /* Base size, effectively scaled by JS on container */
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--card-bg);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--accent-color);
}

.subtitle {
    margin: 0;
    color: #6c757d;
    font-size: 0.9rem;
}

.container {
    display: flex;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
}

.editor-pane,
.preview-pane {
    /* flex: 1; Removed global flex:1 to handle individually */
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow: hidden;
}

.preview-pane {
    height: 60%;
    /* Initial height */
    /* width: 100%; Removed to prevent overflow */
    /* flex: 1; Removed */
    flex: none;
    /* Make it rigid so we can resize height */
}

.editor-pane {
    flex: 1;
    /* Fill remaining space */
    /* width: 100%; */
    display: flex;
    flex-direction: column;
    padding: 1rem;
    overflow: hidden;
    border-right: none;
    /* Border replaced by gutter */
}

/* Draggable Gutter */
.gutter {
    height: 10px;
    width: 100%;
    background: #e9ecef;
    cursor: row-resize;
    /* Vertical resize cursor */
    transition: background 0.2s;
    flex-shrink: 0;
    border-top: 1px solid #dee2e6;
    border-bottom: 1px solid #dee2e6;
}

.gutter:hover,
.gutter:active {
    background: var(--accent-color);
}

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

.controls-row {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.zoom-input {
    width: 60px;
    margin: 0 5px;
    padding: 2px 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

input[type=range] {
    vertical-align: middle;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-right: 15px;
}

.help-tooltip {
    position: relative;
    cursor: pointer;
}

.help-tooltip span {
    background: var(--accent-color);
    color: white;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: bold;
}

.tooltip-content {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: #333;
    color: white;
    padding: 1rem;
    border-radius: 8px;
    width: 200px;
    font-size: 0.85rem;
    z-index: 10;
    line-height: 1.4;
}

.help-tooltip:hover .tooltip-content {
    display: block;
}

textarea {
    flex: 1;
    resize: none;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s;
}

textarea:focus {
    border-color: var(--accent-color);
}

.paper {
    background: white;
    flex: 1;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    justify-content: center;
    /* Center content horizontally */
    align-items: flex-start;
}

.score {
    width: 100%;
    max-width: 900px;
    /* Constrain max width for readability */
    font-family: var(--font-music);
    transition: font-size 0.2s;
    /* Smooth scaling */
    /* font-size set by JS inline style on .score */
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border-color);
    padding: 0.4rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-color);
}

/* --- Jianpu Rendering Styles --- */

/* Slur SVG Layer */
.slur-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    /* Above notes, below tooltips if any */
    overflow: visible;
}

.slur-path {
    fill: #333;
    stroke: none;
}

/* Lyrics Aligned with Notes */
.lyric-container {
    position: absolute;
    top: 100%;
    /* Below the note */
    left: 0;
    /* Align left edge with note group */
    transform: none;
    /* Remove centering */
    padding-top: 2.5em;
    /* Gap = 2.5x lyrics font size */
    font-family: 'Courier New', monospace;
    font-size: 2.4em;
    /* 0.8x of Note Size (3em) = 2.4em */
    white-space: nowrap;
    color: #333;
    font-weight: bold;
    line-height: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Left align rows with each other */
    gap: 1em;
    /* Gap = 1x lyrics font size */
}

/* Spacing Logic Adjustments */
/* If a system row is first, no top margin */
.system-row:first-child {
    margin-top: 0;
}

/* Increase margin to accommodate larger lyrics, gap, and next row */
.system-row {
    margin-top: 20em;
    /* 6em top + ~8em lyrics (2 lines) + 6em bottom = ~20em */
}

/* Score Title */
.score-title {
    width: 100%;
    text-align: center;
    font-size: 4.5em;
    /* 1.5x of Note Font (3em) - Scales with slider */
    font-weight: bold;
    margin-bottom: 0.5em;
    /* Reduced margin since font is huge */
    font-family: var(--font-ui);
}

/* Meta Row (Key Sig + Creators) */
.meta-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    /* Align top */
    width: 100%;
    margin-bottom: 0.5em;
    /* Updated spacing */
    padding: 0 0.5em;
    /* Match measure padding visual */
}

/* Time Signature - Restoring Previous Appearance */
.time-signature {
    font-family: var(--font-music);
    font-weight: bold;
    font-size: 2.4em;
    /* Match previous .time-signature-row size */
    line-height: 1;
}

/* Lyricist/Composer Info */
.creators-info {
    text-align: left;
    /* User requested left alignment relative to each other */
    font-family: var(--font-ui);
    font-size: 2.4em;
    /* User requested same size as Key Sig (2.4em) */
    font-weight: bold;
    /* Match boldness of Key Sig */
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Left align items in this box */
    /* The box itself is right-aligned in .meta-row via justify-content: space-between */
}

.score-subtitle {
    text-align: left;
    margin-bottom: 2.5em;
    /* Space before music */
    padding-left: 0.5em;
    /* Align with Key Sig */
    font-size: 2.4em;
    /* Match Key Sig size */
    font-weight: bold;
    font-family: var(--font-ui);
    width: 100%;
}

/* Hide old class if present */
.time-signature-row {
    display: none;
}

/* System Row (Line of Music) */
.system-row {
    display: flex;
    width: 100%;
    margin-bottom: 0;
    border-right: none;
    /* End bar is handled by measure last-child */
}

/* Measure */
.measure {
    flex: 1;
    display: flex;
    justify-content: center;
    border-left: 2px solid black;
    /* Normal Bar Line */
    border-left-width: 3px;
    /* Thicker request */
    padding: 0;
    position: relative;
    white-space: nowrap;
}

.measure-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.2em 10%;
    box-sizing: border-box;
}

.measure:last-child {
    border-right: 2px solid black;
    border-right-width: 3px;
}

/* Error styling */
.measure-error .note-content,
.measure-error .beam-line,
.measure-error .dash {
    color: red !important;
    background-color: rgba(255, 0, 0, 0.05);
}

.measure-error .beam-line {
    background: red !important;
}

/* Repeat Signs */
.measure.repeat-start {
    border-left: 6px double black;
}

.measure.repeat-start::before {
    content: ":";
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-55%);
    font-size: 2em;
    font-weight: bold;
    line-height: 0;
    color: black;
}

.measure.repeat-end {
    border-right: 6px double black;
}

.measure.repeat-end::after {
    content: ":";
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-55%);
    font-size: 2em;
    font-weight: bold;
    line-height: 0;
    color: black;
}

.measure.repeat-end+.measure {
    border-left: none;
}

/* Notes & Beams */
.note-group {
    display: inline-flex;
    justify-content: center;
    margin: 0;
    position: relative;
    vertical-align: bottom;
    width: 2.2em;
}

.note-content {
    position: relative;
    font-size: 3em;
    font-weight: bold;
    padding-bottom: 0.1em;
    width: 100%;
    text-align: center;
    line-height: 1;
}

.note-content.error-syntax {
    color: red !important;
}

.beam-group {
    display: inline-flex;
    position: relative;
    margin: 0;
}

/* Dots */
.dot-above {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8em;
    line-height: 0.4;
    display: flex;
    flex-direction: column-reverse;
    bottom: 100%;
    margin-bottom: 0.2em;
}

.dot-below {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8em;
    line-height: 0.4;
    display: flex;
    flex-direction: column;
    top: 100%;
    margin-top: 0.2em;
}

/* Beams */
.beam-line {
    background: black;
    height: 0.2em;
    position: absolute;
    bottom: -0.2em;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

.beam-line.level-2 {
    bottom: -0.75em;
}

/* Dashes */
.dash-container {
    display: inline-flex;
    justify-content: center;
    width: 2em;
    font-size: 1.5em;
    align-items: center;
    margin: 0;
}

.dash {
    font-weight: normal;
}

/* Accidental */
.accidental {
    position: absolute;
    font-size: 0.6em;
    top: -0.6em;
    left: 50%;
    margin-left: -1.1em;
    font-weight: normal;
    line-height: 1;
}

.accidental.sharp {
    margin-left: -0.9em;
}

.augmentation-dot {
    position: absolute;
    right: -0.8em;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    line-height: 1;
}

.gutter {
    height: 10px;
    cursor: row-resize;
    background: var(--bg-color);
}

@media print {

    /* Hide everything non-essential */
    header,
    .editor-pane,
    .gutter,
    .controls-row,
    .btn-secondary,
    .help-tooltip,
    .pane-header {
        display: none !important;
    }

    /* Reset container layout for print */
    body,
    .container,
    .preview-pane,
    .paper,
    .score {
        height: auto;
        width: 100%;
        margin: 0;
        padding: 0;
        overflow: visible;
        display: block;
        background: white;
    }

    /* Remove shadows and borders */
    .paper {
        box-shadow: none;
        border: none;
    }

    /* Reset font size scaling for print or ensure it fits?
       Actually user wants "preview result".
       So we should probably keep the generated HTML structure.
       Maybe reset font size to a fixed value or keep what user sees?
       If user zoomed in, they might want that big font.
       Let's keep the font size from the element style, but ensure it wraps.
    */
    .score {
        max-width: 900px;
        /* Enforce same max-width as screen to preserve alignment */
        margin: 0 auto;
        /* Center it */
    }
}