:root {
    --bg: #14110d;
    --surface: #1f1a14;
    --text: #f5ede1;
    --muted: #b3a999;
    --accent: #fb923c;
    --accent-strong: #f97316;
    --on-accent: #1a0d00;
    --border: #2e261c;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}

.container {
    width: min(1100px, 92%);
    margin: 0 auto;
}

.site-header {
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    background: rgba(20, 17, 13, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.site-header nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    min-width: 0;
}

.brand {
    color: var(--text);
    font-weight: 700;
    font-size: 1.15rem;
    text-decoration: none;
    letter-spacing: 0.02em;
}

.nav-back {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    transition: color 0.15s ease, border-color 0.15s ease;
}

.nav-back:hover {
    color: var(--text);
    border-color: var(--accent);
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 1.25rem;
    margin: 0;
    padding: 0;
}

.nav-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-links a:hover {
    color: var(--text);
}

main {
    padding: 3rem 0;
    min-height: calc(100vh - 160px);
}

.hero {
    text-align: center;
    padding: 3rem 0 4rem;
}

.hero h1 {
    font-size: clamp(2rem, 4vw, 3rem);
    margin: 0 0 0.75rem;
    background: linear-gradient(120deg, var(--accent), #fbbf24);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.hero .lead {
    color: var(--muted);
    margin: 0 auto 2rem;
    max-width: 60ch;
}

.actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 0.65rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.95rem;
    transition: transform 0.05s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }

.btn.primary {
    background: var(--accent);
    border-color: var(--accent-strong);
    color: var(--on-accent);
    font-weight: 600;
}

.btn.primary:hover { background: var(--accent-strong); }

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.card h2 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
}

.card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 0;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
}

/* --- Auth / forms --- */

.auth-card {
    max-width: 420px;
    margin: 2rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
}

.auth-card h1 {
    margin: 0 0 1rem;
    font-size: 1.5rem;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.field input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.field input:focus {
    outline: none;
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.25);
}

.btn.block {
    display: block;
    width: 100%;
    text-align: center;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.7rem 1rem;
}

.form-footer {
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.form-footer a {
    color: var(--accent);
}

.alert {
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

/* --- Nav user state --- */

.user-info {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text);
    font-size: 0.9rem;
}

.badge {
    display: inline-block;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
}

.badge.preparing {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    margin-left: 0.4rem;
}

/* --- Admin user list --- */

.user-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.15);
}

.user-row__name {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    overflow-wrap: anywhere;
}

.user-row__date {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.inline-form {
    display: inline;
    margin: 0;
    padding: 0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    padding: 0;
}

.btn-link:hover {
    color: var(--text);
}

/* --- Rooms --- */

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.rooms-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.rooms-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.rooms-header .muted {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
}

.rooms-create {
    margin-bottom: 1.5rem;
}

.rooms-list--other {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.rooms-section-title {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.form-inline {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-inline input {
    flex: 1 1 220px;
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.form-inline input:focus {
    outline: none;
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.25);
}

.form-inline input:disabled,
.form-inline button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.card-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}

.card-grid li { margin: 0; }

.card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease, transform 0.05s ease;
}

.card-link:hover {
    border-color: var(--accent-strong);
}

.card-link:active {
    transform: translateY(1px);
}

.card-link h2 {
    color: var(--text);
}

/* --- Room page --- */
/*
 * The room page is engineered to fit on a typical laptop (e.g. 1366x768)
 * without forcing the user to scroll to reach the player controls. We
 * achieve this by trimming the wrapper padding (`body.room-page main`),
 * collapsing the header to a single compact row, and capping the player
 * shell's max-width so its 16:9 height never grows past the viewport.
 */

body.room-page main {
    padding: 1rem 0 1.25rem;
    min-height: auto;
}

.room-header {
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.room-header__text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.room-header h1 {
    font-size: 1.35rem;
    margin: 0;
    line-height: 1.2;
}

.room-info {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.3;
}

.room-qr {
    flex: 0 0 auto;
    display: inline-block;
    width: 4.5rem;
    height: 4.5rem;
    padding: 0.3rem;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    line-height: 0;
}

.room-qr svg {
    width: 100%;
    height: 100%;
    display: block;
}

@media (max-width: 600px) {
    .room-qr {
        width: 4rem;
        height: 4rem;
    }
}

.breadcrumb {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
}

.breadcrumb a {
    color: var(--muted);
    text-decoration: none;
}

.breadcrumb a:hover {
    color: var(--text);
}

.card-title {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.playlist {
    margin: 0;
    /*
     * The playlist card uses a flex column so the heading stays pinned
     * and only `.playlist-list` actually scrolls when the room has more
     * tracks than fit on screen.
     */
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.playlist h2 {
    font-size: 1rem;
    margin: 0 0 0.5rem;
    flex-shrink: 0;
}

.playlist-item .title {
    overflow-wrap: anywhere;  /* long URLs without titles can't blow out the column */
    color: var(--text);
    flex: 1 1 auto;
    min-width: 0;
}

.playlist-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    /* Cap the visible track-list height so it gets its own scrollbar
     * once it grows past the viewport. The padding-right reserves room
     * for the scrollbar so items don't shift when it appears.
     * Subtraction breakdown (~):
     *   navbar 3.5rem + main padding 2.25rem + room header 4rem
     *   + add-media card 8.5rem + grid gaps & misc 2.25rem ≈ 20.5rem
     */
    max-height: calc(100vh - 20rem);
    overflow-y: auto;
    padding-right: 0.25rem;
    font-size: 0.8rem;
}

/* Custom scrollbar so it matches the orange theme (Webkit + Gecko). */
.playlist-list {
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.playlist-list::-webkit-scrollbar { width: 6px; }
.playlist-list::-webkit-scrollbar-track { background: transparent; }
.playlist-list::-webkit-scrollbar-thumb {
    background: rgba(251, 146, 60, 0.55);
    border-radius: 999px;
}

.playlist-item {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    padding: 0.4rem 0.55rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: background 0.2s ease, border-color 0.2s ease;
    line-height: 1.3;
}

.playlist-item.is-playing {
    background: rgba(251, 146, 60, 0.12);   /* matches --accent at low alpha */
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
}

.playlist-item.is-playing .title {
    color: var(--accent);
    font-weight: 600;
}

/* ---- Room layout (player on the left, playlist column on the right) --- */

.room-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 1.25rem;
    align-items: start;
    margin-bottom: 1rem;
}

.room-layout__main {
    min-width: 0;             /* prevent the video from forcing the grid wider */
    /*
     * Cap the column to whatever 16:9 width fits in the viewport after
     * accounting for the navbar, page padding, header, progress bar, and
     * meta row. With this cap, the video.js `vjs-fluid` element (height
     * = width * 9 / 16) never grows past the viewport, so the controls
     * underneath stay above the fold on common laptop heights.
     */
    max-width: calc((100vh - 13rem) * 16 / 9);
    justify-self: start;
    width: 100%;
}

.room-layout__side {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
    /*
     * The sidebar itself doesn't scroll: the Add-media card stays put,
     * and the playlist's track list (`.playlist-list`) gets its own
     * scrollbar via `max-height` + `overflow-y` rules above.
     */
    min-height: 0;
}

@media (max-width: 900px) {
    .room-layout {
        grid-template-columns: 1fr;
    }
    .room-layout__main {
        max-width: none;
    }
    .playlist-list {
        max-height: none;       /* on phones, let the page scroll */
        overflow-y: visible;
    }
}

/* ---- Synced player ----------------------------------------------------- */

.player-shell {
    margin: 0;
}

.player-frame {
    position: relative;
    width: 100%;
    /*
     * No explicit `aspect-ratio` here -- video.js's fluid wrapper enforces
     * 16:9 via its own `padding-top: 56.25%` and the `aspectRatio: "16:9"`
     * option in room.js. Adding our own aspect-ratio here would fight that
     * (the padding eats into our fixed height under `box-sizing: border-box`).
     */
    background: #000;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.player-frame .video-js {
    width: 100%;
    height: 100%;
    background: #000;
}

/*
 * "Fit" strategy: when a track's natural aspect ratio doesn't match the
 * 16:9 frame (portrait clips, 4:3 archives, ultrawide trailers...) the
 * source is shown in full inside the locked frame with black bars on
 * the unused edges. Crucially, this means the *frame* never resizes to
 * the source -- the player and the page below it stay put on every
 * track change.
 */
.player-frame video {
    object-fit: contain;
    background: #000;
}

/* Block any seek-bar interaction even if a video.js skin sneaks in. */
.video-js.vjs-locked .vjs-control-bar,
.video-js.vjs-locked .vjs-progress-control,
.video-js.vjs-locked .vjs-big-play-button {
    display: none !important;
}

.player-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.9rem;
    background: linear-gradient(180deg, rgba(0,0,0,0.0), rgba(0,0,0,0.0));
}

.player-overlay__msg {
    background: rgba(20, 17, 13, 0.7);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    backdrop-filter: blur(4px);
}

.player-overlay__msg:empty {
    display: none;
}

.player-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.6rem;
    flex-wrap: wrap;
}

.player-now {
    margin: 0;
    color: var(--text);
    font-weight: 500;
    font-size: 0.95rem;
}

.btn.ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.btn.ghost:hover {
    background: rgba(251, 146, 60, 0.1);
}

/* ---- Player meta right-hand controls ---------------------------------- */

.player-meta__controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ---- Skip popup --------------------------------------------------------
 *
 * One-shot floating pill triggered by the server on the first skip vote a
 * user casts per track. CSS transition handles fade in/out; JS just
 * toggles `.visible`. `transform: translate(-50%, -50%)` lets the JS use
 * the popup's *center* as the anchor point, which keeps random placement
 * symmetrical near the edges.
 */

.skip-popup {
    position: fixed;
    z-index: 1000;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--accent);
    color: var(--on-accent);
    padding: 0.6rem 1.1rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.95rem;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.35s cubic-bezier(.2, .9, .3, 1.4);
    white-space: nowrap;
    max-width: 80vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

.skip-popup.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ---- Skip vote button ------------------------------------------------- */

.player-skip-btn {
    min-width: 6rem;
    text-align: center;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.player-skip-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}

.player-skip-btn.has-voted {
    background: rgba(251, 146, 60, 0.18);
    color: var(--text);
}

/* ---- Volume control ---------------------------------------------------- */

.player-volume {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: nowrap;
}

.player-volume__btn {
    min-width: 7.5rem;
    text-align: center;
}

.player-volume__slider {
    accent-color: var(--accent);
    width: 9rem;
    cursor: pointer;
}

.player-volume__value {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
    min-width: 3rem;
    text-align: right;
}

/* ---- Progress indicator ----------------------------------------------- */

.player-progress {
    margin-top: 0.5rem;
}

.player-progress__bar {
    position: relative;
    width: 100%;
    height: 4px;
    background: rgba(251, 146, 60, 0.18);
    border-radius: 999px;
    overflow: hidden;
}

.player-progress__fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.2s linear;
    will-change: width;
}

.player-progress__times {
    display: flex;
    justify-content: space-between;
    margin-top: 0.3rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.8rem;
}
