:root {
    --bg: #070b12;
    --panel: rgba(12, 20, 34, 0.78);
    --ink: #e8f1ff;
    --muted: #8ea0b8;
    --line: rgba(140, 196, 255, 0.16);
    --accent: #67e8f9;
    --accent-ink: #04222a;
    --paper: #f4f8ff;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
    color-scheme: dark;
    font-family: Bahnschrift, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
body {
    background-color: var(--bg);
    background-image:
        linear-gradient(rgba(103, 232, 249, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(103, 232, 249, 0.045) 1px, transparent 1px),
        radial-gradient(880px 420px at 100% -8%, rgba(56, 189, 248, 0.18), transparent 55%),
        radial-gradient(720px 380px at -10% 0%, rgba(99, 102, 241, 0.16), transparent 50%);
    background-size: 56px 56px, 56px 56px, auto, auto;
    background-attachment: fixed;
    color: var(--ink);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.top {
    display: flex;
    gap: 24px;
    align-items: center;
    justify-content: space-between;
    padding: 22px 32px 14px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background:
        linear-gradient(135deg, transparent 46%, var(--accent) 46% 54%, transparent 54%),
        linear-gradient(180deg, rgba(103, 232, 249, 0.2), rgba(99, 102, 241, 0.05));
    box-shadow: inset 0 0 0 6px rgba(7, 11, 18, 0.55), 0 0 24px rgba(103, 232, 249, 0.25);
}
.eyebrow {
    margin: 0 0 2px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    font-size: 11px;
    color: var(--accent);
}
h1 {
    margin: 0;
    font-weight: 560;
    font-size: 34px;
    letter-spacing: -0.04em;
}
.top-actions { display: flex; gap: 12px; align-items: center; width: min(520px, 100%); }
.search { width: min(420px, 100%); flex: 1; }
.exit {
    color: var(--ink);
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 14px;
    white-space: nowrap;
    background: rgba(8, 14, 24, 0.55);
}
.exit:hover { border-color: var(--accent); }
.who {
    color: var(--accent);
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.gate-link {
    color: var(--accent);
    text-align: center;
    text-decoration: none;
}
.gate-link:hover { text-decoration: underline; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
    width: min(420px, 100%);
    display: grid;
    gap: 14px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px);
}
.gate-card h1 { font-size: 34px; }
.gate-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; letter-spacing: 0.04em; }
.lang-pick {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    display: grid;
    gap: 8px;
}
.lang-pick legend { padding: 0 4px; color: var(--muted); font-size: 13px; }
.lang-pick label { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.lang-pick input { width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); }
.gate-card input, .search input, .pager input[type="number"] { font-size: 16px; }
.gate-card input {
    border: 1px solid var(--line);
    background: rgba(4, 8, 16, 0.72);
    border-radius: 12px;
    padding: 12px 14px;
}
.gate-card input:focus, .search input:focus, .pager input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(103, 232, 249, 0.16);
}
.gate-card button, .resume button {
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    background: linear-gradient(180deg, #9af4ff, var(--accent));
    color: var(--accent-ink);
    font-weight: 650;
    min-height: 44px;
}
.search input {
    width: 100%;
    border: 1px solid var(--line);
    background: rgba(8, 14, 24, 0.72);
    border-radius: 12px;
    padding: 12px 16px;
    outline: none;
}

.shelves {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 32px 18px;
    scrollbar-width: none;
}
.shelves::-webkit-scrollbar { display: none; }
.chip {
    border: 1px solid var(--line);
    background: rgba(8, 14, 24, 0.45);
    border-radius: 999px;
    padding: 8px 14px;
    white-space: nowrap;
    color: var(--muted);
    letter-spacing: 0.02em;
}
.chip.active {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
    box-shadow: 0 0 18px rgba(103, 232, 249, 0.28);
}

.library { padding: 4px 32px 48px; }
.shelf { margin: 0 0 36px; }
.shelf h2, .series h3 { font-weight: 560; letter-spacing: -0.03em; }
.shelf h2 {
    margin: 0 0 16px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.shelf h2::after {
    content: "";
    height: 1px;
    flex: 1;
    background: linear-gradient(90deg, var(--line), transparent);
}
.series { margin: 0 0 22px; }
.series h3 { margin: 0 0 12px; color: var(--muted); font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
    gap: 18px 14px;
}
.book {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    text-align: left;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.cover {
    position: relative;
    aspect-ratio: 2 / 3;
    border-radius: 10px;
    overflow: hidden;
    background:
        linear-gradient(160deg, hsl(var(--h) 42% 28%), hsl(calc(var(--h) + 36) 36% 12%));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.cover canvas, .cover img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center center;
    background: rgba(4, 8, 16, 0.35);
}
.glyph {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 48px;
    color: rgba(232, 241, 255, 0.9);
}
.ribbon {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border-radius: 999px;
    background: rgba(4, 10, 18, 0.82);
    color: var(--accent);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-align: center;
    padding: 4px 6px;
    border: 1px solid rgba(103, 232, 249, 0.35);
}
.book strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.3;
}
.book em {
    display: block;
    color: var(--muted);
    font-style: normal;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
@media (hover: hover) {
    .book:hover {
        border-color: rgba(103, 232, 249, 0.55);
        transform: translateY(-3px);
    }
}
.book { transition: transform 0.18s ease, border-color 0.18s ease; }
.resume {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 16px;
    align-items: center;
    width: min(760px, 100%);
    margin: 0 0 28px;
    padding: 18px;
    border: 1px solid rgba(103, 232, 249, 0.35);
    border-radius: 18px;
    background:
        linear-gradient(120deg, rgba(103, 232, 249, 0.12), transparent 42%),
        var(--panel);
    box-shadow: 0 0 32px rgba(103, 232, 249, 0.08);
}
.resume .eyebrow { grid-column: 1 / -1; }
.resume strong { grid-column: 1; font-size: 24px; font-weight: 560; letter-spacing: -0.03em; line-height: 1.2; }
.resume span { grid-column: 1; color: var(--muted); font-size: 14px; }
.resume button { grid-column: 2; grid-row: 2 / span 2; align-self: center; }
.status { color: var(--muted); }

.foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 0 32px 28px;
    padding: 12px 0 0;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.reader, .photo {
    position: fixed;
    inset: 0;
    z-index: 5;
    background: #05080e;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.reader[hidden], .photo[hidden] { display: none; }
.reader-bar, .reader-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(8, 14, 24, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}
.reader-nav { border-bottom: 0; border-top: 1px solid var(--line); }
.reader-title { flex: 1; min-width: 0; }
.reader-title strong, .reader-title span {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reader-title span { color: var(--muted); font-size: 13px; }
.reader-tools, .pager { display: flex; align-items: center; gap: 8px; }
.text-btn, .reader-tools button, .reader-nav > button {
    border: 1px solid var(--line);
    background: rgba(8, 14, 24, 0.7);
    border-radius: 12px;
    padding: 8px 12px;
}
.stage {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: grid;
    justify-content: center;
    align-content: start;
    padding: 24px 16px 40px;
    cursor: pointer;
}
.stage canvas {
    background: white;
    box-shadow: var(--shadow);
    border-radius: 2px;
}
.stage.is-epub { display: block; padding: 0; }
.epub-view { width: 100%; height: 100%; background: #f7f4ee; }
.reader.mode-epub .pager,
.reader.mode-epub #slider { display: none; }
.pager input[type="number"] {
    width: 72px;
    background: rgba(4, 8, 16, 0.72);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 8px;
    text-align: center;
}
#slider { flex: 1; accent-color: var(--accent); }
.photo { align-items: center; justify-content: center; gap: 16px; padding: 24px; }
.photo img { max-width: min(1100px, 100%); max-height: calc(100dvh - 100px); object-fit: contain; }
.photo .text-btn { position: absolute; top: 16px; left: 16px; }

@media (max-width: 720px) {
    .top, .library, .shelves { padding-left: 16px; padding-right: 16px; }
    .foot { margin-left: 16px; margin-right: 16px; }
    .top {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding-top: max(20px, env(safe-area-inset-top));
    }
    h1 { font-size: 30px; }
    .top-actions, .search { width: 100%; }
    .chip, .exit, .text-btn, .reader-tools button, .reader-nav > button { min-height: 44px; }
    .shelves {
        position: sticky;
        top: 0;
        z-index: 2;
        background: rgba(7, 11, 18, 0.9);
        backdrop-filter: blur(12px);
        padding-top: 10px;
        padding-bottom: 10px;
    }
    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
    .book { padding: 8px; }
    .resume { grid-template-columns: 1fr; gap: 6px; }
    .resume strong, .resume span, .resume button { grid-column: 1; grid-row: auto; }
    .resume button { width: 100%; }
    .reader-bar, .reader-nav { flex-wrap: wrap; }
    .reader-bar { padding-top: max(10px, env(safe-area-inset-top)); }
    .reader-tools { margin-left: auto; }
    .reader-nav {
        display: grid;
        grid-template-columns: 52px minmax(0, 1fr) 52px;
        grid-template-areas:
            "prev pager next"
            "slider slider slider";
        gap: 8px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    #prev { grid-area: prev; }
    .pager { grid-area: pager; justify-content: center; }
    #next { grid-area: next; }
    #slider { grid-area: slider; width: 100%; height: 32px; }
    #prev-book, #next-book { display: none; }
    .stage { padding: 12px 10px 20px; }
    .foot { flex-direction: column; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
