:root {
    --bg: #0c0a11;
    --surface: #15111d;
    --surface-2: #1c1627;
    --surface-3: #261d35;
    --text: #f5f1fa;
    --muted: #aaa0b8;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #a978ff;
    --accent-2: #e0b45f;
    --danger: #ff7a8f;
    --success: #70d6a2;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    --radius: 24px;
    --radius-small: 15px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 90% 0%, rgba(169, 120, 255, 0.15), transparent 32rem),
        radial-gradient(circle at 0% 100%, rgba(224, 180, 95, 0.08), transparent 32rem),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button,
select,
input[type="range"] {
    accent-color: var(--accent);
}

button {
    color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(169, 120, 255, 0.55);
    outline-offset: 3px;
}

.app-shell {
    width: min(1540px, 100%);
    margin: 0 auto;
    padding: 26px clamp(16px, 3vw, 44px) calc(30px + var(--safe-bottom));
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.topbar h1,
.panel-heading h2,
.section-heading h2,
.section-heading h3,
.book-hero h2,
.now-playing-card h3,
.welcome-state h2 {
    margin: 0;
    line-height: 1.1;
}

.topbar h1 {
    margin-top: 4px;
    font-size: clamp(2rem, 5vw, 4.4rem);
    letter-spacing: -0.055em;
}

.subtitle,
.description,
.author,
.welcome-state > p:last-child,
.empty-library p,
.empty-note {
    color: var(--muted);
}

.subtitle {
    margin: 8px 0 0;
}

.eyebrow {
    margin: 0;
    color: var(--accent-2);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.layout {
    display: grid;
    grid-template-columns: minmax(300px, 410px) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.library-panel,
.player-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(21, 17, 29, 0.9);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.library-panel {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    overflow: hidden;
    padding: 22px;
}

.player-panel {
    min-height: 680px;
    padding: clamp(18px, 3vw, 34px);
}

.panel-heading,
.section-heading,
.chapter-heading,
.progress-copy,
.time-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.count-badge {
    display: grid;
    min-width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 999px;
    color: #120d19;
    background: var(--accent-2);
    font-weight: 900;
}

.search-box {
    display: block;
    margin: 18px 0;
}

.search-box input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 12px 16px;
    color: var(--text);
    background: var(--surface-2);
}

.book-list {
    display: grid;
    gap: 10px;
    max-height: calc(100vh - 230px);
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-color: var(--surface-3) transparent;
}

.book-card,
.resume-card {
    width: 100%;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    padding: 10px;
    text-align: left;
    background: transparent;
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.book-card:hover,
.book-card.active,
.resume-card:hover {
    transform: translateY(-1px);
    border-color: rgba(169, 120, 255, 0.32);
    background: var(--surface-2);
}

.book-card-inner,
.resume-card {
    display: grid;
    grid-template-columns: 66px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

.cover {
    position: relative;
    display: grid;
    overflow: hidden;
    place-items: center;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 17px;
    background:
        linear-gradient(145deg, rgba(169, 120, 255, 0.32), rgba(224, 180, 95, 0.13)),
        var(--surface-3);
    color: rgba(255, 255, 255, 0.86);
    font-size: 1.45rem;
    font-weight: 900;
    letter-spacing: -0.05em;
}

.cover.has-image {
    background-position: center;
    background-size: cover;
}

.cover.has-image > span {
    display: none;
}

.book-copy {
    min-width: 0;
}

.book-copy strong,
.book-copy span,
.book-copy small {
    display: block;
}

.book-copy strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-copy span,
.book-copy small {
    color: var(--muted);
}

.book-copy small {
    margin-top: 4px;
}

.book-meta-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-badge {
    display: inline-flex !important;
    width: fit-content;
    margin-top: 5px;
    border-radius: 999px;
    padding: 2px 7px;
    color: #140d1c !important;
    background: var(--accent-2);
    font-size: 0.65rem;
    font-weight: 900;
    text-transform: uppercase;
}

.mini-progress,
.progress-track {
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.mini-progress {
    height: 4px;
    margin-top: 8px;
}

.mini-progress span,
.progress-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width 220ms ease;
}

.resume-section {
    margin-bottom: 16px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
}

.resume-card {
    margin-top: 8px;
    background: rgba(169, 120, 255, 0.08);
}

.welcome-state {
    display: grid;
    min-height: 610px;
    place-items: center;
    align-content: center;
    max-width: 640px;
    margin: auto;
    text-align: center;
}

.welcome-symbol {
    display: grid;
    width: 98px;
    height: 98px;
    margin-bottom: 24px;
    place-items: center;
    border: 1px solid rgba(169, 120, 255, 0.35);
    border-radius: 50%;
    color: var(--accent-2);
    background: radial-gradient(circle, rgba(169, 120, 255, 0.22), transparent 66%);
    box-shadow: 0 0 70px rgba(169, 120, 255, 0.18);
    font-size: 2.4rem;
}

.player-content {
    display: grid;
    gap: 20px;
}

.book-hero {
    display: grid;
    grid-template-columns: minmax(170px, 250px) minmax(0, 1fr);
    gap: clamp(20px, 4vw, 42px);
    align-items: center;
}

.large-cover {
    border-radius: 26px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, 0.35);
    font-size: clamp(2.8rem, 7vw, 5.6rem);
}

.book-hero h2 {
    margin-top: 8px;
    font-size: clamp(2rem, 4vw, 3.7rem);
    letter-spacing: -0.045em;
}

.author {
    margin: 8px 0;
    font-weight: 700;
}

.description {
    max-width: 75ch;
    white-space: pre-line;
}

.overall-progress {
    margin-top: 22px;
}

.progress-copy {
    margin-bottom: 8px;
    font-size: 0.86rem;
}

.progress-track {
    height: 8px;
}

.now-playing-card,
.chapters-card,
.bookmarks-card {
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: clamp(18px, 3vw, 28px);
    background: var(--surface-2);
}

.chapter-heading {
    align-items: flex-start;
}

.icon-text-button,
.control-button,
.ghost-button,
.danger-button,
.dialog-close {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 14px;
    background: transparent;
    cursor: pointer;
}

.icon-text-button:hover,
.control-button:hover,
.ghost-button:hover {
    border-color: rgba(169, 120, 255, 0.45);
    background: rgba(169, 120, 255, 0.09);
}

.icon-text-button.completed {
    color: var(--success);
    border-color: rgba(112, 214, 162, 0.32);
}

.timeline-wrap {
    margin-top: 28px;
}

.timeline {
    width: 100%;
    cursor: pointer;
}

.time-row {
    margin-top: 4px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.82rem;
}

.main-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(8px, 2vw, 18px);
    margin: 22px 0;
}

.round-button,
.play-button {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    cursor: pointer;
}

.round-button {
    width: 52px;
    height: 52px;
    background: var(--surface-3);
    font-weight: 800;
}

.round-button.small {
    width: 44px;
    height: 44px;
    color: var(--muted);
    font-size: 0.78rem;
}

.round-button:hover {
    border-color: rgba(169, 120, 255, 0.5);
}

.play-button {
    width: 76px;
    height: 76px;
    border: 0;
    color: #160f1e;
    background: linear-gradient(145deg, var(--accent), #c8a4ff);
    box-shadow: 0 12px 30px rgba(169, 120, 255, 0.3);
    font-size: 1.7rem;
    font-weight: 900;
}

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

.secondary-controls label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 0.76rem;
}

.secondary-controls select {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0 11px;
    color: var(--text);
    background: var(--surface-3);
}

.control-button {
    min-height: 42px;
}

.sleep-status {
    min-height: 1.5em;
    margin: 14px 0 0;
    color: var(--accent-2);
    text-align: center;
    font-size: 0.85rem;
}

.chapter-list,
.bookmark-list {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.chapter-item,
.bookmark-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.025);
}

.chapter-item {
    width: 100%;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.chapter-item:hover,
.chapter-item.active {
    border-color: rgba(169, 120, 255, 0.35);
    background: rgba(169, 120, 255, 0.08);
}

.chapter-index {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 10px;
    color: var(--muted);
    background: var(--surface-3);
    font-size: 0.76rem;
    font-weight: 900;
}

.chapter-item.completed .chapter-index {
    color: #0d1712;
    background: var(--success);
}

.chapter-item-copy {
    min-width: 0;
}

.chapter-item-copy strong,
.chapter-item-copy small {
    display: block;
}

.chapter-item-copy strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-item-copy small {
    color: var(--muted);
}

.chapter-status {
    color: var(--muted);
    font-size: 0.78rem;
}

.bookmark-item button {
    border: 0;
    padding: 4px 8px;
    color: var(--danger);
    background: transparent;
    cursor: pointer;
}

.bookmark-jump {
    border: 0 !important;
    padding: 0 !important;
    color: inherit !important;
    text-align: left;
    background: transparent !important;
}

.bookmark-jump strong,
.bookmark-jump small {
    display: block;
}

.bookmark-jump small {
    color: var(--muted);
}

.compact {
    padding: 7px 11px;
    font-size: 0.78rem;
}

.empty-library,
.empty-note {
    padding: 22px 8px;
    text-align: center;
}

.empty-library code {
    color: var(--accent-2);
}

footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 4px 0;
    color: var(--muted);
    font-size: 0.78rem;
}

dialog {
    width: min(560px, calc(100% - 28px));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.dialog-card {
    padding: 24px;
}

.dialog-close {
    display: grid;
    width: 38px;
    height: 38px;
    padding: 0;
    place-items: center;
    font-size: 1.4rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 24px 0;
}

.stats-grid div {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    background: var(--surface-2);
}

.stats-grid span,
.stats-grid strong {
    display: block;
}

.stats-grid span {
    color: var(--muted);
    font-size: 0.78rem;
}

.stats-grid strong {
    margin-top: 5px;
    font-size: 1.1rem;
}

.danger-button {
    width: 100%;
    color: var(--danger);
}

.danger-button:hover {
    background: rgba(255, 122, 143, 0.08);
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
}

[hidden] {
    display: none !important;
}

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

    .library-panel {
        position: static;
        max-height: none;
    }

    .book-list {
        grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
        max-height: none;
        overflow: visible;
    }

    .player-panel {
        min-height: auto;
    }

    .welcome-state {
        min-height: 340px;
    }
}

@media (max-width: 680px) {
    .app-shell {
        padding-top: 18px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions button {
        flex: 1;
    }

    .book-hero {
        grid-template-columns: 110px minmax(0, 1fr);
        align-items: start;
    }

    .book-hero h2 {
        font-size: 1.65rem;
    }

    .description {
        grid-column: 1 / -1;
    }

    .overall-progress {
        grid-column: 1 / -1;
    }

    .chapter-heading,
    .section-heading {
        align-items: flex-start;
    }

    .icon-text-button {
        max-width: 140px;
        border-radius: 14px;
        font-size: 0.76rem;
    }

    .main-controls {
        gap: 7px;
    }

    .round-button {
        width: 46px;
        height: 46px;
    }

    .round-button.small {
        width: 38px;
        height: 38px;
    }

    .play-button {
        width: 66px;
        height: 66px;
    }

    .secondary-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .secondary-controls label,
    .secondary-controls select,
    .secondary-controls .control-button {
        width: 100%;
    }

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

@media (max-width: 430px) {
    .book-hero {
        grid-template-columns: 88px minmax(0, 1fr);
        gap: 15px;
    }

    .large-cover {
        border-radius: 18px;
    }

    .library-panel,
    .player-panel {
        border-radius: 19px;
    }

    .book-list {
        grid-template-columns: 1fr;
    }

    .round-button.small {
        display: none;
    }
}
