:root {
    color-scheme: light;
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f6f4ef;
    color: #25211b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    background: #f6f4ef;
}

button,
select,
input {
    font: inherit;
}

a {
    color: inherit;
}

.app-shell {
    width: min(1180px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 28px 0 36px;
}

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 6px;
    color: #5d6b63;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 4vw, 3.4rem);
    line-height: 1;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 0;
    font-size: 1.65rem;
    line-height: 1.15;
    letter-spacing: 0;
}

h3 {
    margin-bottom: 0;
    font-size: 1rem;
}

.source-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    min-width: 170px;
    padding: 12px 14px;
    border: 1px solid #ded7c8;
    border-radius: 8px;
    background: #fffdf8;
}

.source-status span {
    color: #6a6258;
    font-size: 0.82rem;
}

.source-status--ok strong {
    color: #146c54;
}

.source-status--warn strong,
.source-status--warn span {
    color: #8a3f1d;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.header-link {
    display: inline-grid;
    place-items: center;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid #cfc7b8;
    border-radius: 6px;
    background: #fffdf8;
    color: #155946;
    font-weight: 800;
    text-decoration: none;
}

.notice {
    display: grid;
    gap: 7px;
    margin-bottom: 18px;
    padding: 14px 16px;
    border: 1px solid #e2b990;
    border-radius: 8px;
    background: #fff7ec;
    color: #4c3424;
}

.notice code {
    overflow-wrap: anywhere;
    color: #6a452a;
}

.progress-panel {
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid #ddd5c6;
    border-radius: 8px;
    background: #fffdf8;
}

.progress-track {
    overflow: hidden;
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: #e7dfd0;
}

.progress-track span {
    display: block;
    height: 100%;
    min-width: 4px;
    border-radius: inherit;
    background: #155946;
    transition: width 180ms ease;
}

.progress-track--unknown span {
    animation: progress-slide 1.1s ease-in-out infinite;
}

.progress-current {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.progress-current span {
    color: #625d54;
    font-size: 0.86rem;
    font-weight: 700;
}

.progress-current strong,
.progress-current small {
    overflow-wrap: anywhere;
}

.progress-current small {
    color: #746d62;
}

@keyframes progress-slide {
    0% {
        transform: translateX(-110%);
    }

    100% {
        transform: translateX(300%);
    }
}

.workspace {
    display: grid;
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.selector-panel,
.player-panel {
    border: 1px solid #ddd5c6;
    border-radius: 8px;
    background: #fffdf8;
}

.selector-panel {
    display: grid;
    gap: 14px;
    padding: 16px;
    position: sticky;
    top: 16px;
}

.field {
    display: grid;
    gap: 7px;
}

.field span,
.range-control span {
    color: #625d54;
    font-size: 0.86rem;
    font-weight: 700;
}

select {
    width: 100%;
    min-height: 42px;
    padding: 0 38px 0 12px;
    border: 1px solid #cfc7b8;
    border-radius: 6px;
    background: #fff;
    color: #25211b;
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
    gap: 6px;
}

.chapter-button {
    display: grid;
    place-items: center;
    min-height: 38px;
    border: 1px solid #ddd5c6;
    border-radius: 6px;
    background: #fbfaf6;
    color: #746d62;
    cursor: pointer;
}

.chapter-button:hover {
    border-color: #82a398;
    color: #25211b;
}

.chapter-button--available {
    color: #155946;
    border-color: #add2c5;
    background: #eef8f3;
}

.chapter-button--active {
    color: #fff;
    border-color: #155946;
    background: #155946;
}

.player-panel {
    display: grid;
    gap: 18px;
    min-width: 0;
    padding: 18px;
}

.chapter-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.api-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.api-links a,
.text-link {
    min-height: 34px;
    padding: 8px 11px;
    border: 1px solid #cfc7b8;
    border-radius: 6px;
    background: #fff;
    color: #155946;
    font-weight: 700;
    text-decoration: none;
}

.text-link--inline {
    width: fit-content;
}

.audio-player {
    width: 100%;
    min-height: 46px;
}

.empty-player {
    display: grid;
    gap: 4px;
    min-height: 76px;
    padding: 16px;
    border: 1px dashed #cfc7b8;
    border-radius: 8px;
    background: #fbfaf6;
    color: #625d54;
}

.controls {
    display: grid;
    grid-template-columns: auto minmax(190px, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 14px;
    border: 1px solid #e5ddce;
    border-radius: 8px;
    background: #fbfaf6;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 38px;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch span {
    position: relative;
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: #bbb3a5;
    transition: background-color 160ms ease;
}

.switch span::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 160ms ease;
}

.switch input:checked + span {
    background: #155946;
}

.switch input:checked + span::after {
    transform: translateX(20px);
}

.range-control {
    display: grid;
    grid-template-columns: auto minmax(120px, 1fr) 48px;
    gap: 10px;
    align-items: center;
}

.range-control input {
    width: 100%;
    accent-color: #155946;
}

.range-control output {
    color: #625d54;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.speed-control {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.speed-button {
    min-width: 48px;
    min-height: 34px;
    border: 1px solid #cfc7b8;
    border-radius: 6px;
    background: #fff;
    color: #524b42;
    cursor: pointer;
}

.speed-button--active {
    border-color: #b45722;
    background: #b45722;
    color: #fff;
}

.parts-section {
    display: grid;
    gap: 10px;
    border: 1px solid #e5ddce;
    border-radius: 8px;
    background: #fff;
    padding: 0 12px 12px;
}

.section-title {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    margin: 0 -12px;
    padding: 0 12px;
    cursor: pointer;
    list-style: none;
}

.section-title::-webkit-details-marker {
    display: none;
}

.section-title::before {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    border: 1px solid #add2c5;
    border-radius: 50%;
    background: #eef8f3;
}

.section-title::after {
    content: "";
    position: absolute;
    left: 22px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-right: 2px solid #155946;
    border-bottom: 2px solid #155946;
    transform: translateY(-50%) rotate(-45deg);
    transition: transform 160ms ease;
}

.parts-section[open] .section-title::after {
    transform: translateY(-50%) rotate(45deg);
}

.section-title h3 {
    min-width: 0;
}

.parts-section[open] .section-title::before {
    border-color: #82a398;
    background: #dff1e9;
}

.parts-section:not([open]) {
    padding-bottom: 0;
}

.section-title:hover {
    background: #fbfaf6;
}

.section-title span {
    display: grid;
    place-items: center;
    min-width: 32px;
    height: 28px;
    border-radius: 999px;
    background: #efe8da;
    color: #625d54;
    font-weight: 700;
}

.part-list {
    display: grid;
    gap: 8px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.part-list li {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid #e5ddce;
    border-radius: 8px;
    background: #fff;
}

.part-list li.part-item--active {
    border-color: #82a398;
    background: #f3fbf7;
}

.part-order {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    background: #eef8f3;
    color: #155946;
    font-weight: 800;
}

.part-main {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.part-main span,
.part-main small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.part-main small,
.muted {
    color: #746d62;
}

.part-meta {
    display: grid;
    gap: 2px;
    color: #625d54;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.part-play-button {
    min-width: 62px;
    min-height: 34px;
    border: 1px solid #cfc7b8;
    border-radius: 6px;
    background: #fff;
    color: #155946;
    font-weight: 800;
    cursor: pointer;
}

.part-play-button:hover,
.part-item--active .part-play-button {
    border-color: #155946;
    background: #155946;
    color: #fff;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.metric-card {
    display: grid;
    gap: 5px;
    min-height: 84px;
    padding: 14px;
    border: 1px solid #ddd5c6;
    border-radius: 8px;
    background: #fffdf8;
}

.metric-card span {
    color: #625d54;
    font-size: 0.84rem;
    font-weight: 700;
}

.metric-card strong {
    color: #155946;
    font-size: 1.25rem;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

.statistics-panel {
    display: grid;
    gap: 12px;
    padding: 18px;
    border: 1px solid #ddd5c6;
    border-radius: 8px;
    background: #fffdf8;
}

.statistics-table {
    display: grid;
    gap: 6px;
}

.book-details {
    border: 1px solid #e5ddce;
    border-radius: 8px;
    background: #fff;
}

.book-details summary {
    display: grid;
    grid-template-columns: minmax(220px, 1.5fr) repeat(4, minmax(90px, 1fr));
    gap: 12px;
    align-items: center;
    min-height: 52px;
    padding: 10px 12px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    list-style: none;
}

.book-details summary::-webkit-details-marker {
    display: none;
}

.book-details summary::before {
    content: ">";
    color: #155946;
    font-weight: 900;
}

.book-details[open] summary::before {
    content: "v";
}

.book-details summary:hover {
    background: #fbfaf6;
}

.book-cell {
    display: grid;
    gap: 2px;
    min-width: 0;
    font-variant-numeric: normal;
}

.book-cell strong,
.book-cell small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-cell small {
    color: #746d62;
}

.file-list {
    display: grid;
    gap: 5px;
    padding: 0 12px 12px;
}

.file-row {
    display: grid;
    grid-template-columns: 70px minmax(220px, 1.7fr) minmax(100px, 0.7fr) minmax(90px, 0.7fr) minmax(90px, 0.7fr);
    gap: 10px;
    align-items: center;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid #eee7da;
    border-radius: 6px;
    background: #fffdf8;
    font-variant-numeric: tabular-nums;
}

.file-row--head {
    min-height: 32px;
    background: #eef8f3;
    color: #155946;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.file-cell {
    display: grid;
    gap: 2px;
    min-width: 0;
    font-variant-numeric: normal;
}

.file-cell strong,
.file-cell small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-cell small {
    color: #746d62;
}

.missing-book-list {
    display: grid;
    gap: 6px;
}

.missing-book {
    border: 1px solid #e5ddce;
    border-radius: 8px;
    background: #fff;
}

.missing-book summary {
    display: grid;
    grid-template-columns: minmax(220px, 1fr);
    min-height: 48px;
    padding: 10px 12px;
    cursor: pointer;
    list-style: none;
}

.missing-book summary::-webkit-details-marker {
    display: none;
}

.missing-book summary::before {
    content: ">";
    color: #155946;
    font-weight: 900;
}

.missing-book[open] summary::before {
    content: "v";
}

.missing-book summary:hover {
    background: #fbfaf6;
}

.missing-chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    padding: 0 12px 12px;
}

.missing-chapter-grid span {
    display: grid;
    place-items: center;
    min-height: 32px;
    border: 1px solid #e2b990;
    border-radius: 6px;
    background: #fff7ec;
    color: #8a3f1d;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.empty-state {
    width: min(760px, calc(100vw - 32px));
    margin: 56px auto;
}

@media (max-width: 820px) {
    .app-header,
    .chapter-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .source-status,
    .header-actions,
    .api-links {
        align-items: flex-start;
        justify-content: flex-start;
    }

    .header-actions {
        flex-wrap: wrap;
    }

    .workspace {
        grid-template-columns: 1fr;
    }

    .stats-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .book-details summary {
        grid-template-columns: minmax(170px, 1.4fr) repeat(4, minmax(72px, 1fr));
        overflow-x: auto;
    }

    .file-row {
        grid-template-columns: 56px minmax(180px, 1.4fr) repeat(3, minmax(72px, 1fr));
        overflow-x: auto;
    }

    .selector-panel {
        position: static;
    }

    .controls {
        grid-template-columns: 1fr;
    }

    .range-control {
        grid-template-columns: 1fr 64px;
    }

    .range-control span {
        grid-column: 1 / -1;
    }

    .speed-control {
        justify-content: flex-start;
    }
}

@media (max-width: 520px) {
    .app-shell {
        width: min(100vw - 20px, 1180px);
        padding-top: 16px;
    }

    .part-list li {
        grid-template-columns: 34px minmax(0, 1fr);
    }

    .part-meta,
    .part-play-button {
        grid-column: 2;
    }

    .part-meta {
        text-align: left;
    }

    .stats-summary {
        grid-template-columns: 1fr;
    }

    .book-details summary {
        grid-template-columns: 1fr 1fr;
    }

    .book-cell {
        grid-column: 1 / -1;
    }

    .file-row,
    .file-row--head {
        grid-template-columns: 1fr 1fr;
    }

    .file-row--head {
        display: none;
    }

    .file-cell {
        grid-column: 1 / -1;
    }
}
