/* css/stage.css */

/* 1. Full Screen Overlay */
#stage-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: var(--app-vh, 100vh);
    background: rgba(0, 0, 0, 0.95);
    /* Extremely dark, slightly transparent */
    z-index: 9999;
    /* Top level */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#stage-view.visible {
    opacity: 1;
    pointer-events: auto;
}

/* 2. Song Content Pane */
.stage-content {
    width: 95%;
    /* Use almost full width but keep a small safe margin */
    max-width: none;
    /* UNLIMITED WIDTH */
    height: 100%;
    overflow: hidden;
    padding: var(--stage-toolbar-clearance, 70px) 40px 20px;
    /* Slightly reduced padding to maximize space */
    box-sizing: border-box;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    /* Hide scrollbar visually but allow scroll */
    scrollbar-width: none;
    margin: 0 auto;
}

.stage-content::-webkit-scrollbar {
    display: none;
}

/* 3. Typography Overrides for Stage */
.stage-content {
    /* Base scalar for zoom controls */
    --stage-font-scale: 1.0;
    --readable-max-width: 1500px;
    --stage-toolbar-clearance: 64px;
}

.stage-content h1 {
    font-size: 2em;
    color: #fff;
    text-align: center;
    margin-bottom: 4px;
}

.stage-meta {
    text-align: center;
    color: #888;
    margin-bottom: 8px;
    font-size: 0.92em;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
    flex: 0 0 auto;
}

.stage-meta h1 {
    margin: 0 0 4px 0;
    line-height: 1.06;
    font-weight: 700;
    font-size: clamp(1.7rem, 2.6vw, 2.5rem);
}

.stage-meta > div {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    column-gap: 14px;
    row-gap: 4px;
}

.stage-meta strong {
    color: #aaa;
    margin-left: 5px;
}

.stage-meta span {
    margin: 0;
}

/* Reuse existing lyric/chord classes but scale them up if needed */
/* Reuse existing lyric/chord classes but scale them up if needed */
/* USE CHILD COMBINATOR > TO PREVENT RECURSIVE SCALING IN NESTED DATA */
/* ROBUST FIX: Apply scale to container, let children inherit relative size */
/* ROBUST FIX: Apply scale to container, let children inherit relative size */
.stage-body {
    /* Base size 20px * scale */
    font-size: calc(20px * var(--stage-font-scale));

    width: 100%;
    max-width: none;
    margin: 0 auto;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 20px;
    scrollbar-width: none;
}

.stage-body::-webkit-scrollbar {
    display: none;
}

.stage-body .segment-label {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #777;
    border-left: 3px solid #444;
    padding-left: 8px;
    margin: 0 0 6px 0;
    font-family: 'Consolas', 'Courier New', monospace;
}

/* Segmented View Backgrounds (Stage) */
.stage-body.segmented-view .song-part {
    background: var(--seg-bg-verse);
    border: 1px solid var(--seg-border);
    border-radius: 8px;
    padding: 10px 12px;
}

.stage-body.segmented-view .song-part[data-part="header"] {
    background: var(--seg-bg-header);
}
.stage-body.segmented-view .song-part[data-part="intro"] {
    background: var(--seg-bg-intro);
}
.stage-body.segmented-view .song-part[data-part="refrain"] {
    background: var(--seg-bg-refrain);
}
.stage-body.segmented-view .song-part[data-part="bridge"] {
    background: var(--seg-bg-bridge);
}
.stage-body.segmented-view .song-part[data-part="other"] {
    background: var(--seg-bg-other);
}

.stage-body .segment-handle {
    display: none;
}

/* When Two Column is Active: Needs full width */
.stage-body.two-column {
    max-width: none;
    width: 100%;
    overflow: hidden !important;
    overflow-y: hidden;
    overscroll-behavior: contain;
}

.stage-body .song-part>.lyric-line {
    font-size: 1.2em;
    /* Relative to stage-body */
    line-height: 1.6;
    color: var(--text-lyric);
    font-family: 'Consolas', 'Courier New', monospace;
    white-space: pre;
    transition: font-size 0.2s ease;
}

.stage-body .song-part>.chord-line {
    font-size: 1.1em;
    /* Relative to stage-body */
    color: var(--text-chord);
    /* Explicit fallback only, inline style handles specific colors */
    font-weight: bold;
    font-family: 'Consolas', 'Courier New', monospace;
    white-space: pre;
    min-height: 1.2em;
    transition: font-size 0.2s ease;
}

/* Force links in chord lines to inherit color (fixes <a> styling issues) */
.stage-content .chord-line a,
.stage-body .chord-line a {
    color: inherit;
    /* Allow parent or inline style to win */
    text-decoration: none;
    cursor: pointer;
}

/* 4. Controls */
.stage-toolbar {
    position: fixed;
    top: calc(20px + var(--safe-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(12, 12, 12, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 6px 14px;
    z-index: 10001;
    backdrop-filter: blur(8px);
}

.stage-toolbar-sep {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
}

.stage-tool-btn {
    background: transparent;
    border: none;
    color: #d9d9d9;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 8px 12px;
    border-radius: 999px;
    transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
    position: relative;
}

.stage-tool-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
}

.stage-tool-btn.active {
    color: #fff;
    background: rgba(56, 143, 255, 0.32);
}

.stage-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.stage-tool-btn:focus-visible {
    outline: 2px solid rgba(56, 143, 255, 0.75);
    outline-offset: 1px;
}

#btn-stage-auto-slower,
#btn-stage-auto-faster {
    min-width: 30px;
    padding: 8px 10px;
    font-weight: 700;
}

.stage-tool-btn.auto-off {
    color: #d9d9d9;
}

.stage-tool-btn.auto-waiting {
    color: #ffe5a0;
    background: rgba(255, 214, 102, 0.14);
}

.stage-tool-btn.auto-running {
    color: #d9f6ff;
    background: rgba(70, 180, 255, 0.2);
}

.stage-tool-btn.auto-running::after {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #7ed7ff;
    position: absolute;
    right: 6px;
    top: 6px;
    animation: stage-auto-pulse 1.2s ease-in-out infinite;
}

.stage-tool-btn.auto-paused {
    color: #ffd9a8;
    background: rgba(255, 177, 83, 0.18);
}

.stage-tool-btn.auto-idle {
    color: #b8c2d1;
    background: rgba(180, 188, 201, 0.14);
}

@keyframes stage-auto-pulse {
    0% { opacity: 0.4; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1.15); }
    100% { opacity: 0.4; transform: scale(0.85); }
}

.stage-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #555;
    font-size: 4em;
    cursor: pointer;
    padding: 20px;
    transition: color 0.2s;
    user-select: none;
    outline: none;
    z-index: 10002;
    pointer-events: auto;
}

.stage-btn:hover {
    color: #fff;
}

.stage-prev {
    left: 20px;
}

.stage-next {
    right: 20px;
}

.stage-close {
    position: absolute;
    top: calc(20px + var(--safe-top, 0px));
    right: 30px;
    font-size: 3em;
    background: transparent;
    border: none;
    color: #555;
    cursor: pointer;
    line-height: 1;
    transform: none;
    /* Override centering */
    padding: 10px;
    z-index: 10003;
    pointer-events: auto;
}

.stage-close:hover {
    color: #ff4444;
}

/* Two Column support in Stage */
/* Two Column support in Stage */
.stage-content .two-column {
    column-count: 2;
    column-gap: clamp(28px, 3vw, 56px);
    column-fill: balance;
    width: 100%;
}

.stage-content .stage-body.snake-mode.two-column {
    column-count: initial !important;
    column-gap: 0 !important;
    column-fill: auto !important;
    overflow: hidden !important;
    padding-bottom: 0;
}

.stage-body.snake-mode .snake-viewport {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: clamp(28px, 3vw, 56px);
    width: 100%;
    height: 100%;
}

.stage-body.snake-mode .snake-col {
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.stage-body.snake-mode .snake-track {
    will-change: transform;
}

.stage-body.snake-mode .snake-row {
    min-height: 0;
    box-sizing: border-box;
    display: block;
    padding: 0 12px;
    margin: 0;
    text-align: left;
}

.stage-body.snake-mode .snake-row.snake-row-pair {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
}

.stage-body.snake-mode .snake-row > .segment-label,
.stage-body.snake-mode .snake-row > .chord-line,
.stage-body.snake-mode .snake-row > .lyric-line {
    margin: 0;
}

.stage-body.snake-mode.segmented-view .snake-row[data-part="header"] {
    background: var(--seg-bg-header);
}
.stage-body.snake-mode.segmented-view .snake-row[data-part="intro"] {
    background: var(--seg-bg-intro);
}
.stage-body.snake-mode.segmented-view .snake-row[data-part="refrain"] {
    background: var(--seg-bg-refrain);
}
.stage-body.snake-mode.segmented-view .snake-row[data-part="bridge"] {
    background: var(--seg-bg-bridge);
}
.stage-body.snake-mode.segmented-view .snake-row[data-part="other"] {
    background: var(--seg-bg-other);
}

/* Center song parts using GLOBAL width to prevent jagged left alignment */
.stage-body.two-column .song-part {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    break-inside: avoid;
}

/* Also apply to Single Column for consistency */
.stage-body:not(.two-column) {
    display: flex;
    flex-direction: column;
    max-width: min(100%, var(--readable-max-width));
    margin: 0 auto;
    align-items: stretch;
}

.stage-body:not(.two-column) .song-part {
    width: 100%;
    max-width: 100%;
    margin: 0;
    text-align: left;
    align-self: stretch;
}

.stage-body:not(.two-column) .song-part > .lyric-line,
.stage-body:not(.two-column) .song-part > .chord-line,
.stage-body:not(.two-column) .song-part > .segment-label {
    text-align: left;
}

/* Preserve line sizing when long lines are wrapped in outlier containers */
.stage-body .song-part .stage-outlier-scroll > .lyric-line {
    font-size: 1.2em;
    line-height: 1.6;
    color: var(--text-lyric);
    font-family: 'Consolas', 'Courier New', monospace;
    white-space: pre;
}

.stage-body .song-part .stage-outlier-scroll > .chord-line {
    font-size: 1.1em;
    color: var(--text-chord);
    font-weight: bold;
    font-family: 'Consolas', 'Courier New', monospace;
    white-space: pre;
    min-height: 1.2em;
}

.stage-outlier-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.36) transparent;
    padding-bottom: 2px;
}

.stage-outlier-scroll::-webkit-scrollbar {
    height: 6px;
}

.stage-outlier-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.35);
    border-radius: 999px;
}

.stage-outlier-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.stage-outlier-line {
    min-width: max-content;
}

.stage-body.stage-snake-jump {
    box-shadow: inset 0 0 0 1px rgba(100, 190, 255, 0.2);
}

.stage-state {
    margin-top: 20vh;
    text-align: center;
    color: #888;
    font-size: 1.5em;
}

.stage-state.error {
    color: #ff4444;
}

body.light-theme #stage-view {
    background: rgba(244, 248, 255, 0.96);
}

body.light-theme .stage-content {
    color: #1f2b3d;
}

body.light-theme .stage-content h1 {
    color: #1f2b3d;
}

body.light-theme .stage-meta {
    color: #596984;
    border-bottom-color: #cdd7e6;
}

body.light-theme .stage-meta strong {
    color: #2b3951;
}

body.light-theme .stage-body .segment-label {
    color: #5f6f88;
    border-left-color: #9faecc;
}

body.light-theme .stage-toolbar {
    background: rgba(255, 255, 255, 0.86);
    border-color: rgba(35, 52, 79, 0.18);
    box-shadow: 0 8px 20px rgba(25, 40, 65, 0.12);
}

body.light-theme .stage-toolbar-sep {
    background: rgba(35, 52, 79, 0.18);
}

body.light-theme .stage-tool-btn {
    color: #314560;
}

body.light-theme .stage-tool-btn:hover {
    color: #1f2f45;
    background: rgba(25, 57, 102, 0.1);
}

body.light-theme .stage-tool-btn.active {
    color: #0d3f74;
    background: rgba(0, 120, 212, 0.2);
}

body.light-theme .stage-tool-btn.auto-off {
    color: #324760;
}

body.light-theme .stage-tool-btn.auto-waiting {
    color: #7a5600;
    background: rgba(255, 214, 102, 0.22);
}

body.light-theme .stage-tool-btn.auto-running {
    color: #0f5f9d;
    background: rgba(70, 180, 255, 0.2);
}

body.light-theme .stage-tool-btn.auto-paused {
    color: #8a4c00;
    background: rgba(255, 177, 83, 0.2);
}

body.light-theme .stage-tool-btn.auto-idle {
    color: #4b5c77;
    background: rgba(180, 188, 201, 0.18);
}

body.light-theme .stage-btn {
    color: #91a0b5;
}

body.light-theme .stage-btn:hover {
    color: #20314b;
}

body.light-theme .stage-close {
    color: #8e9caf;
}

body.light-theme .stage-close:hover {
    color: #c02e2e;
}

body.light-theme .stage-outlier-scroll {
    scrollbar-color: rgba(35, 52, 79, 0.3) transparent;
}

body.light-theme .stage-outlier-scroll::-webkit-scrollbar-thumb {
    background: rgba(35, 52, 79, 0.3);
}

body.light-theme .stage-state {
    color: #607089;
}

body.light-theme .stage-state.error {
    color: #c53131;
}

@media (max-width: 900px) {
    .stage-content {
        width: 100vw;
        margin: 0;
        padding: calc(52px + var(--safe-top, 0px)) 0 calc(8px + var(--safe-bottom, 0px));
    }

    .stage-meta {
        margin-bottom: 6px;
        padding-bottom: 6px;
    }

    .stage-meta h1 {
        font-size: clamp(1.45rem, 6.1vw, 2.05rem);
    }

    .stage-meta > div {
        column-gap: 10px;
        row-gap: 3px;
        font-size: 0.95em;
    }

    .stage-toolbar {
        top: calc(4px + var(--safe-top, 0px));
        left: 6px;
        right: 74px;
        transform: none;
        border-radius: 12px;
        padding: 4px 6px;
        overflow-x: auto;
        overflow-y: hidden;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
        z-index: 10020;
    }

    .stage-toolbar::-webkit-scrollbar {
        height: 4px;
    }

    .stage-toolbar::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.25);
        border-radius: 999px;
    }

    body.light-theme .stage-toolbar::-webkit-scrollbar-thumb {
        background: rgba(35, 52, 79, 0.28);
    }

    .stage-toolbar-sep {
        height: 16px;
    }

    .stage-tool-btn {
        padding: 7px 9px;
        font-size: 12px;
        white-space: nowrap;
    }

    #btn-stage-auto-slower,
    #btn-stage-auto-faster {
        min-width: 26px;
        padding: 7px 8px;
    }

    .stage-body {
        font-size: calc(17px * var(--stage-font-scale));
        padding-left: 6px;
        padding-right: 6px;
        padding-bottom: calc(10px + var(--safe-bottom, 0px));
    }

    .stage-body:not(.two-column) {
        max-width: 100%;
        margin: 0;
        padding-left: 6px;
        padding-right: 6px;
    }

    .stage-body.segmented-view .song-part {
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        padding-left: 8px;
        padding-right: 8px;
        margin-left: 0;
        margin-right: 0;
    }

    .stage-body .song-part > .lyric-line {
        font-size: 1.08em;
        line-height: 1.5;
    }

    .stage-body .song-part > .chord-line {
        font-size: 1em;
        line-height: 1.28;
    }

    .stage-content .two-column,
    .stage-body.two-column {
        column-count: 1 !important;
        column-gap: 0 !important;
        column-fill: auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    .stage-body.snake-mode .snake-viewport {
        grid-template-columns: 1fr;
        column-gap: 0;
    }

    .stage-btn {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: 38px;
        height: 70px;
        font-size: 1.35rem;
        line-height: 1;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        background: rgba(0, 0, 0, 0.42);
        border: 1px solid rgba(255, 255, 255, 0.2);
        color: #d7dce6;
        z-index: 10030;
        touch-action: manipulation;
    }

    body.light-theme .stage-btn {
        background: rgba(21, 39, 66, 0.08);
    }

    .stage-prev {
        left: 2px;
    }

    .stage-next {
        right: 2px;
    }

    .stage-close {
        position: fixed;
        top: calc(4px + var(--safe-top, 0px));
        right: 8px;
        width: 34px;
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.35rem;
        padding: 0;
        border-radius: 9px;
        background: rgba(0, 0, 0, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.28);
        color: #f2f4f8;
        z-index: 10040;
        touch-action: manipulation;
    }
}
