:root {
    --bg: #071018;
    --panel: rgba(10, 18, 25, 0.95);
    --panel-soft: rgba(12, 22, 30, 0.84);
    --panel-border: rgba(122, 215, 242, 0.22);
    --text-main: #ecf5fb;
    --text-muted: #9fb6c5;
    --accent-brass: #d7bb74;
    --accent-steel: #7ad7f2;
    --accent-deep: #163646;
    --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.42);
}

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

body {
    background:
        radial-gradient(circle at top, rgba(122, 215, 242, 0.12), transparent 26%),
        radial-gradient(circle at 85% 0%, rgba(215, 187, 116, 0.12), transparent 24%),
        linear-gradient(180deg, #09111a 0%, #05080d 100%);
    color: var(--text-main);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body.reader-page {
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

body.home-page,
body.audiobook-page {
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: manipulation;
}

body.theme-dark {
    --panel: rgba(10, 18, 25, 0.95);
    --panel-soft: rgba(12, 22, 30, 0.84);
    --panel-border: rgba(122, 215, 242, 0.22);
    --text-main: #ecf5fb;
    --text-muted: #9fb6c5;
}

body.theme-light {
    --panel: rgba(247, 250, 252, 0.96);
    --panel-soft: rgba(235, 242, 246, 0.94);
    --panel-border: rgba(71, 116, 140, 0.18);
    --text-main: #17232d;
    --text-muted: #566976;
    background:
        radial-gradient(circle at top, rgba(71, 116, 140, 0.08), transparent 28%),
        linear-gradient(180deg, #f4f7f9 0%, #dbe5ea 100%);
}

body.theme-sepia {
    --panel: rgba(246, 238, 221, 0.96);
    --panel-soft: rgba(234, 222, 199, 0.93);
    --panel-border: rgba(141, 111, 80, 0.18);
    --text-main: #4f3925;
    --text-muted: #7d6650;
    background:
        radial-gradient(circle at top, rgba(141, 111, 80, 0.08), transparent 28%),
        linear-gradient(180deg, #f6ead5 0%, #dfcfb7 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
.button-link,
select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid currentColor;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    padding: 8px 12px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

button:hover,
button:focus-visible,
.button-link:hover,
.button-link:focus-visible,
select:hover,
select:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

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

.primary-link,
.chapter-button.active,
.transport-button.primary {
    background: linear-gradient(135deg, rgba(215, 187, 116, 0.24), rgba(122, 215, 242, 0.18));
    border-color: rgba(215, 187, 116, 0.65);
}

.inline-link {
    padding-inline: 14px;
}

.eyebrow {
    margin: 0;
    color: var(--accent-steel);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.mode-shell,
.listen-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 40px;
    box-sizing: border-box;
}

.hero-card,
.player-panel,
.chapters-panel {
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-strong);
    backdrop-filter: blur(14px);
}

.hero-card {
    min-height: calc(100vh - 64px);
    border-radius: 28px;
    padding: 34px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 28px;
}

.hero-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.hero-logo {
    width: 82px;
    height: auto;
}

.hero-copy {
    max-width: 760px;
}

.hero-copy h1,
.listen-header h1 {
    margin: 8px 0 14px;
    font-size: clamp(2.8rem, 7vw, 4.8rem);
    line-height: 0.94;
    color: var(--accent-brass);
}

.hero-kicker,
.hero-summary {
    margin: 0;
}

.hero-kicker {
    color: var(--text-main);
    font-size: 1.1rem;
}

.hero-summary {
    max-width: 640px;
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1.7;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.mode-card {
    padding: 22px;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(12, 21, 29, 0.88) 0%, rgba(8, 13, 19, 0.94) 100%);
    border: 1px solid rgba(122, 215, 242, 0.18);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.mode-art,
.audio-cover {
    width: min(100%, 320px);
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 20px;
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
}

.mode-card h2,
.player-panel h2,
.chapters-header h2 {
    margin: 0;
}

.mode-card p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.6;
}

#app-container {
    position: relative;
    width: 100vw;
    height: 100vh;
}

#viewer {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
}

#viewer iframe {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.hud-element {
    position: fixed !important;
    left: 0 !important;
    width: 100% !important;
    min-height: 68px !important;
    padding: 0 18px;
    box-sizing: border-box;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--panel) !important;
    color: var(--text-main) !important;
    border-color: var(--panel-border);
    z-index: 2147483647 !important;
    pointer-events: none;
    transition: transform 0.28s ease, opacity 0.28s ease;
    will-change: transform;
    backdrop-filter: blur(14px);
}

.hud-element.visible {
    transform: translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

#hud-top {
    top: 0;
    transform: translateY(-100%);
    border-bottom: 1px solid var(--panel-border);
}

#hud-bottom {
    bottom: 0;
    transform: translateY(100%);
    border-top: 1px solid var(--panel-border);
}

.book-title {
    flex: 1;
    min-width: 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: center;
}

.hud-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

#menu-btn,
#fullscreen-btn {
    flex-shrink: 0;
}

#side-menu {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 30;
    width: min(320px, 84vw);
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    background: linear-gradient(180deg, rgba(7, 13, 19, 0.98) 0%, rgba(13, 22, 29, 0.98) 100%);
    color: var(--text-main);
    border-right: 1px solid rgba(122, 215, 242, 0.24);
    box-shadow: var(--shadow-strong);
    padding: 18px 18px 112px;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

#side-menu.open {
    transform: translateX(0);
}

body.theme-light #side-menu {
    color: #17232d;
    background: linear-gradient(180deg, rgba(248, 251, 252, 0.98) 0%, rgba(229, 237, 242, 0.98) 100%);
    border-right-color: rgba(71, 116, 140, 0.16);
}

body.theme-sepia #side-menu {
    color: #4f3925;
    background: linear-gradient(180deg, rgba(246, 238, 221, 0.98) 0%, rgba(228, 212, 188, 0.98) 100%);
    border-right-color: rgba(141, 111, 80, 0.18);
}

.side-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.side-menu-header h2 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

#toc-list li {
    margin: 0;
}

#toc-list button {
    width: 100%;
    border: 0;
    border-radius: 10px;
    padding: 12px 12px 12px calc(12px + (var(--toc-depth, 0) * 14px));
    text-align: left;
    color: inherit;
    line-height: 1.35;
}

#toc-list button:hover,
#toc-list button:focus-visible {
    background: rgba(255, 255, 255, 0.08);
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#location-indicator {
    font-weight: 600;
}

#hud-hint {
    color: var(--text-muted);
    font-size: 0.92rem;
}

#dev-splash {
    position: fixed;
    inset: 0;
    z-index: 9999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    background:
        radial-gradient(circle at 20% 20%, rgba(122, 215, 242, 0.12), transparent 26%),
        radial-gradient(circle at 80% 30%, rgba(215, 187, 116, 0.12), transparent 24%),
        linear-gradient(180deg, #05080d 0%, #09111a 100%);
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.36s ease, transform 0.36s ease;
}

.dev-splash-inner {
    width: min(460px, 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
    transform: translateY(0);
    transition: transform 0.36s ease;
}

.splash-cover {
    width: min(240px, 54vw);
    border-radius: 16px;
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.45);
}

.splash-text-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.splash-kicker,
.splash-subtitle,
.splash-hint {
    margin: 0;
}

.splash-kicker {
    color: var(--accent-steel);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 0.8rem;
}

.splash-title {
    margin: 0;
    color: var(--accent-brass);
    font-size: clamp(2rem, 6vw, 3.2rem);
    line-height: 1;
}

.splash-subtitle {
    color: var(--text-main);
    font-size: 1rem;
}

.dev-logo-img {
    width: min(140px, 36vw);
    height: auto;
    display: block;
    filter: drop-shadow(0 8px 28px rgba(122, 215, 242, 0.22));
}

.splash-hint {
    color: var(--text-muted);
    font-size: 0.92rem;
}

#dev-splash.splash-hidden {
    opacity: 0;
    transform: scale(0.985);
    pointer-events: none;
}

body.splash-active .hud-element {
    visibility: hidden !important;
    pointer-events: none !important;
}

body.splash-active #viewer {
    filter: blur(2px) brightness(0.6);
}

body.is-fullscreen {
    cursor: none;
}

body.is-fullscreen .hud-element.visible,
body.is-fullscreen #side-menu.open {
    cursor: default;
}

.listen-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.listen-layout {
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    gap: 20px;
}

.player-panel,
.chapters-panel {
    border-radius: 24px;
    padding: 24px;
    box-sizing: border-box;
}

.player-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: sticky;
    top: 24px;
}

.player-label,
.current-chapter-title,
.audio-status,
.chapter-hint {
    margin: 0;
}

.player-label,
.chapter-hint {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.78rem;
}

.current-chapter-title {
    color: var(--accent-brass);
    font-size: 1.08rem;
    line-height: 1.5;
}

.audio-element {
    display: none;
}

.playback-cluster {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(122, 215, 242, 0.14);
}

.playback-buttons,
.audio-actions,
.time-row,
.speed-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.playback-buttons,
.audio-actions {
    flex-wrap: wrap;
}

.transport-button {
    min-width: 96px;
}

.transport-button.compact {
    min-width: 82px;
}

.progress-input {
    width: 100%;
    accent-color: var(--accent-steel);
}

.time-row {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.speed-row {
    justify-content: flex-start;
}

.speed-row label {
    color: var(--text-muted);
}

.speed-row select {
    padding-right: 28px;
}

.audio-status {
    min-height: 24px;
    color: var(--text-muted);
    line-height: 1.5;
}

.audio-status.error {
    color: #f2a39d;
}

.chapters-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.chapter-count {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.audio-chapter-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.audio-chapter-list li {
    margin: 0;
}

.chapter-button {
    width: 100%;
    border-radius: 16px;
    border: 1px solid rgba(122, 215, 242, 0.18);
    background: rgba(255, 255, 255, 0.02);
    padding: 14px 16px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    text-align: left;
}

.chapter-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chapter-index {
    color: var(--text-muted);
    font-size: 0.82rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.chapter-title {
    color: var(--text-main);
    line-height: 1.45;
}

.chapter-state {
    color: var(--accent-steel);
    font-size: 0.9rem;
    white-space: nowrap;
}

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

    .player-panel {
        position: relative;
        top: 0;
    }
}

@media (max-width: 900px) {
    .hud-element {
        min-height: 74px !important;
        padding: 0 12px;
        gap: 10px;
    }

    #hud-top {
        flex-wrap: wrap;
        justify-content: center;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .book-title {
        order: -1;
        width: 100%;
    }

    .hud-controls {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    #hud-bottom {
        justify-content: center;
        gap: 6px;
        flex-wrap: wrap;
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

@media (max-width: 720px) {
    .mode-shell,
    .listen-shell {
        width: min(100% - 20px, 1180px);
        padding-top: 20px;
        padding-bottom: 24px;
    }

    .hero-card,
    .player-panel,
    .chapters-panel {
        border-radius: 22px;
        padding: 18px;
    }

    .listen-header {
        flex-direction: column;
        align-items: stretch;
    }

    .listen-nav {
        display: flex;
        gap: 10px;
        flex-wrap: wrap;
    }

    .playback-buttons,
    .audio-actions {
        justify-content: stretch;
    }

    .transport-button {
        flex: 1 1 140px;
    }
}

@media (max-width: 640px) {
    button,
    .button-link,
    select {
        padding: 8px 10px;
        font-size: 0.92rem;
    }

    #theme-controls {
        gap: 6px;
    }

    #theme-controls button {
        padding-inline: 9px;
    }

    #hud-hint,
    .chapter-count,
    .time-row {
        font-size: 0.84rem;
    }

    .splash-cover {
        width: min(220px, 64vw);
    }

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

@media (prefers-reduced-motion: reduce) {
    #dev-splash,
    .dev-splash-inner,
    .hud-element,
    #side-menu,
    button,
    .button-link,
    select {
        transition: none !important;
    }
}
