/* Flat black-and-white look, themable through custom properties. */
:root {
    color-scheme: light;
    --bg: #ffffff;
    --fg: #000000;
    --muted: #6b6b6b;
    --line: #000000;
    --line-soft: #d9d9d9;
    --hover: #f3f3f3;
    --toast-bg: #000000;
    --toast-fg: #ffffff;
    --accent: #1f5fd1;
    --danger: #b3261e;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1013;
    --fg: #f2f4f8;
    --muted: #9aa1ad;
    --line: #f2f4f8;
    --line-soft: #2a2f3a;
    --hover: #171b22;
    --toast-bg: #f2f4f8;
    --toast-fg: #0e1013;
    --accent: #3d7bff;
    --danger: #ff7b72;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "SiteFont", "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    margin: 0;
    padding: 20px;
    transition:
        background-color 0.2s ease,
        color 0.2s ease;
}

a {
    color: inherit;
}

button {
    font: inherit;
    color: inherit;
}

#app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* --- header --- */
#site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 40px;
}

#site-title {
    font-size: 1.3em;
    font-weight: 700;
    text-decoration: none;
}

#site-title:hover {
    text-decoration: underline;
}

#header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.edit-mode #edit-toggle {
    color: var(--accent);
}

/* --- generic controls --- */
.icon-button {
    background: transparent;
    border: none;
    width: 44px;
    height: 44px;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    color: var(--fg);
    transition: opacity 0.2s ease;
}

.icon-button svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.icon-button:hover {
    opacity: 0.6;
}

.icon-button:disabled {
    opacity: 0.25;
    cursor: default;
}

.icon-button.danger {
    color: var(--danger);
}

.text-button {
    background: transparent;
    border: 1px solid var(--line);
    padding: 8px 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.text-button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.text-button:hover {
    background: var(--hover);
}

.notice {
    text-align: center;
    color: var(--muted);
    margin: 40px 0;
}

/* --- view header --- */
.back-link {
    display: inline-block;
    text-decoration: none;
    font-weight: 600;
    margin-bottom: 24px;
}

.back-link:hover {
    text-decoration: underline;
}

.view-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.view-title {
    margin: 0;
    font-size: 2em;
    font-weight: 400;
}

.view-title.editable {
    cursor: text;
    text-decoration: underline dotted var(--muted);
}

.playlist-meta {
    color: var(--muted);
    margin: 6px 0 0;
}


.view-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 24px 0 30px;
}

/* --- playlist overview --- */
.playlist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.playlist-card {
    position: relative;
    border: 1px solid var(--line);
    transition: background-color 0.15s ease;
}

.playlist-card:hover {
    background: var(--hover);
}

.playlist-card-link {
    display: block;
    padding: 22px 22px 20px;
    text-decoration: none;
    min-height: 130px;
}

.playlist-name {
    margin: 0 0 8px;
    font-size: 1.35em;
    font-weight: 400;
}

.playlist-card.smart .playlist-name {
    padding-right: 70px;
}

.playlist-card .playlist-meta {
    margin: 0;
}


.badge {
    position: absolute;
    top: 22px;
    right: 22px;
    font-size: 0.7em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.playlist-card.private {
    border-style: dashed;
}

.card-actions {
    position: absolute;
    right: 8px;
    bottom: 6px;
    display: flex;
    gap: 2px;
}

.card-actions .icon-button {
    width: 36px;
    height: 36px;
}

.card-actions .icon-button svg {
    width: 18px;
    height: 18px;
}

/* --- song list --- */
.song-item {
    padding-bottom: 30px;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--line);
}

.song-item:last-child {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.song-title {
    margin: 0 0 40px 0;
    font-size: 2em;
    font-weight: 400;
    text-align: center;
}

.waveform-and-time-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.waveform-container {
    flex-grow: 1;
    height: 100px;
    cursor: pointer;
    position: relative;
    min-width: 0;
}

.waveform-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.time-display {
    font-size: 1.1em;
    flex-shrink: 0;
    width: 50px;
    font-variant-numeric: tabular-nums;
}

.current-time {
    text-align: right;
}

.total-time {
    text-align: left;
}

.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.edit-controls {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px dashed var(--line-soft);
}

.drag-handle {
    cursor: grab;
    touch-action: none;
}

.song-item.dragging {
    opacity: 0.35;
}

.song-list {
    position: relative;
}

.drop-marker {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 3px;
    background: var(--accent);
    pointer-events: none;
    z-index: 5;
}

.drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    pointer-events: none;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--line);
    padding: 8px 14px;
    font-size: 1.1em;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.is-dragging {
    user-select: none;
    cursor: grabbing;
}

/* --- popover (add to playlist) --- */
.popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg);
    border: 1px solid var(--line);
    padding: 12px 14px;
    min-width: 240px;
    max-width: 90vw;
    z-index: 20;
    text-align: left;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.popover-title {
    margin: 0 0 10px;
    font-size: 0.8em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.popover-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    cursor: pointer;
}

.popover-item input {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    margin: 0;
}

.popover-empty,
.popover-loading {
    margin: 4px 0;
    color: var(--muted);
}

.popover-new {
    margin-top: 10px;
    background: none;
    border: none;
    padding: 6px 0;
    cursor: pointer;
    color: var(--accent);
}

.popover-new:hover {
    text-decoration: underline;
}

/* --- upload --- */
.dropzone {
    border: 2px dashed var(--muted);
    padding: 26px 20px;
    text-align: center;
    margin: 24px 0 32px;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--accent);
    background: var(--hover);
}

.dropzone input {
    display: none;
}

.dropzone-label {
    margin: 0;
}

.dropzone-hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.9em;
}

.upload-progress:not(:empty) {
    margin-top: 16px;
    text-align: left;
}

.upload-row {
    display: grid;
    grid-template-columns: 1fr 160px;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
    font-size: 0.9em;
}

.upload-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-bar {
    height: 6px;
    background: var(--line-soft);
}

.upload-bar-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.1s linear;
}

.upload-row.done .upload-bar-fill {
    width: 100%;
    background: var(--fg);
}

.upload-row.failed {
    color: var(--danger);
}

.upload-row.failed .upload-bar-fill {
    background: var(--danger);
}

/* --- transport bar --- */
#transport {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 12px 20px 6px;
    background: var(--bg);
}

/* The line between the song list and the transport doubles as a seek bar. */
#transport-scrubber {
    position: absolute;
    left: 0;
    right: 0;
    top: -8px;
    height: 16px;
    cursor: pointer;
    touch-action: none;
}

.transport-line {
    position: absolute;
    left: 0;
    right: 0;
    top: 7px;
    height: 1px;
    background: var(--line);
}

#transport-dot {
    position: absolute;
    top: 2px;
    left: 0;
    width: 11px;
    height: 11px;
    margin-left: -5.5px;
    border-radius: 50%;
    background: var(--fg);
    border: 2px solid var(--bg);
    box-shadow: 0 0 0 1px var(--line);
    transition: transform 0.1s ease;
}

#transport-scrubber:hover #transport-dot {
    transform: scale(1.4);
}

#transport[hidden] {
    display: none;
}

body.has-transport {
    padding-bottom: 90px;
}

.transport-title {
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.1em;
    min-width: 0;
}

.transport-title:hover {
    text-decoration: underline;
}

.transport-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.transport-time {
    text-align: right;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.song-item.focused .song-title {
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 3px;
    text-underline-offset: 8px;
}

/* --- toast --- */
#toast-notification {
    visibility: hidden;
    opacity: 0;
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--toast-bg);
    color: var(--toast-fg);
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 1em;
    z-index: 30;
    max-width: 90vw;
    transition:
        opacity 0.5s,
        visibility 0.5s ease;
}

body.has-transport #toast-notification {
    bottom: 100px;
}

#toast-notification.show {
    visibility: visible;
    opacity: 1;
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    #transport {
        grid-template-columns: 1fr auto;
        padding: 4px 12px;
    }

    .transport-time {
        display: none;
    }

    #app-container {
        padding: 10px;
    }

    .song-title {
        font-size: 1.5em;
        margin-bottom: 24px;
    }

    .time-display {
        font-size: 0.9em;
        width: 42px;
    }

    .waveform-and-time-container {
        gap: 8px;
    }
}
