:root {
    color-scheme: light;
    --ink: #212952;
    --muted: #828282;
    --paper: #ffffff;
    --card: #ffffff;
    --line: #e5e7eb;
    --accent: #e4572e;
    --forest: #212952;
    --ok: #1f7a4a;
    --ok-bg: #e8f6ee;
    --err: #dc2626;
    --err-bg: #fde8e4;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body.site {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    color: #4b5563;
    font-family: Roboto, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.6;
}

h1, h2, .brand, .issue strong {
    font-family: Roboto, "Segoe UI", sans-serif;
    font-weight: 700;
    letter-spacing: 0;
    color: var(--ink);
}

h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.2; margin: 0; }
h2 { font-size: 1.35rem; margin: 0; color: var(--ink); }

a { color: inherit; }
button, input { font: inherit; color: inherit; }
button, a { touch-action: manipulation; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.top {
    width: 100%;
    min-height: 76px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 5;
}

.top-inner {
    width: min(1100px, 100%);
    height: 100%;
    margin: 0 auto;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    line-height: 0;
    text-decoration: none;
    background: #5a6e7c;
    border-radius: 6px;
    padding: 8px 12px;
}

.logo {
    height: 96px;
    width: auto;
    max-width: min(360px, 64vw);
    display: block;
    object-fit: contain;
}

.home-link {
    text-decoration: none;
    white-space: nowrap;
}

.wrap {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: 28px 18px 64px;
    flex: 1;
}

.site-foot {
    background: #232323;
    color: rgba(255, 255, 255, 0.78);
    text-align: center;
    padding: 22px 16px;
    font-size: 0.92rem;
}
.site-foot p { margin: 0; }

.mast {
    margin: 8px auto 28px;
    max-width: 720px;
    text-align: center;
    padding-bottom: 18px;
    border-bottom: 1px solid #e6e8ee;
}
.mast .note { margin-top: 12px; }
.eyebrow {
    margin: 0 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
}
.lede { margin: 10px 0 0; color: var(--muted); font-size: 1.05rem; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
    gap: 18px;
}

.issue {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    background: #ffffff;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid #eef0f4;
    box-shadow: 0 12px 30px rgba(33, 41, 82, 0.08);
    min-width: 0;
}

@media (hover: hover) {
    .issue { transition: transform 0.18s ease; }
    .issue:hover { transform: translateY(-3px); }
}

.issue-meta { display: grid; gap: 4px; padding: 14px 14px 16px; }
.issue strong { font-size: 1.35rem; }
.issue em { font-style: normal; font-weight: 600; color: var(--accent); }
.kicker, .meta, .note {
    color: var(--muted);
    font-size: 0.85rem;
}
.note { margin: 0; }
.meta { margin: 4px 0 10px; }

.cover-frame {
    position: relative;
    display: block;
    aspect-ratio: 3 / 4;
    background: linear-gradient(165deg, #1f7a4a, #212952 72%);
    overflow: hidden;
}

.cover-frame canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.cover-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.16), transparent 80%);
    transform: translateX(-70%);
    animation: shine 1.35s ease-in-out infinite;
    pointer-events: none;
}

.cover-frame.ready::after { display: none; }

@keyframes shine {
    to { transform: translateX(70%); }
}

.empty, .panel, .manage {
    background: #ffffff;
    border-radius: 18px;
    border: 1px solid #eef0f4;
    box-shadow: 0 12px 30px rgba(33, 41, 82, 0.06);
}

.empty { padding: 22px; display: grid; gap: 14px; justify-items: start; }
.empty p { margin: 0; }

.panel { padding: 18px; margin-bottom: 18px; }
.stack { display: grid; gap: 12px; }
.list { display: grid; gap: 14px; }

.lbl { display: grid; gap: 6px; font-weight: 600; }

.stack input[type="text"],
.stack input[type="password"],
.inline input[type="text"],
.linkline input {
    min-height: 48px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    color: #212952;
    padding: 0 12px;
}

.stack input[type="text"],
.stack input[type="password"] { width: 100%; }

.drop {
    position: relative;
    display: grid;
    gap: 4px;
    place-items: center;
    text-align: center;
    min-height: 128px;
    padding: 18px;
    border: 1.5px dashed #d3c3ae;
    border-radius: 16px;
    background: #faf6ef;
    cursor: pointer;
}

.drop.hot { border-color: var(--accent); background: #fff1e8; }
.drop input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.drop-title { font-weight: 650; }
.drop-sub { color: var(--muted); }

.btn {
    appearance: none;
    border: 0;
    background: var(--ink);
    color: #ffffff;
    border-radius: 8px;
    min-height: 46px;
    padding: 0 18px;
    font-weight: 600;
    text-decoration: none;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    width: fit-content;
}

.btn.ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid #e5e7eb;
}

.btn.danger {
    background: transparent;
    color: var(--err);
    border: 1px solid #efcfc8;
}

.btn.danger.armed {
    background: #8d2f22;
    color: #fffaf3;
    border-color: #8d2f22;
}

.manage {
    display: flex;
    gap: 16px;
    padding: 16px;
}

.admin-frame { width: 96px; flex: none; }
.manage-body { min-width: 0; flex: 1; display: grid; gap: 10px; align-content: start; }

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

.linkline input, .inline input[type="text"] {
    flex: 1 1 200px;
    min-width: 0;
    width: auto;
}

.inline input[type="file"] { max-width: 100%; }

.flash {
    padding: 12px 14px;
    border-radius: 12px;
    margin: 0 0 14px;
}
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }

body.auth main {
    min-height: calc(100dvh - 70px);
    display: grid;
    align-content: center;
}
.auth-card { width: min(440px, 100%); }
.auth-card h1 { font-size: 2.4rem; }
code { font-size: 0.92em; }

@media (max-width: 560px) {
    .manage { flex-direction: column; }
    .admin-frame { width: min(180px, 48vw); }
}

@media (prefers-reduced-motion: reduce) {
    .cover-frame::after { animation: none; }
    .issue { transition: none; }
}

body.room {
    color-scheme: light;
    margin: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #f4f6f8;
    color: #212952;
    font-family: Roboto, "Segoe UI", sans-serif;
}

body.room :focus-visible { outline-color: #212952; }

.readbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}

body.room .logo { height: 64px; }

.read-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (max-width: 720px) {
    .readbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .readbar h1 { display: none; }
    body.room .logo { height: 48px; }
    .home-link { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }
}

.readbar h1 {
    margin: 0;
    font-size: 1.05rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#count {
    font-variant-numeric: tabular-nums;
    color: #212952;
    font-weight: 700;
    min-width: 4.5rem;
    text-align: right;
}

#sound {
    appearance: none;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    color: #212952;
    border-radius: 8px;
    min-height: 36px;
    padding: 0 12px;
    font-weight: 700;
    cursor: pointer;
}

.stage {
    flex: 1;
    min-height: 0;
    display: flex;
    padding: 0 6px calc(8px + env(safe-area-inset-bottom));
}

#book {
    flex: 1;
    min-width: 0;
    min-height: 0;
    --fb-bg: transparent;
    --fb-paper: #fbf6ee;
    --fb-control-bg: rgba(33, 41, 82, 0.9);
    --fb-control-fg: #ffffff;
    --fb-counter-fg: #ffffff;
    --fb-shadow: 0 28px 48px rgba(0, 0, 0, 0.48), 0 10px 16px rgba(0, 0, 0, 0.32);
    --fb-fold-shadow: drop-shadow(0 16px 14px rgba(0, 0, 0, 0.42));
}

#book .fb-book {
    box-shadow:
        5px 0 0 #f4ecdf,
        6px 0 0 #e6d9c4,
        7px 0 0 #d8c9b0,
        8px 0 0 #cbbda3;
}

#book .fb-face {
    background: #fbf6ee;
}

#book .fb-face::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.11;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.hint {
    margin: 0;
    padding: 8px 16px 0;
    text-align: center;
    color: #828282;
    font-size: 0.85rem;
    background: #f4f6f8;
}

.hint[hidden] { display: none; }

#loading {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #ffffff;
    color: #212952;
}

body.ready #loading { display: none; }

.loading-card { width: min(440px, 100%); }
.loading-card h1 { font-size: clamp(1.8rem, 6vw, 2.8rem); margin-bottom: 16px; }
.track {
    height: 4px;
    background: #e5e7eb;
    border-radius: 99px;
    overflow: hidden;
}
#bar {
    display: block;
    height: 100%;
    width: 0;
    background: #e4572e;
}
#load-status { color: #828282; }
.quiet { color: #e4572e; font-weight: 700; }

body.room .flash {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 50;
}
