:root {
    --paper: #f7f3ea;
    --ink: #20211d;
    --muted: #64665f;
    --line: #d8d0c2;
    --panel: #fffcf4;
    --accent: #2e6f5f;
    --accent-dark: #1f5045;
    --rust: #9a4f2f;
    --gold: #d6a844;
    --header-start: #24251f;
    --header-end: #303127;
    --header-text: #fffaf0;
    --header-muted: #e4dac4;
    --field: #fffdf7;
    --soft-panel: #fffaf0;
    --sidebar: #eee7d8;
    --filter-panel: #fbf6ea;
    --quote-bg: #eef5ef;
    --shadow: 0 10px 24px rgba(32, 33, 29, 0.08);
    color-scheme: light;
}

body[data-theme="dark"] {
    --paper: #151711;
    --ink: #f2ead8;
    --muted: #b8ae9c;
    --line: #404336;
    --panel: #1d2018;
    --accent: #71a58f;
    --accent-dark: #b4d9ca;
    --rust: #d58b62;
    --gold: #e0bb5f;
    --header-start: #090a08;
    --header-end: #151711;
    --header-text: #f8f0df;
    --header-muted: #c9bea7;
    --field: #23261e;
    --soft-panel: #20241b;
    --sidebar: #1b1e17;
    --filter-panel: #20241b;
    --quote-bg: #1f2b24;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.setup-error {
    padding: 10px 16px;
    background: #7d2f24;
    color: #fff;
    font-weight: 700;
}

button,
input {
    font: inherit;
}

.search-shell {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 12.5vh;
    max-height: 142px;
    padding: 18px clamp(16px, 3vw, 42px);
    background: linear-gradient(180deg, var(--header-start) 0%, var(--header-end) 100%);
    border-bottom: 4px solid var(--gold);
    color: var(--header-text);
    display: grid;
    align-content: center;
    gap: 12px;
}

.search-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.35rem, 2.6vw, 2.1rem);
    font-weight: 700;
}

.db-count {
    color: var(--header-muted);
    font-size: 0.92rem;
    text-align: right;
}

.search-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    gap: 0;
}

.search-box {
    position: relative;
    min-width: 0;
}

#songSearch {
    width: 100%;
    min-width: 0;
    height: 52px;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 0 18px;
    background: var(--field);
    color: var(--ink);
    font-size: clamp(1rem, 1.4vw, 1.28rem);
    outline: none;
    box-shadow: inset 0 0 0 1px rgba(32, 33, 29, 0.08), var(--shadow);
}

.search-action,
.theme-toggle {
    display: none;
    height: 52px;
    min-width: 58px;
    border: 1px solid rgba(255, 250, 240, 0.28);
    border-radius: 8px;
    background: var(--gold);
    color: #20211d;
    cursor: pointer;
    font-weight: 800;
}

.theme-toggle {
    min-width: 76px;
    background: transparent;
    color: var(--header-text);
}

.search-action:hover,
.search-action:focus,
.theme-toggle:hover,
.theme-toggle:focus {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

#songSearch:focus {
    border-color: var(--gold);
}

.suggestions {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 40;
    max-height: min(320px, 62vh);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.suggestions.is-open {
    display: grid;
}

.suggestion-item {
    min-width: 0;
    padding: 10px 12px;
    border: 0;
    border-left: 4px solid transparent;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    text-align: left;
}

.suggestion-item:last-child {
    border-bottom: 0;
}

.suggestion-item:hover,
.suggestion-item:focus,
.suggestion-item[aria-selected="true"] {
    border-left-color: var(--rust);
    background: var(--soft-panel);
    outline: none;
}

.suggestion-title,
.suggestion-subtitle {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.suggestion-title {
    font-weight: 750;
}

.suggestion-subtitle {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.86rem;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(270px, 34vw) minmax(0, 1fr);
    min-height: calc(100vh - 12.5vh);
}

.results-shell {
    border-right: 1px solid var(--line);
    background: var(--sidebar);
    min-height: 0;
    padding: 16px;
}

.catalog-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
    gap: 6px;
    margin-bottom: 10px;
}

.catalog-tab {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft-panel);
    color: var(--ink);
    cursor: pointer;
    font-weight: 700;
}

.catalog-tab.is-active {
    background: var(--header-start);
    border-color: var(--header-start);
    color: var(--header-text);
}

.result-count {
    min-height: 24px;
    color: var(--muted);
    font-size: 0.92rem;
}

.results-list {
    display: grid;
    gap: 8px;
    padding: 6px 0 24px;
}

.result-item {
    width: 100%;
    min-height: 84px;
    padding: 12px;
    border: 1px solid var(--line);
    border-left: 4px solid transparent;
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.result-item:hover,
.result-item:focus,
.result-item.is-selected,
.result-item[data-active="true"] {
    border-left-color: var(--rust);
    outline: none;
}

.result-title {
    display: block;
    font-weight: 700;
    line-height: 1.25;
}

.result-subtitle,
.result-snippet {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.35;
}

.result-snippet {
    color: var(--muted);
}

.no-results,
.loading-detail {
    padding: 12px;
    color: var(--muted);
    font-size: 0.95rem;
}

.detail-shell {
    min-width: 0;
    padding: clamp(18px, 3vw, 38px);
    background: var(--paper);
}

.detail-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.kind-pill {
    min-height: 22px;
    color: var(--rust);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 4px 0 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2rem, 4vw, 4.2rem);
    line-height: 1;
    font-weight: 700;
}

.source-link {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--accent-dark);
    background: var(--soft-panel);
    text-decoration: none;
}

.source-link:hover,
.source-link:focus {
    border-color: var(--accent);
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1px;
    margin: 18px 0;
    border: 1px solid var(--line);
    background: var(--line);
}

.meta-item {
    min-width: 0;
    padding: 12px;
    background: var(--soft-panel);
}

.meta-label {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
}

.meta-value {
    display: block;
    margin-top: 4px;
    overflow-wrap: anywhere;
    font-weight: 650;
}

.media-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
}

.media-link {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft-panel);
    color: var(--accent-dark);
    text-decoration: none;
    font-size: 0.92rem;
}

.annotation-block {
    display: grid;
    gap: 10px;
    margin: 0 0 18px;
}

.annotation-title {
    margin: 0;
    color: var(--rust);
    font-size: 0.84rem;
    text-transform: uppercase;
}

.annotation-list {
    margin: 0;
    padding-left: 20px;
    color: var(--ink);
}

.annotation-list li {
    margin: 5px 0;
}

.related-note {
    border-left: 4px solid var(--gold);
    padding: 10px 12px;
    background: var(--soft-panel);
}

.related-note strong {
    display: block;
    margin-bottom: 4px;
}

.chart {
    width: 100%;
    margin: 0;
    padding: clamp(14px, 2vw, 22px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--ink);
    box-shadow: var(--shadow);
    overflow: auto;
    font: 0.95rem/1.45 "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.chart-text {
    margin: 0;
    white-space: pre-wrap;
    font: inherit;
}

.tab-quote {
    margin: 12px 0;
    padding: 12px 14px;
    border: 0;
    border-left: 4px solid var(--accent);
    background: var(--quote-bg);
    color: var(--ink);
    overflow: auto;
}

.tab-quote pre {
    margin: 0;
    min-width: max-content;
    white-space: pre;
    font: inherit;
}

@media (max-width: 900px) {
    .search-shell {
        max-height: none;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .results-shell {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .results-list {
        grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    }

    .meta-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.is-mobile-detail .results-shell {
        display: none;
    }

    body.is-mobile-detail .detail-shell {
        padding-top: 14px;
    }
}

@media (pointer: coarse) {
    body.is-mobile-detail .app-shell {
        grid-template-columns: 1fr;
    }

    body.is-mobile-detail .results-shell {
        display: none;
    }

    body.is-mobile-detail .detail-shell {
        padding-top: 14px;
    }
}

@media (max-width: 560px), (pointer: coarse) {
    .source-link,
    .meta-grid,
    .media-row,
    .annotation-block {
        display: none;
    }

    .detail-head {
        padding-bottom: 8px;
        border-bottom: 0;
    }
}

@media (max-width: 560px) {
    .search-shell {
        min-height: auto;
        padding: 10px;
        gap: 0;
    }

    .search-meta {
        display: none;
    }

    .search-row {
        grid-template-columns: minmax(0, 1fr) 52px 66px;
        gap: 6px;
    }

    #songSearch {
        height: 44px;
        padding: 0 10px;
        font-size: 1rem;
    }

    .suggestions {
        max-height: min(230px, 52vh);
    }

    .search-action,
    .theme-toggle {
        display: block;
        height: 44px;
        min-width: 0;
        padding: 0 8px;
        font-size: 0.92rem;
    }

    .detail-head {
        flex-direction: column;
    }

    .meta-grid {
        grid-template-columns: 1fr;
    }

    .chart {
        padding: 8px;
        font-size: 0.88rem;
    }

    .tab-quote {
        padding: 8px 8px 8px 10px;
        overflow: hidden;
    }

    .tab-quote pre {
        min-width: 0;
        max-width: 100%;
    }
}
