:root {
    --timeline-editor-sidebar-width: 25rem;
    --timeline-preview-width: 900px;
    --timeline-preview-height: 630px;
}

.timeline-wrapper {
    display: flex;
    min-height: 100vh;
    box-sizing: border-box;
    background: var(--color-bg, var(--loading-background));
    transition: padding-right 0.3s ease;
}

.timeline-wrapper.has-editor-sidebar {
    padding-right: var(--timeline-editor-sidebar-width);
}

.timeline-wrapper .timeline-body {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    left: 0%;
    margin-top: var(--header-height, 4.1rem);
    padding: 1rem;
    width: 100%;
    min-height: calc(100vh - var(--header-height, 4.1rem));
    box-sizing: border-box;
    gap: 1rem;
}

.timeline-wrapper .battle-selection-panel {
    --student-track-card-width: 6rem;
    --student-avatar-size: 4.5rem;
    container: battle-selection / inline-size;
    width: min(100%, 72rem);
    box-sizing: border-box;
    border: 1px solid var(--border, var(--loading-border));
    border-radius: 0.85rem;
    background: var(--surface-primary, var(--loading-surface));
    box-shadow: 0 0.65rem 1.6rem var(--shadow);
}

.timeline-wrapper .student-list-panel-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 3.5rem;
    padding: 0.5rem 1rem;
    box-sizing: border-box;
    border-bottom: 1px solid var(--border, var(--loading-border));
    border-radius: 0.85rem 0.85rem 0 0;
    background: var(--surface-secondary, var(--loading-surface));
}

.timeline-wrapper .battle-selection-content,
.timeline-wrapper .track-container {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
    gap: 0.75rem;
}

.timeline-wrapper .battle-controls {
    display: flex;
    flex: 1;
    min-width: 0;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.timeline-wrapper .battle-selection-content {
    padding: 1rem;
}

.timeline-wrapper .student-list-panel {
    display: flex;
    max-width: 100%;
}

.timeline-wrapper .track-container {
    max-width: 100%;
    padding: 0.5rem 0.25rem;
    box-sizing: border-box;
}

.timeline-wrapper .track-container,
.timeline-wrapper .selection-group {
    border: 1px solid var(--border, var(--loading-border));
    border-radius: 0.5rem;
    background: var(--student-list-panel-bg);
    overflow: hidden;
}

.timeline-wrapper .selection-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 0;
}

.timeline-wrapper .student-select-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    gap: 0.25rem;
}

.timeline-wrapper .selection-group-color-line {
    display: block;
    flex-shrink: 0;
    height: 0.25rem;
    margin: 0 0.5rem;
    border-radius: 0.25rem 0.25rem 0 0;
    background: var(--selection-group-color, var(--loading-border));
}

.timeline-wrapper .student-select-track {
    display: grid;
    grid-template-columns: repeat(var(--student-track-columns), var(--student-track-card-width));
    justify-content: center;
}

.timeline-wrapper .timeline-type-raid .student-select-group--stricker {
    --student-track-columns: 4;
}

.timeline-wrapper .timeline-type-raid .student-select-group--special {
    --student-track-columns: 2;
}

.timeline-wrapper .timeline-type-final-restriction-release .student-select-group--stricker {
    --student-track-columns: 6;
}

.timeline-wrapper .timeline-type-final-restriction-release .student-select-group--special {
    --student-track-columns: 4;
}

.timeline-wrapper .timeline-editor-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: var(--header-height, 4.1rem);
    width: var(--timeline-editor-sidebar-width);
    height: calc(100vh - var(--header-height, 4.1rem));
    min-height: 0;
    box-sizing: border-box;
    border-left: 1px solid var(--border, var(--loading-border));
    background: var(--surface-primary, var(--loading-surface));
    box-shadow: -0.65rem 0 1.6rem var(--shadow);
    text-align: center;
    z-index: 1000;
}

.timeline-wrapper .timeline-panel-host {
    container: timeline-panel / inline-size;
    width: min(100%, 88rem);
    min-width: 0;
}

.timeline-panel-host > .timeline-analysis-panel {
    width: 100%;
}

.timeline-wrapper .preview-image-panel {
    position: relative;
    display: grid;
    grid-template-rows: 3.5rem minmax(12rem, auto);
    align-items: center;
    width: min(100%, 72rem);
    margin-inline: auto;
    max-width: 100%;
    min-width: 12rem;
    min-height: 15.5rem;
    border: 1px solid var(--border, var(--loading-border));
    border-radius: 0.85rem;
    box-shadow: 0 0.65rem 1.6rem var(--shadow);
    background: var(--surface-primary, var(--loading-surface));
    overflow: hidden;
}

.timeline-wrapper .preview-image-container {
    display: flex;
    flex-direction: column;
    grid-row: 2;
    width: 100%;
    min-height: 12rem;
    gap: 1rem;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
    overflow: auto;
    scrollbar-width: auto;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-gutter: stable;
}

.timeline-wrapper .content-title-container {
    display: flex;
    position: relative;
    grid-row: 1;
    background: var(--surface-secondary, var(--loading-surface));
    top: 0;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    min-height: 3.5rem;
    padding: 0.25rem 1rem;
    border-bottom: 1px solid var(--border, var(--loading-border));
    box-sizing: border-box;
    z-index: 20;
}

@container battle-selection (min-width: 70rem) {
    .timeline-wrapper .timeline-type-final-restriction-release {
        --student-track-card-width: 5.5rem;
    }
}

@container battle-selection (max-width: 70rem) {
    .timeline-wrapper .timeline-type-final-restriction-release .student-select-group--stricker {
        --student-track-columns: 3;
    }

    .timeline-wrapper .timeline-type-final-restriction-release .student-select-group--special {
        --student-track-columns: 2;
    }
}

@container battle-selection (max-width: 49rem) {
    .timeline-wrapper .timeline-type-raid .student-select-group--stricker {
        --student-track-columns: 2;
    }

    .timeline-wrapper .timeline-type-raid .student-select-group--special {
        --student-track-columns: 1;
    }
}

@container battle-selection (max-width: 30rem) {
    .timeline-wrapper .student-list-panel-top {
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    .timeline-wrapper .battle-duration-field {
        flex-direction: column;
        gap: 0.15rem;
    }

    .timeline-wrapper .battle-selection-content {
        padding: 0.75rem;
    }
}

@container battle-selection (max-width: 24rem) {
    .timeline-wrapper .battle-controls {
        gap: 0.5rem;
    }

    .timeline-wrapper .battle-controls .switch-label {
        display: none;
    }

    /* Each half must hold 制約解除決戰 (six full-width glyphs, 6 x 0.74rem):
       (10.5rem - 6px) / 2 - 2 x 0.2rem leaves about 74px for 71px of text. */
    .timeline-wrapper .battle-controls .timeline-type-switch {
        width: 10.5rem;
    }

    .timeline-wrapper .battle-controls .switch-option {
        padding: 0 0.2rem;
        font-size: 0.74rem;
    }

    .timeline-wrapper .battle-duration-label {
        width: 4.5rem;
        white-space: normal;
        text-align: center;
    }
}

@media (max-width: 1200px) {
    .timeline-wrapper.has-editor-sidebar {
        padding-right: 0;
    }
}

@media (max-width: 700px) {
    .timeline-wrapper .timeline-body {
        padding: 0.75rem;
    }

    .timeline-wrapper .student-select-track {
        --student-track-card-width: clamp(3.25rem, 15vw, 4.25rem);
        --student-avatar-size: min(3.25rem, calc(var(--student-track-card-width) - 0.4rem));
        grid-template-columns: repeat(var(--student-track-columns), var(--student-track-card-width));
    }

    .timeline-wrapper .timeline-type-raid .student-select-group--stricker {
        --student-track-columns: 2;
    }

    .timeline-wrapper .timeline-type-raid .student-select-group--special {
        --student-track-columns: 1;
    }

    .timeline-wrapper .timeline-type-final-restriction-release .student-select-group--stricker {
        --student-track-columns: 3;
    }

    .timeline-wrapper .timeline-type-final-restriction-release .student-select-group--special {
        --student-track-columns: 2;
    }
}

@media (max-width:900px) {
    .timeline-wrapper .timeline-editor-sidebar {
        width: min(var(--timeline-editor-sidebar-width), 92vw);
    }
}
