*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Layout: brand-blue masthead band, latest publication featured large, archive grid below; the reader is a full-screen navy stage with the book centered. */
:root {
  --bg: #f3f6fa; --surface: #ffffff; --ink: #10233f; --muted: #556781; --line: #d8e1ec;
  --brand: #175298; --brand-ink: #ffffff; --sky: #2f8fcc; --sky-soft: #e3f0fa;
  --stage: #0d1f38; --stage-ink: #e8eef7; --stage-muted: #9fb2cb; --stage-btn: #1b3456;
  --danger: #b42318; --danger-soft: #fdecea; --ok: #1d7a46;
  --display: "Montserrat", "Avenir Next", "Segoe UI", Arial, sans-serif;
  --body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(16,35,63,.06), 0 8px 24px rgba(16,35,63,.08);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0a1525; --surface: #11213a; --ink: #e6eef8; --muted: #9db0c8; --line: #233a5c;
  --brand: #134a8c; --brand-ink: #ffffff; --sky: #5cb3e6; --sky-soft: #15314f;
  --stage: #060e1a; --stage-ink: #e8eef7; --stage-muted: #8fa3bd; --stage-btn: #15294a;
  --danger: #f08a80; --danger-soft: #3a1a1a; --ok: #5fcf8f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #0a1525; --surface: #11213a; --ink: #e6eef8; --muted: #9db0c8; --line: #233a5c;
  --brand: #134a8c; --brand-ink: #ffffff; --sky: #5cb3e6; --sky-soft: #15314f;
  --stage: #060e1a; --stage-ink: #e8eef7; --stage-muted: #8fa3bd; --stage-btn: #15294a;
  --danger: #f08a80; --danger-soft: #3a1a1a; --ok: #5fcf8f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 17px; line-height: 1.5; }
.wrap { max-width: 1120px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
button, .btn { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

/* Masthead */
.mast { background: var(--brand); color: var(--brand-ink); }
.mast .wrap { padding-block: 28px 36px; display: flex; flex-direction: column; gap: 20px; }
.mast img.logo { width: 190px; height: auto; display: block; }
.mast h1 { font-size: clamp(28px, 4.5vw, 44px); font-weight: 800; text-transform: uppercase; letter-spacing: 0.01em; line-height: 1.05; }
.mast p { margin: 6px 0 0; max-width: 60ch; opacity: .88; }
.eyebrow { font-family: var(--display); font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.mast .eyebrow { color: #9fd3f2; }

main.wrap { padding-block: 32px 64px; display: flex; flex-direction: column; gap: 40px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; padding: 10px 18px; font-weight: 700; font-size: 15px; text-decoration: none; border: 1.5px solid transparent; line-height: 1.2; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.12); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--sky); color: var(--sky); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* Featured */
.featured { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 36px; align-items: center; }
.cover { display: block; width: 100%; aspect-ratio: 612 / 792; max-width: 100%; object-fit: cover; background: var(--line); border-radius: 3px; box-shadow: var(--shadow); }
.cover-btn { padding: 0; border: 0; background: none; display: block; width: 100%; border-radius: 3px; transition: transform .2s ease; }
.cover-btn:hover { transform: translateY(-3px); }
.featured .info { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.featured .eyebrow { color: var(--sky); }
.featured h2 { font-size: clamp(26px, 3.4vw, 38px); font-weight: 800; line-height: 1.1; }
.featured p.sub { margin: 0; color: var(--muted); max-width: 55ch; }
.meta { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Archive */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--brand); padding-bottom: 8px; margin-bottom: 20px; }
.section-head h2 { font-size: 18px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 28px 24px; }
.card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card h3 { font-size: 16px; font-weight: 700; line-height: 1.25; }
.card .row { display: flex; gap: 12px; font-size: 14px; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; color: var(--sky); font-weight: 700; text-decoration: none; font-size: 14px; }
.link:hover { text-decoration: underline; }

/* Admin */
.admin { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.admin h2 { font-size: 20px; font-weight: 700; }
.admin .note { margin: 0; color: var(--muted); font-size: 15px; max-width: 70ch; }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: 28px 16px; text-align: center; color: var(--muted); background: var(--bg); transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--sky); background: var(--sky-soft); }
.drop strong { color: var(--ink); }
.drop .file-name { color: var(--ink); font-weight: 600; word-break: break-word; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.field input { font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 6px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); min-width: 0; }
.field input:focus { border-color: var(--sky); outline: none; }
.status { font-size: 15px; display: flex; flex-direction: column; gap: 8px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--sky); transition: width .2s; }
.err { color: var(--danger); font-weight: 600; }
.admin-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.slug { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; color: var(--ink); word-break: break-all; }
.confirm { background: var(--danger-soft); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.empty h2 { color: var(--ink); font-size: 22px; margin-bottom: 6px; }
footer.wrap { padding-block: 0 40px; color: var(--muted); font-size: 13px; }

/* Reader */
.reader { position: fixed; inset: 0; z-index: 20; background: var(--stage); color: var(--stage-ink); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
.rbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px; }
.rbar .title { flex: 1; min-width: 0; font-family: var(--display); font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbtn { background: var(--stage-btn); color: var(--stage-ink); border: 0; border-radius: 6px; padding: 9px 14px; display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; text-decoration: none; }
.rbtn:hover { background: var(--brand); }
.rbtn svg { width: 18px; height: 18px; flex: none; }
.rbtn.icon { padding: 9px; }
.rbtn.dl { background: var(--brand); }
.rbtn.dl:hover { filter: brightness(1.15); }
.stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 8px 16px; }
.book-host { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.book-host > .book { margin: 0 auto; }
.page { background: #fff; overflow: hidden; }
.page img { width: 100%; height: 100%; display: block; object-fit: contain; }
.page .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #8a9ab0; font-family: var(--display); font-size: 13px; background: #f4f6f9; }
.rfoot { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 10px 16px 14px; }
.counter { font-variant-numeric: tabular-nums; color: var(--stage-muted); font-size: 14px; min-width: 120px; text-align: center; }
.loading { color: var(--stage-muted); text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; max-width: 320px; }
.loading .bar { width: 220px; background: var(--stage-btn); }
.hint { font-size: 12px; color: var(--stage-muted); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: 14px; z-index: 40; max-width: calc(100% - 32px); }

@media (max-width: 720px) {
  .featured { grid-template-columns: 1fr; gap: 20px; }
  .featured .cover-btn { max-width: 240px; }
  .fields { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 16px; }
  .rbar .lbl { display: none; }
  .mast img.logo { width: 150px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Share + admin page extras */
.share-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.login { max-width: 420px; margin: 64px auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.list { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.item { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 14px 16px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item img { width: 64px; aspect-ratio: 612 / 792; object-fit: cover; border-radius: 2px; background: var(--line); }
.item h3 { font-size: 16px; }
.item .actions { justify-content: flex-end; }
.item .edit { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 720px) { .item { grid-template-columns: 48px minmax(0, 1fr); } .item img { width: 48px; } .item > .actions { grid-column: 1 / -1; justify-content: flex-start; } }
.qr-wrap { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.qr-preview { width: 180px; max-width: 100%; flex: none; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.qr-preview svg { display: block; width: 100%; height: auto; }
.qr-wrap > .status { flex: 1; min-width: 220px; }
.updated { color: var(--ok); font-weight: 600; }
.qr-panel .actions, .item .edit .actions { justify-content: flex-start; }
.user-item { grid-template-columns: 40px minmax(0, 1fr) auto; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--sky-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 800; }
.select { font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 6px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.log-scroll { max-height: 420px; overflow: auto; }
.log-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.log-table th { position: sticky; top: 0; background: var(--surface); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); }
.log-table td { padding: 9px 16px; border-top: 1px solid var(--line); vertical-align: top; }
.log-table td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
@media (max-width: 720px) { .user-item { grid-template-columns: 40px minmax(0, 1fr); } .user-item > .actions { grid-column: 1 / -1; justify-content: flex-start; } }
