:root {
    color-scheme: light;
    --bg: #f3f5f2;
    --panel: #ffffff;
    --panel-strong: #f9faf7;
    --ink: #18211f;
    --muted: #65716c;
    --line: #d9dfd8;
    --accent: #d6533f;
    --accent-ink: #ffffff;
    --teal: #28727a;
    --gold: #b77d19;
    --shadow: 0 16px 40px rgba(21, 29, 27, 0.08);
    --active-bg: #dcece7;
    --active-ink: #123f43;
    --soft-bg: #e7eee8;
    --hover-bg: #eaf2ed;
    --filter-bg: #f8faf7;
    --chip-ink: #26302c;
    --chip-bg: #edf0eb;
    --mood-ink: #183f42;
    --mood-bg: #dfeeed;
    --genre-ink: #5b3415;
    --genre-bg: #f2e8d7;
    --era-ink: #3e3a15;
    --era-bg: #eee9c8;
    --flag-ink: #653024;
    --flag-bg: #f5dfd9;
    --focus-ring: rgba(40, 114, 122, 0.28);
    --drawer-shadow: 0 18px 52px rgba(15, 23, 20, 0.28);
    --mobile-button-shadow: 0 10px 24px rgba(92, 36, 27, 0.28);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #151a17;
    --panel: #202721;
    --panel-strong: #273027;
    --ink: #eef5ef;
    --muted: #a8b6ad;
    --line: #3d493f;
    --accent: #e0644f;
    --accent-ink: #171311;
    --teal: #75c9c3;
    --gold: #d5a642;
    --shadow: 0 16px 42px rgba(0, 0, 0, 0.34);
    --active-bg: #21413d;
    --active-ink: #d9fbf5;
    --soft-bg: #2b352d;
    --hover-bg: #303b32;
    --filter-bg: #1b221d;
    --chip-ink: #e4ece6;
    --chip-bg: #303a32;
    --mood-ink: #d9fbf5;
    --mood-bg: #244945;
    --genre-ink: #f5dfba;
    --genre-bg: #4a3723;
    --era-ink: #f3ecb7;
    --era-bg: #454021;
    --flag-ink: #ffd7cd;
    --flag-bg: #55322c;
    --focus-ring: rgba(117, 201, 195, 0.36);
    --drawer-shadow: 0 18px 52px rgba(0, 0, 0, 0.52);
    --mobile-button-shadow: 0 10px 24px rgba(0, 0, 0, 0.38);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow-x: hidden;
}

html,
body,
.topbar,
.shell {
    max-width: 100vw;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    padding: 28px 32px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--teal);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 34px;
    line-height: 1.1;
    letter-spacing: 0;
}

h2 {
    font-size: 18px;
    line-height: 1.2;
}

.status {
    max-width: 360px;
    color: var(--muted);
    font-size: 14px;
    text-align: right;
}

.shell {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 20px 32px 32px;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto 44px 44px;
    gap: 10px;
    align-items: center;
}

.search-box {
    display: flex;
    align-items: center;
    min-height: 46px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.search-box svg {
    flex: 0 0 auto;
    width: 19px;
    height: 19px;
    color: var(--teal);
}

.search-box input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    padding: 0 0 0 10px;
    color: var(--ink);
    background: transparent;
}

.search-box input::placeholder {
    color: var(--muted);
}

select,
.command,
.icon-button {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
}

select {
    width: 100%;
    padding: 0 12px;
}

select option {
    color: var(--ink);
    background: var(--panel);
}

.command {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
    font-weight: 700;
}

.command svg,
.icon-button svg {
    width: 18px;
    height: 18px;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    padding: 0;
}

.command:hover,
.icon-button:hover,
select:hover {
    border-color: var(--teal);
}

.mode-tabs {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(112px, 1fr));
    gap: 4px;
    max-width: 100%;
    margin-top: 14px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.mode-tab,
.choice-button,
.letter-button {
    border: 0;
    border-radius: 6px;
    color: var(--ink);
    background: transparent;
    font-weight: 800;
}

.mode-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    min-height: 36px;
    padding: 0 12px;
}

.mode-tab svg {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
}

.mode-tab span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mode-tab.is-active,
.choice-button.is-active,
.letter-button.is-active {
    background: var(--active-bg);
    color: var(--active-ink);
}

.search-scope {
    display: flex;
    gap: 8px;
    margin: 14px 0 16px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.search-scope[hidden] {
    display: none;
}

.search-scope label {
    flex: 0 0 auto;
}

.search-scope input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.search-scope span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0 13px;
    background: var(--soft-bg);
    color: var(--chip-ink);
    font-weight: 700;
    white-space: nowrap;
}

.search-scope label:hover span,
.search-scope input:checked + span {
    border-color: var(--teal);
    background: var(--active-bg);
}

.search-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    min-width: 0;
    margin: -2px 0 16px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--filter-bg);
}

.search-filters[hidden] {
    display: none;
}

.select-filter,
.filter-checks,
.search-order {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.filter-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.filter-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.select-filter {
    flex: 0 0 auto;
}

.select-filter select {
    width: 156px;
    min-height: 36px;
    box-shadow: none;
}

.filter-checks label {
    flex: 0 0 auto;
}

.filter-checks input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.filter-checks label span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 12px;
    background: var(--panel);
    color: var(--chip-ink);
    font-weight: 700;
    white-space: nowrap;
}

.filter-checks label:hover span,
.filter-checks input:checked + span {
    border-color: var(--teal);
    background: var(--active-bg);
    color: var(--active-ink);
}

.search-order {
    gap: 4px;
    min-height: 42px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.search-order .filter-label {
    margin: 0 4px 0 6px;
}

.search-order .choice-button {
    min-height: 34px;
    padding: 0 11px;
}

.filter-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 11px;
    background: var(--panel);
    color: var(--ink);
    font-weight: 800;
}

.filter-clear[hidden] {
    display: none;
}

.filter-clear svg {
    width: 15px;
    height: 15px;
}

.browse-tools {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    min-width: 0;
    max-width: 100%;
    margin: 0 0 16px;
}

.browse-tools[hidden] {
    display: none;
}

.browse-choice {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(98px, 1fr));
    gap: 4px;
    max-width: 100%;
    min-height: 42px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.choice-button {
    min-width: 0;
    padding: 0 12px;
}

.letter-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
}

.letter-button {
    min-width: 38px;
    min-height: 38px;
    padding: 0 8px;
    border: 1px solid var(--line);
    background: var(--panel);
}

.letter-button:hover,
.choice-button:hover,
.mode-tab:hover,
.filter-clear:hover {
    background: var(--hover-bg);
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: start;
}

.results-panel,
.setlist-panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.setlist-panel {
    position: sticky;
    top: 16px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 72px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-strong);
    border-radius: 8px 8px 0 0;
}

.panel-heading p {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.group-actions {
    display: inline-flex;
    gap: 6px;
}

.group-actions[hidden],
.close-setlist,
.mobile-setlist-button {
    display: none;
}

.group-actions .icon-button:disabled {
    opacity: 0.45;
    cursor: default;
}

.results-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 14px;
}

.results-list.is-grouped {
    grid-template-columns: 1fr;
}

.results-list[hidden],
.browse-list[hidden] {
    display: none;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 0 14px 16px;
}

.result-actions[hidden] {
    display: none;
}

.subtle-command {
    min-height: 38px;
    box-shadow: none;
}

.browse-list {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.browse-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    overflow: visible;
}

.browse-section summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 52px;
    padding: 0 14px;
    background: var(--panel-strong);
    cursor: pointer;
    font-weight: 900;
    list-style: none;
}

.browse-section summary > span {
    min-width: 0;
}

.browse-section summary::-webkit-details-marker {
    display: none;
}

.browse-count {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.browse-items {
    display: grid;
}

.browse-row,
.artist-song-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(160px, 260px) auto;
    gap: 12px;
    align-items: center;
    min-height: 46px;
    padding: 9px 14px;
    border-top: 1px solid var(--line);
}

.artist-song-row {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-left: 28px;
}

.browse-title {
    min-width: 0;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.browse-artist {
    min-width: 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.mini-add {
    width: 34px;
    min-width: 34px;
    min-height: 32px;
    border: 0;
    border-radius: 8px;
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 900;
}

.song-card {
    display: grid;
    gap: 12px;
    min-width: 0;
    min-height: 176px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    overflow: visible;
}

.song-title {
    overflow-wrap: anywhere;
    font-size: 17px;
    font-weight: 800;
    line-height: 1.25;
}

.song-artist {
    margin-top: 4px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: start;
}

.pill {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    min-height: 24px;
    border: 0;
    border-radius: 999px;
    appearance: none;
    padding: 4px 8px;
    color: var(--chip-ink);
    background: var(--chip-bg);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    text-align: left;
    overflow-wrap: anywhere;
}

.pill.is-clickable:hover,
.pill.is-clickable:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 1px;
}

.pill.mood {
    color: var(--mood-ink);
    background: var(--mood-bg);
}

.pill.genre {
    color: var(--genre-ink);
    background: var(--genre-bg);
}

.pill.era {
    color: var(--era-ink);
    background: var(--era-bg);
}

.pill.flag {
    color: var(--flag-ink);
    background: var(--flag-bg);
}

.card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
}

.row-tools {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.song-popout {
    position: relative;
    display: inline-flex;
    justify-content: flex-end;
    min-width: 0;
}

.link-popout-button {
    width: 36px;
    min-height: 34px;
    background: var(--panel-strong);
}

.link-popout-button:disabled {
    cursor: default;
    opacity: 0.44;
}

.song-popout.is-open .link-popout-button {
    border-color: var(--teal);
    color: var(--active-ink);
    background: var(--active-bg);
}

.song-links-popout,
.song-tags-popout {
    position: absolute;
    right: 0;
    bottom: calc(100% + 7px);
    z-index: 30;
    display: grid;
    gap: 4px;
    min-width: 172px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.song-tags-popout {
    gap: 9px;
    min-width: 230px;
    max-width: min(320px, calc(100vw - 36px));
    max-height: 360px;
    overflow: auto;
}

.card-actions .song-links-popout,
.card-actions .song-tags-popout {
    right: auto;
    left: 0;
}

.song-links-popout[hidden],
.song-tags-popout[hidden] {
    display: none;
}

.song-links-popout a {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    border-radius: 6px;
    padding: 0 9px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.song-links-popout a:hover,
.song-links-popout a:focus-visible {
    outline: 0;
    color: var(--active-ink);
    background: var(--active-bg);
}

.song-links-popout svg {
    width: 16px;
    height: 16px;
    color: var(--teal);
}

.tag-popout-group {
    display: grid;
    gap: 5px;
}

.tag-popout-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.tag-popout-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.add-button {
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    padding: 0 12px;
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 800;
}

.setlist {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 14px 14px 16px 34px;
}

.setlist li {
    padding: 9px 8px;
    border-bottom: 1px solid var(--line);
}

.setlist-title {
    display: block;
    font-weight: 800;
    line-height: 1.25;
}

.setlist-artist {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.remove-button {
    margin-top: 8px;
    border: 0;
    padding: 0;
    color: var(--accent);
    background: transparent;
    font-weight: 800;
}

.empty-state {
    padding: 28px 16px;
    color: var(--muted);
    text-align: center;
}

.setlist > .empty-state {
    list-style: none;
    margin-left: -20px;
}

dialog {
    width: min(420px, calc(100% - 32px));
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--panel);
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgb(0 0 0 / 0.45);
}

.dialog-body {
    display: grid;
    gap: 14px;
}

.dialog-body p {
    color: var(--muted);
    line-height: 1.45;
}

@media (max-width: 980px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .setlist-panel {
        position: static;
    }
}

@media (max-width: 720px) {
    .topbar {
        align-items: start;
        flex-direction: column;
        padding: 22px 18px 16px;
    }

    .status {
        text-align: left;
    }

    .shell {
        padding: 16px 14px 92px;
    }

    .toolbar {
        grid-template-columns: 1fr 44px;
    }

    .search-box,
    select,
    .command {
        grid-column: 1 / -1;
    }

    #randomButton {
        grid-column: 1;
    }

    .icon-button {
        grid-column: 2;
    }

    #clearButton {
        display: none;
    }

    h1 {
        font-size: 28px;
    }

    .results-list {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .mode-tabs,
    .search-scope,
    .search-filters,
    .browse-tools {
        width: calc(100vw - 28px);
        max-width: calc(100vw - 28px);
    }

    .mode-tabs,
    .browse-choice {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .browse-tools {
        grid-template-columns: 1fr;
    }

    .browse-choice,
    .letter-strip,
    .results-panel,
    .setlist-panel {
        width: calc(100vw - 28px);
        max-width: calc(100vw - 28px);
    }

    .content-grid {
        width: calc(100vw - 28px);
        min-width: 0;
        max-width: calc(100vw - 28px);
    }

    .letter-strip {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .search-scope {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        overflow-x: visible;
    }

    .search-scope label {
        min-width: 0;
    }

    .search-scope span,
    .mode-tab {
        width: 100%;
        padding-right: 10px;
        padding-left: 10px;
    }

    .select-filter,
    .filter-checks,
    .search-order {
        width: 100%;
    }

    .select-filter select {
        flex: 1 1 160px;
        width: auto;
    }

    .search-order {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .letter-button {
        flex: 0 0 auto;
    }

    .browse-row {
        grid-template-columns: 1fr;
    }

    .artist-song-row {
        grid-template-columns: 1fr;
        padding-left: 14px;
    }

    .browse-row .browse-artist {
        grid-column: 1 / -1;
    }

    .browse-row .row-tools,
    .artist-song-row .row-tools {
        grid-column: 1 / -1;
        justify-content: center;
    }

    .card-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .song-popout {
        justify-content: center;
    }

    .song-links-popout,
    .song-tags-popout,
    .card-actions .song-links-popout,
    .card-actions .song-tags-popout {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    .add-button {
        width: 100%;
    }

    body.setlist-open {
        overflow: hidden;
    }

    .setlist-panel {
        display: none;
        position: fixed;
        right: 12px;
        bottom: 12px;
        left: 12px;
        z-index: 20;
        width: auto;
        max-width: none;
        max-height: min(76vh, 620px);
        overflow: auto;
        box-shadow: var(--drawer-shadow);
    }

    body.setlist-open .setlist-panel {
        display: block;
    }

    .close-setlist {
        display: inline-flex;
    }

    .mobile-setlist-button {
        position: fixed;
        right: 14px;
        bottom: 14px;
        z-index: 18;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 46px;
        border: 0;
        border-radius: 999px;
        padding: 0 16px;
        color: var(--accent-ink);
        background: var(--accent);
        box-shadow: var(--mobile-button-shadow);
        font-weight: 900;
    }

    .mobile-setlist-button svg {
        width: 18px;
        height: 18px;
    }
}
