:root {
    color-scheme: light dark;
    --bg: light-dark(#ffffff, #14161c);
    --text: light-dark(#222733, #e8eaf0);
    --muted: light-dark(#6b7280, #9aa1b1);
    --card: light-dark(#f3f4f7, #222631);
    --border: light-dark(#d9dce3, #373d4b);
    --accent: #48c78e;
    --accent-text: #0a2b1c;
    --correct: light-dark(#e3f7ec, #1d4433);
    --correct-border: #48c78e;
    /* Darker than the accent so it stays readable on light backgrounds */
    --correct-text: light-dark(#1b6b43, #6fdcaa);
    --wrong: light-dark(#fde3e6, #4a252b);
    --wrong-border: #d9546a;

    /* Every song card is the same height, which the drag logic relies on */
    --card-height: 4.25rem;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

.wrap {
    max-width: 34rem;
    margin: 0 auto;
    padding: 0 0.75rem;
}

/* Header and tabs */
.site-header {
    background: var(--accent);
    color: var(--accent-text);
    margin-bottom: 1rem;
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
}

.title-row h1 {
    margin: 0;
    font-size: 1.75rem;
}

.subtitle {
    margin: 0;
}

.title-row .button {
    flex-shrink: 0;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.tabs {
    display: flex;
    gap: 0.25rem;
}

.tab {
    background: none;
    border: 0;
    border-radius: 6px 6px 0 0;
    color: var(--accent-text);
    cursor: pointer;
    font: inherit;
    padding: 0.5rem 0.75rem;
}

.tab.is-active {
    background: var(--bg);
    color: var(--text);
}

/* Buttons and notices */
.button {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    padding: 0.5rem 1rem;
}

.button-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

.button:disabled {
    cursor: default;
    opacity: 0.45;
}

.close {
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
}

.notice {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.75rem;
}

.notice-error {
    background: var(--wrong);
    border-color: var(--wrong-border);
}

.puzzle-meta {
    color: var(--muted);
    margin: 0 0 0.25rem;
}

.end-label {
    margin: 0.5rem 0 0.35rem;
    font-weight: 700;
}

/* Song list: the slots stay put, the cards move between them */
#song-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.slot {
    display: flex;
    align-items: center;
    height: var(--card-height);
    margin-bottom: 0.4rem;
}

.card {
    /* Space inside both ends of a card */
    --card-pad: 0.8rem;
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    height: 100%;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: grab;
    padding-right: var(--card-pad);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.card.is-correct {
    background: var(--correct);
    border-color: var(--correct-border);
}

.card.is-correct .song-name,
.card.is-correct .song-artist {
    color: var(--correct-text);
}

.card.is-wrong {
    border-color: var(--wrong-border);
}

.card.is-fixed {
    cursor: default;
}

.grip {
    display: flex;
    flex: 0 0 calc(var(--card-pad) + 1.5rem);
    align-items: center;
    padding-left: var(--card-pad);
    /* Icons only as wide as their shape, so they start right at the padding */
    --fa-width: auto;
    align-self: stretch;
    color: var(--muted);
    font-size: 1.1rem;
    /* Stops a touch on the handle from scrolling the page */
    touch-action: none;
}

.card.is-fixed .grip {
    touch-action: auto;
}

.card.is-fixed.is-correct .grip {
    color: var(--correct-text);
    font-size: 1.5rem;
}

.song {
    flex: 1;
    min-width: 0;
}

.song div {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.song-name {
    font-weight: 600;
}

.song-artist,
.song-hint {
    color: var(--muted);
    font-size: 0.8rem;
}

.song-year {
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.song-year.is-unknown {
    color: var(--muted);
}

/* Dragging */
.is-dragging-list .card {
    cursor: grabbing;
    transition: transform 150ms ease;
}

.is-dragging-list .card.is-dragging {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    transition: none;
    z-index: 2;
}

.card.is-settling {
    transition: transform 180ms ease;
}

@media (prefers-reduced-motion: reduce) {
    .card {
        transition: none !important;
    }
}

/* Narrow phones: give the song titles more room */
@media (max-width: 400px) {
    .card {
        gap: 0.35rem;
        --card-pad: 0.65rem;
    }
}

/* Counter and actions */
#guess-counter {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    color: var(--muted);
}

#message {
    min-height: 1.4rem;
    margin: 0.4rem 0;
    text-align: center;
}

.actions .button {
    width: 100%;
    font-size: 1.25rem;
    padding: 0.75rem 1rem;
}

/* Previous puzzles */
#previous-puzzles {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

#previous-puzzles .is-win {
    background: var(--correct);
    border-color: var(--correct-border);
}

#previous-puzzles .is-lose {
    background: var(--wrong);
    border-color: var(--wrong-border);
}

/* Results dialog */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.75rem;
    z-index: 10;
}

.modal-card {
    width: 100%;
    max-width: 26rem;
    max-height: 100%;
    overflow-y: auto;
    background: var(--bg);
    border-radius: 10px;
    padding: 1rem;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-head h2 {
    margin: 0;
    font-size: 1.25rem;
}

.chart-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 3px;
}

.chart-label {
    flex: 0 0 2.5rem;
    text-align: right;
}

.chart-track {
    flex: 1;
}

.chart-bar {
    min-width: 1.5rem;
    background: var(--accent);
    border-radius: 3px;
    color: var(--accent-text);
    font-size: 0.8rem;
    padding: 0 0.4rem;
    text-align: right;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
}

.modal-actions .button {
    flex: 1;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
