:root {
    --bg-color: #ffffff;
    --surface: #fffaf0;
    --surface-strong: #fbeec5;
    --text-main: #1b1d34;
    --text-secondary: #526070;
    --brand-blue: #1d3e66;
    --accent: #e4963c;
    --accent-hover: #c8731f;
    --danger: #b3261e;
    --danger-hover: #89271d;
    --border-color: #d9e1df;
    --soft-blue: #e7f4f6;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    /* Maintain fallback for initial load */
    --real-vh: 1vh;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background:
        linear-gradient(180deg, #ffffff 0%, #f7fbfc 45%, #fff7e8 100%);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    /* Fallback */
    min-height: max(620px, calc(var(--real-vh, 1vh) * 100));
    /* For modern mobile browsers */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.player-container {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 30px;
    width: 100%;
    width: 500px;
    box-shadow: 0 18px 45px rgba(29, 62, 102, 0.14);
    /* Flex layout for scrolling */
    display: flex;
    flex-direction: column;
    max-height: 95vh;
    /* Leave some breathing room on desktop */
}

header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0;
    margin-bottom: 4px;
    color: var(--brand-blue);
    line-height: 1.12;
}

.title-icon {
    display: block;
    height: 96px;
    width: auto;
    border-radius: 12%;
    margin: 0 auto 8px;
}

header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

@media (max-width: 500px) {
    header h1 {
        font-size: 1.85rem;
    }

    .title-icon {
        height: 88px;
        margin-bottom: 6px;
    }
}

/* Track List */
.track-list-section {
    margin-bottom: 30px;
    flex: 1;
    /* Take available space */
    min-height: 0;
    /* Allow shrinking below content size to trigger scroll */
    overflow-y: auto;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid var(--border-color);
}

.track-list {
    list-style: none;
}

.track-list li {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    position: relative;
    /* For absolute markers */
}

.track-list li:last-child {
    border-bottom: none;
}

.track-list li:hover {
    background: var(--soft-blue);
    color: var(--brand-blue);
}

.track-list li.active {
    background: #fff2d4;
    color: var(--brand-blue);
    border-left: 4px solid var(--accent);
    font-weight: 600;
}

.track-list li .icon {
    margin-right: 10px;
    font-size: 1.2rem;
}

/* Controls Section */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex-shrink: 0;
    /* Never shrink controls */
}

/* Transport Buttons */
.transport-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 0.85rem;
}

button:hover {
    background: var(--soft-blue);
    border-color: #b8d3d9;
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
}

button.play-btn {
    background: var(--accent);
    color: #1b1d34;
    font-weight: bold;
    min-width: 80px;
}

button.play-btn:hover {
    background: var(--accent-hover);
    color: #ffffff;
    box-shadow: 0 10px 20px rgba(228, 150, 60, 0.25);
}

/* Sliders */
.sliders-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 10px;
}

/* Marker Button UI (Updated) */
.slider-row {
    display: flex;
    align-items: stretch;
    /* Make button full height */
    gap: 10px;
}

.slider-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    /* Take remaining width */
}

.slider-row label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slider-row label span {
    color: var(--accent);
    font-family: monospace;
}

.marker-btn {
    padding: 0 0 10px 0;
    /* Add bottom padding to visually center considering the tail */
    font-size: 2rem;
    /* Larger plus */
    line-height: 1;
    background: var(--soft-blue);
    color: var(--text-main);

    /* Shape */
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 50% 85%, 0% 100%);
    border-radius: 4px;
    /* Slight rounding on top */

    /* Sizing */
    height: auto;
    width: 40px;
    /* Wider */
    min-height: 50px;
    /* Taller */

    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.marker-btn:hover {
    background: var(--accent);
    color: #1b1d34;
    transform: translateY(-2px);
}

.ticks {
    position: relative;
    height: 1.2em;
    font-size: 0.7rem;
    color: #7d8894;
    margin-top: 5px;
    width: 100%;
    /* Ensure full width */
}

.ticks span {
    position: absolute;
    transform: translateX(-50%);
    cursor: pointer;
    padding: 10px;
    /* Large click area */
    margin-top: -5px;
    /* Re-center */
    transition: color 0.2s, text-shadow 0.2s;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.ticks span.active {
    color: var(--brand-blue);
    font-weight: bold;
    text-shadow: none;
    opacity: 1;
}

@media (hover: hover) {
    .ticks span:hover {
        color: var(--brand-blue);
    }
}

/* 50% */
.ticks span:nth-child(1) {
    left: 2.3%;
}

/* 80% */
.ticks span:nth-child(2) {
    left: 43.5%;
}

/* 90% */
.ticks span:nth-child(3) {
    left: 57.5%;
}

/* 100% */
.ticks span:nth-child(4) {
    left: 71.4%;
}

/* 120% */
.ticks span:nth-child(5) {
    right: -10%;
}

/* Custom Range Input */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]:focus {
    outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: #dfe8ea;
    border-radius: 3px;
}

input[type=range]::-webkit-slider-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -5px;
    box-shadow: 0 2px 8px rgba(29, 62, 102, 0.28);
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Mozilla Firefox */
input[type=range]::-moz-range-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: #dfe8ea;
    border-radius: 3px;
}

input[type=range]::-moz-range-thumb {
    height: 16px;
    width: 16px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(29, 62, 102, 0.28);
}

/* Marker Strip */
.marker-strip {
    position: relative;
    width: calc(100% - 16px);
    height: 12px;
    margin-top: 1px;
    margin-left: 8px;
}

.marker-indicator {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--accent);
    font-family: var(--font-family);
    line-height: 1;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 5;
    padding: 10px;
    /* Double the hit area */
    margin-top: -5px;
    /* Re-center vertically after padding increase */
    opacity: 0.5;
    /* Dimmed by default */
    transition: all 0.2s;
}

.marker-indicator.active {
    color: var(--accent);
    opacity: 1;
    font-weight: bold;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

@media (max-width: 500px),
(max-height: 640px) {
    body {
        padding: 0;
        align-items: flex-start;
    }

    .player-container {
        max-width: 100%;
        min-height: 100vh;
        /* Fallback */
        min-height: max(620px, calc(var(--real-vh, 1vh) * 100));
        border-radius: 0;
        border: none;
        border-top: none;
        border-bottom: none;
        margin: 0;
        backdrop-filter: none;
        background: var(--surface);
        display: flex;
        flex-direction: column;
        justify-content: center;
        /* Center if content is small */
        max-height: 100vh;
        /* Fallback */
        max-height: calc(var(--real-vh, 1vh) * 100);
        /* Full viewport height */
    }
}

/* Markers in List */
.track-markers {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 5px;
}

.marker-tag {
    background: var(--soft-blue);
    border: none;
    /* remove border for clean shape */
    color: var(--text-main);
    font-size: 0.85rem;
    /* Larger font */
    font-weight: bold;
    padding: 4px 10px 12px 8px;
    /* Extra padding bottom for the tail */
    cursor: pointer;
    transition: all 0.2s;
    z-index: 2;

    /* Bookmark Shape */
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 50% 80%, 0% 100%);
    border-radius: 2px;
    /* Slight rounding on top corners if supported or ignored by clip-path */

    /* Ensure sizing */
    min-width: 25px;
    text-align: center;

    /* Visual distinction */
    background: #ffe7ad;

    /* Above title */
}


.marker-tag:hover,
.marker-tag.active {
    background: var(--accent);
    color: #1b1d34;
    border-color: var(--accent);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(27, 29, 52, 0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #ffffff;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 18px 45px rgba(29, 62, 102, 0.24);
    text-align: center;
    max-width: 90%;
    width: 300px;
}

.modal h3 {
    margin-bottom: 15px;
    color: var(--brand-blue);
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button.danger {
    background: var(--danger);
    color: white;
    border: none;
}

.modal-actions button.danger:hover {
    background: var(--danger-hover);
}

@media (max-height: 640px) and (min-width: 640px) {

    html,
    body {
        overflow: hidden;
        /* No global scrollbar ever */
        padding: 0;
        margin: 0;
        height: 100%;
        /* Force full height */
        align-items: flex-start;
        justify-content: flex-start;
    }

    .player-container {
        /* Full viewport, strict 0,0 positioning context */
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 0;
        border: none;

        /* Grid Layout 50/50 */
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr;
        /* Header natural height, rest for controls */
        grid-template-areas:
            "list header"
            "list controls";
        gap: 20px;
        padding: 0;
        /* No padding on container edges */

        box-shadow: none;
        background: var(--surface);
    }

    /* Reset min-height fallback from previous rules if necessary */
    .player-container {
        min-height: 0;
    }

    /* Left Column: Track List */
    .track-list-section {
        grid-area: list;
        grid-row: 1 / -1;
        /* Full height of grid */
        height: 100%;
        overflow-y: auto;
        margin-bottom: 0;
        background: #ffffff;
        border-radius: 0;
        /* Flush to edge if desired, or keep rounded */
        padding: 15px;
        /* Add internal padding back here */
    }

    /* Right Column Top: Header */
    header {
        grid-area: header;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding-top: 15px;
        /* Visual breathing room from top edge */
    }

    header h1 {
        margin: 0;
        font-size: 1.35rem;
    }

    .title-icon {
        height: 2.15em;
    }

    header p {
        text-align: left;
    }

    /* Right Column Bottom: Controls */
    .controls-section {
        grid-area: controls;
        overflow-y: auto;
        justify-content: flex-start;
        gap: 10px;
        padding-right: 15px;
        /* internal padding */
        padding-bottom: 15px;
        /* internal padding */
    }

    .transport-controls {
        justify-content: flex-start;
    }
}
