:root {
    --bg: #f5f2ea;
    --surface: #fffdf8;
    --surface-2: #eef5f1;
    --ink: #182322;
    --muted: #66716f;
    --line: #d9ded6;
    --primary: #087e8b;
    --primary-strong: #05606a;
    --accent: #cc5a37;
    --danger: #b42318;
    --success: #12715b;
    --shadow: 0 20px 50px rgba(24, 35, 34, 0.12);
    --radius: 8px;
}

* {
    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;
    line-height: 1.5;
}

a {
    color: var(--primary-strong);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
textarea,
select {
    font: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px clamp(16px, 4vw, 44px);
    border-bottom: 1px solid rgba(24, 35, 34, 0.08);
    background: rgba(255, 253, 248, 0.92);
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-weight: 800;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 7px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

.topnav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 14px;
}

.nav-button,
.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 1px 0 rgba(24, 35, 34, 0.04);
    cursor: pointer;
    text-decoration: none;
}

.button:hover,
.nav-button:hover {
    border-color: #b7c7c3;
    text-decoration: none;
}

.button.primary {
    border-color: var(--primary);
    color: #fff;
    background: var(--primary);
}

.button.primary:hover {
    background: var(--primary-strong);
}

.button.danger {
    border-color: #f3c3bd;
    color: var(--danger);
    background: #fff5f3;
}

.button.small {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 13px;
}

.button.block {
    width: 100%;
}

.main {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 56px;
}

.footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 38px;
    color: var(--muted);
    font-size: 13px;
    border-top: 1px solid var(--line);
}

.hero-surface {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 22px;
    padding: clamp(24px, 5vw, 44px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(120deg, rgba(8, 126, 139, 0.12), rgba(204, 90, 55, 0.10)),
        var(--surface);
    box-shadow: var(--shadow);
}

.hero-surface h1,
.page-title h1,
.reader-head h1 {
    max-width: 820px;
    margin: 0;
    font-size: clamp(30px, 6vw, 58px);
    line-height: 1.02;
}

.hero-surface p {
    max-width: 680px;
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 17px;
}

.hero-actions,
.title-actions,
.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

.center {
    text-align: center;
}

.section-head,
.page-title,
.reader-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin: 34px 0 18px;
}

.page-title h1,
.reader-head h1 {
    font-size: clamp(28px, 5vw, 46px);
}

.page-title p,
.reader-head p,
.section-head p {
    margin: 8px 0 0;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}

.book-card,
.panel,
.auth-card,
.install-card,
.empty-state,
.stat-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(24, 35, 34, 0.08);
}

.book-card {
    overflow: hidden;
}

.book-cover {
    display: grid;
    height: 170px;
    place-items: center;
    color: #fff;
    background:
        linear-gradient(145deg, rgba(8, 126, 139, 0.88), rgba(204, 90, 55, 0.82)),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px 12px);
}

.book-cover span {
    display: grid;
    width: 76px;
    height: 96px;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.72);
    border-radius: 6px;
    font-size: 44px;
    font-weight: 900;
}

.book-card-body {
    padding: 18px;
}

.book-card h3,
.panel h2,
.auth-card h1,
.install-card h1,
.empty-state h3 {
    margin: 0;
}

.book-card p {
    min-height: 48px;
    color: var(--muted);
}

.meta-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 12px 0 16px;
    color: var(--muted);
    font-size: 13px;
}

.meta-row span,
.pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--surface-2);
}

.flash-wrap {
    position: fixed;
    top: 74px;
    right: 20px;
    z-index: 80;
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 40px));
}

.flash,
.alert {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.flash-success {
    border-color: #bde2d4;
    color: var(--success);
}

.flash-danger,
.alert-danger {
    border-color: #f0b7ae;
    color: var(--danger);
}

.flash-warning {
    border-color: #ead18d;
    color: #806100;
}

.panel {
    padding: 22px;
}

.panel.tight {
    padding: 18px;
}

.panel.narrow,
.auth-card {
    max-width: 620px;
    margin-inline: auto;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.form-grid {
    display: grid;
    gap: 16px;
}

.form-grid label {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-weight: 700;
}

.form-grid label span,
.inline-form {
    font-size: 14px;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid #cbd5d1;
    border-radius: var(--radius);
    padding: 10px 12px;
    color: var(--ink);
    background: #fff;
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: 3px solid rgba(8, 126, 139, 0.18);
    border-color: var(--primary);
}

.check-row {
    display: flex !important;
    grid-template-columns: auto 1fr;
    align-items: center;
    flex-direction: row;
}

.check-row input {
    width: auto;
}

hr {
    width: 100%;
    border: 0;
    border-top: 1px solid var(--line);
}

.auth-page .main {
    display: grid;
    min-height: 68vh;
    place-items: center;
}

.auth-card,
.install-card {
    width: min(100%, 560px);
    padding: clamp(22px, 5vw, 34px);
}

.install-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.install-panel {
    width: min(100%, 720px);
}

.code-area {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    padding: 18px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 32px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

td small {
    display: block;
    color: var(--muted);
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.inline-form select {
    width: auto;
    min-width: 100px;
}

.empty-state {
    padding: 34px;
    text-align: center;
}

.empty-state.compact {
    padding: 24px;
}

.danger-zone {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid #f0c0ba;
}

.analytics-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.75fr);
    gap: 18px;
}

.bar-chart {
    display: flex;
    align-items: end;
    gap: 10px;
    min-height: 220px;
    padding-top: 20px;
}

.bar-item {
    display: grid;
    flex: 1;
    min-width: 32px;
    gap: 6px;
    text-align: center;
    color: var(--muted);
}

.bar {
    display: block;
    min-height: 8px;
    border-radius: 5px 5px 0 0;
    background: linear-gradient(180deg, var(--primary), var(--accent));
}

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

.editor-sidebar {
    display: grid;
    gap: 16px;
}

.media-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.media-list li {
    display: grid;
    gap: 2px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.editor-main,
.reader-main {
    min-width: 0;
}

.reader-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.icon-button {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.icon-button:hover {
    border-color: var(--primary);
}

.page-jump {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.page-jump input {
    width: 76px;
    text-align: center;
}

.toolbar-note {
    color: var(--muted);
    font-size: 13px;
}

.editor-stage,
.reader-shell {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #e8ece7;
}

.editor-stage {
    position: relative;
    min-height: 620px;
    padding: 16px;
    overflow: auto;
}

.editor-canvas {
    display: grid;
    place-items: start center;
}

.document-page,
.book-page {
    position: relative;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 14px 36px rgba(24, 35, 34, 0.18);
}

.document-page canvas,
.book-page canvas {
    display: block;
}

.editor-layer,
.page-media-layer {
    position: absolute;
    inset: 0;
}

.editor-hotspot {
    position: absolute;
    display: flex;
    min-width: 48px;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--primary);
    border-radius: 7px;
    background: rgba(8, 126, 139, 0.14);
    cursor: move;
    user-select: none;
}

.editor-image {
    border-color: var(--accent);
    background: rgba(204, 90, 55, 0.12);
}

.editor-audio {
    border-color: #536dfe;
    background: rgba(83, 109, 254, 0.12);
}

.hotspot-label {
    display: flex;
    align-items: center;
    gap: 7px;
    max-width: 100%;
    padding: 6px 8px;
    overflow: hidden;
    color: var(--ink);
    font-size: 12px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hotspot-delete {
    position: absolute;
    top: -12px;
    right: -12px;
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 0;
    border-radius: 999px;
    color: #fff;
    background: var(--danger);
    cursor: pointer;
}

.resize-handle {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 4px;
    background: var(--primary);
    cursor: nwse-resize;
}

.loading-state {
    display: grid;
    min-height: 180px;
    place-items: center;
    color: var(--muted);
}

.loading-state.error {
    color: var(--danger);
}

.reader-shell {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 16px;
    padding: 16px;
}

.page-sidebar {
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 253, 248, 0.75);
}

.page-sidebar h2 {
    margin: 0 0 12px;
    font-size: 16px;
}

.page-nav-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-height: 68vh;
    overflow: auto;
}

.page-nav-list button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
}

.page-nav-list button.active {
    border-color: var(--primary);
    color: #fff;
    background: var(--primary);
}

.flipbook {
    width: 100%;
    min-height: 560px;
}

.flipbook-fallback {
    display: grid;
    justify-content: center;
    gap: 18px;
}

.media-hotspot {
    position: absolute;
    display: grid;
    min-width: 44px;
    min-height: 36px;
    place-items: center;
    overflow: hidden;
    border: 2px solid rgba(8, 126, 139, 0.72);
    border-radius: 7px;
    color: #fff;
    background: rgba(8, 126, 139, 0.74);
    cursor: pointer;
    padding: 0;
    text-align: center;
}

.media-hotspot:hover {
    filter: brightness(1.05);
}

.media-hotspot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-hotspot span:not(.media-icon) {
    position: absolute;
    right: 4px;
    bottom: 4px;
    left: 4px;
    padding: 3px 5px;
    overflow: hidden;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.52);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-icon {
    font-size: clamp(20px, 4vw, 42px);
}

.media-image {
    border-color: rgba(204, 90, 55, 0.78);
}

.media-audio {
    border-color: rgba(83, 109, 254, 0.75);
    background: rgba(83, 109, 254, 0.78);
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 17, 18, 0.62);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(880px, 100%);
    max-height: min(88vh, 820px);
    overflow: auto;
    padding: 20px;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    cursor: pointer;
}

.video-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
}

.video-frame iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.modal-image {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    margin: 0 auto;
}

.modal audio {
    width: 100%;
}

@media (max-width: 900px) {
    .hero-surface,
    .section-head,
    .page-title,
    .reader-head,
    .editor-layout,
    .reader-shell,
    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .section-head,
    .page-title,
    .reader-head {
        align-items: start;
    }

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

    .page-sidebar {
        order: 2;
    }

    .page-nav-list {
        grid-template-columns: repeat(8, 1fr);
        max-height: none;
    }
}

@media (max-width: 620px) {
    .topbar {
        align-items: start;
        flex-direction: column;
    }

    .topnav {
        justify-content: flex-start;
    }

    .main {
        width: min(100% - 20px, 1180px);
        padding-top: 20px;
    }

    .hero-surface {
        padding: 22px;
    }

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

    .panel,
    .auth-card,
    .install-card {
        padding: 18px;
    }

    .editor-stage,
    .reader-shell {
        padding: 10px;
    }

    .page-nav-list {
        grid-template-columns: repeat(5, 1fr);
    }

    .footer {
        width: min(100% - 20px, 1180px);
    }
}
