/* ==========================================================
   PROJECT NAVIE READING SITE · Midnight Blue Theme
   Colours, fonts and spacing come from tokens.css.
   The admin Design page can change --accent, --story-blue,
   --story-red and --bg-main (core.js writes them into the page).

   Sections:
     1. Theme (dark + light)     7. Reactions + game banner
     2. Base                     8. Comments
     3. Top bar                  9. Footer + phone bar
     4. Chapter banner          10. Chapter list (drawer)
     5. Chapter text            11. Sign in / account
     6. Chapter navigation      12. Lightbox, toast, print
                                13. Phones
   ========================================================== */

/* ---------- 1. Theme ---------- */

:root {
  --accent: var(--blue);
  --accent-glow: var(--blue-glow);
  --accent-hover: #4F7FE6;
  --story-blue: var(--blue);
  --story-red: var(--spark);
  --bg-main: var(--bg);
  --story-size: 17px;
  --read: 720px;                 /* reading column: 672 px text + padding */
  --topbar-bg: rgba(8, 11, 20, .82);
  --terminal-bg: #050810;
}

/* Light theme: the same roles, light values */
[data-theme="light"] {
  --bg: #F4F6FA;
  --bg2: #EBEFF6;
  --card: #FFFFFF;
  --raised: #EEF2F8;
  --line: #D8DEE9;
  --field: #7A8499;
  --text: #0E1424;
  --body: #2E3A50;
  --muted: #5A6680;
  --accent: #2F5FD0;
  --accent-glow: rgba(47, 95, 208, .15);
  --story-red: #D32F3A;
  --topbar-bg: rgba(244, 246, 250, .86);
  --terminal-bg: #0C1220;
}

/* Korean: Inter and Outfit have no Hangul, so Noto Sans KR fills in.
   For another language that needs its own font, add a block like this
   one with that language code, e.g. :lang(ja) and Noto Sans JP. */
:root:lang(ko) {
  --font-body: 'Inter', 'Noto Sans KR', system-ui, sans-serif;
  --font-head: 'Outfit', 'Noto Sans KR', system-ui, sans-serif;
}
/* Korean wraps at spaces, not in the middle of words */
:lang(ko) { word-break: keep-all; overflow-wrap: anywhere; }
/* Wide letter spacing suits small capitals, not Hangul */
:lang(ko) .chapter-item-kicker, :lang(ko) .nav-note, :lang(ko) .m-where,
:lang(ko) .game-banner-kicker, :lang(ko) .chapter-item-tag, :lang(ko) .auth-step { letter-spacing: 0; font-family: var(--font-body); }

/* ---------- 2. Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg-main);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }

a { color: inherit; text-decoration: none; }
p { margin: 0; }
h1, h2, h3 { font-family: var(--font-head); margin: 0; letter-spacing: -.01em; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }
code { font-family: var(--font-mono); font-size: .9em; }

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

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 16px; top: -60px; z-index: 100; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--r-pill); font-weight: 600; }
.skip-link:focus { top: 12px; }

.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-btn.danger { color: var(--story-red); }

/* ---------- 3. Top bar ---------- */

.top-bar {
  position: sticky; top: 0; z-index: 40;
  height: 64px; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--topbar-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 10px; }

.menu-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px 0 12px;
  border-radius: var(--r-pill); border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 600; font-size: 14px;
}
.menu-btn:hover { background: var(--raised); }

.brand-title { display: inline-flex; align-items: center; gap: 10px; font: 700 19px var(--font-head); }
.brand-title img { width: 28px; height: 28px; }
[data-theme="light"] .brand-title img, [data-theme="light"] .auth-brand img { filter: invert(1); }

.control-pill {
  height: 36px; min-width: 36px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: transparent; color: var(--text);
  font: 600 13px var(--font-body); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.control-pill:hover:not(:disabled) { background: var(--raised); }
.control-pill:disabled { opacity: .4; cursor: default; }
.admin-pill { border-color: rgba(110, 155, 255, .5); color: var(--accent); }
.account-pill.is-signed-in { padding-left: 4px; }
/* Profile pictures: a round photo, or the first letter of the name */
.avatar {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; overflow: hidden;
  background: var(--accent); color: var(--bg-main);
  display: inline-flex; align-items: center; justify-content: center; font: 700 13px var(--font-head);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.has-photo { background: var(--raised); }
.comment-avatar { width: 30px; height: 30px; font-size: 13px; background: var(--raised); color: var(--text); border: 1px solid var(--line); }
.comment-card.is-author .comment-avatar:not(.has-photo) { background: var(--accent); color: var(--bg-main); border-color: transparent; }
.avatar-lg { width: 64px; height: 64px; font-size: 26px; }

/* Your account › Profile picture */
.avatar-edit { display: flex; align-items: flex-start; gap: 16px; padding: 4px 0 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.avatar-edit[aria-busy="true"] { opacity: .6; pointer-events: none; }
.avatar-edit-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.avatar-edit-body strong { font-size: 14px; }
.avatar-edit-body strong span { font-weight: 400; color: var(--muted); }
.avatar-edit-body small { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.avatar-edit-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.auth-secondary.avatar-upload { position: relative; cursor: pointer; width: auto; height: 40px; padding: 0 18px; font-size: 14px; }
.avatar-upload:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-status { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); min-height: 0; }
.avatar-status:empty { display: none; }
.avatar-status.is-error { color: var(--story-red); }

/* "Aa" only shows on phones (section 13) */
.reading-btn { display: none; font-family: var(--font-head); }
.reading-panel { display: flex; gap: 10px; }

.progress-bar-container { position: sticky; top: 64px; z-index: 39; height: 2px; background: transparent; }
.progress-bar { height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }

/* Language menu: a native select inside a pill */
.lang-pick { position: relative; padding: 0 10px; gap: 6px; cursor: pointer; }
.lang-pick select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; color: inherit;
  font: 600 13px var(--font-body); cursor: pointer; padding-right: 14px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 4px center, right 0 center; background-size: 4px 4px; background-repeat: no-repeat;
}
.lang-pick select:focus { outline: none; }
.lang-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.lang-pick select option { background: var(--card); color: var(--text); }

/* ---------- 4. Chapter banner ---------- */

.hero-banner { position: relative; overflow: hidden; min-height: 340px; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.header-bg-art {
  position: absolute; inset: 0;
  background: url(../images/banner.jpg) right 30% center / cover no-repeat;
}
.header-gradient-overlay {
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg, var(--bg-main) 0%, color-mix(in srgb, var(--bg-main) 92%, transparent) 30%, color-mix(in srgb, var(--bg-main) 40%, transparent) 62%, transparent 100%),
    linear-gradient(0deg, var(--bg-main) 0%, transparent 45%);
}
.hero-content { position: relative; width: 100%; max-width: var(--max); margin: 0 auto; padding: 72px 24px 40px; display: flex; flex-direction: column; gap: 12px; }
.banner-meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.project-name { display: inline-flex; align-items: center; font: 500 12px var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--spark); box-shadow: 0 0 12px 3px var(--spark-glow); margin-right: 10px; }
.designer-name { font-size: 13px; color: var(--muted); }
.edit-chapter-btn { margin-left: auto; height: 32px; padding: 0 14px; border-radius: var(--r-pill); border: 1px dashed var(--accent); color: var(--accent); background: var(--card); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; }
.chapter-headline { font-size: 52px; font-weight: 800; line-height: 1.05; letter-spacing: -.025em; max-width: 760px; }
.chapter-headline:focus { outline: none; }
.pub-meta { font-size: 14px; color: var(--muted); }

/* ---------- 5. Chapter text (reading column) ---------- */

.main-wrapper { max-width: var(--read); margin: 0 auto; padding: 48px 24px 0; }

.hidden-chapter-note {
  margin-bottom: 28px; padding: 14px 18px; border-radius: 12px;
  border: 1px dashed var(--accent); background: var(--accent-glow); color: var(--text); font-size: 14px;
}

/* ---------- No chapter published yet ("Coming soon") ---------- */
.coming-soon {
  margin-bottom: 40px; padding: 24px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--card);
  display: flex; flex-direction: column; gap: 12px;
}
.coming-soon-title { font-size: 20px; color: var(--text); margin: 0; }
.coming-soon-text { color: var(--body); line-height: 1.6; margin: 0; }
.coming-soon .gate-actions { display: flex; flex-wrap: wrap; gap: 10px; }
/* Nothing to read yet: hide the reading tools and everything about a chapter,
   but keep the game banner */
.no-chapters .progress-bar-container,
.no-chapters .chapter-nav-bottom,
.no-chapters .mobile-chapter-bar,
.no-chapters .drawer-search,
.no-chapters .fan-section > :not(.game-banner) { display: none !important; }
.no-chapters .fan-section { padding-top: 0; }
.control-pill:disabled { opacity: .4; cursor: default; }

.lang-note {
  margin-bottom: 28px; padding: 12px 16px; border-radius: 12px; font-size: 13.5px;
  border: 1px solid var(--line); background: var(--card); color: var(--body);
}

.story-content { font-size: var(--story-size); line-height: 1.85; color: var(--body); -webkit-user-select: none; user-select: none; }
.story-content p { margin: 0 0 1.25em; }
.story-content strong { color: var(--text); }
.story-content em { color: var(--text); }
.story-content blockquote {
  margin: 1.6em 0; padding: 14px 20px; border-left: 3px solid var(--story-blue);
  background: color-mix(in srgb, var(--story-blue) 8%, transparent); border-radius: 0 10px 10px 0;
  font-family: var(--font-mono); font-size: .86em; line-height: 1.7; color: var(--text);
}
.story-content hr { border: 0; margin: 2.4em 0; text-align: center; color: var(--muted); }
.story-content hr::before { content: "·  ·  ·"; letter-spacing: .4em; font-size: 1.2em; }

/* Terminal screens */
.terminal-box {
  margin: 1.8em 0; border: 1px solid color-mix(in srgb, var(--story-blue) 45%, transparent); border-radius: 12px;
  background: var(--terminal-bg); color: #CFE0FF; font: 13.5px/1.7 var(--font-mono); overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .2), 0 12px 32px rgba(0, 0, 0, .25);
}
.terminal-header {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--story-blue) 30%, transparent);
  color: var(--story-blue); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 12px;
}
.terminal-header i { margin-right: 6px; }
.terminal-row { display: flex; justify-content: space-between; gap: 16px; padding: 4px 16px; }
.terminal-row:first-of-type { padding-top: 12px; }
.terminal-row span:last-child { color: #FFFFFF; text-align: right; }
.terminal-row:only-child span, .terminal-row span:only-child { text-align: left; }
.terminal-alert { margin-top: 8px; padding: 10px 16px; border-top: 1px solid rgba(255, 90, 95, .35); background: rgba(255, 90, 95, .1); color: #FF8A8E; font-weight: 600; }
.terminal-box > :last-child:not(.terminal-alert) { padding-bottom: 12px; }
.terminal-box.is-alert { border-color: rgba(255, 90, 95, .6); background: #1A0A0E; }
.terminal-box.is-alert .terminal-header { color: #FF8A8E; border-color: rgba(255, 90, 95, .35); }

/* Illustrations: tap to enlarge */
.inline-illustration { margin: 2em 0; }
.illustration-open { position: relative; display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--card); cursor: zoom-in; }
.illustration-open img { width: 100%; height: auto; }
.img-shield { position: absolute; inset: 0; }

/* ---------- 6. Chapter navigation ---------- */

.chapter-nav-bottom {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  margin: 56px 0 0; padding: 22px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.nav-btn {
  height: 42px; padding: 0 18px; border-radius: var(--r-pill); border: 1px solid var(--line);
  display: inline-flex; align-items: center; font-weight: 600; font-size: 14px; cursor: pointer;
}
.nav-btn:hover:not(.disabled) { background: var(--raised); }
#nextBtn:not(.disabled) { background: var(--text); color: var(--bg-main); border-color: var(--text); }
.nav-btn.disabled { opacity: .35; cursor: default; }
.nav-note { text-align: center; font: 500 12px var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* ---------- 7. Reactions + game banner ---------- */

.fan-section { padding: 48px 0 64px; display: flex; flex-direction: column; gap: 20px; }
.section-title { font-size: 22px; font-weight: 700; }
.comment-count { color: var(--muted); font-weight: 500; }

.reactions-box { display: flex; flex-direction: column; gap: 14px; }
.reactions-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.reaction-chip {
  height: 40px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
  transition: border-color .15s, background .15s;
}
.reaction-chip:hover { border-color: var(--field); }
.reaction-chip .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.reaction-chip.active { border-color: var(--accent); background: var(--accent-glow); }
.reaction-chip.active .count { color: var(--accent); }
.reactions-hint { font-size: 12.5px; color: var(--muted); }

.game-banner {
  position: relative; display: grid; grid-template-columns: 140px 1fr auto; align-items: center; gap: 20px;
  margin: 16px 0 24px; padding: 14px; border-radius: var(--r-card); border: 1px solid var(--line);
  background: linear-gradient(100deg, var(--card), color-mix(in srgb, var(--accent) 10%, var(--card)));
  transition: border-color .2s;
}
.game-banner:hover { border-color: var(--accent); }
.game-banner-art { height: 96px; border-radius: 10px; background: url(../images/prologue-01.jpg) 45% 22% / cover; }
.game-banner-info { display: flex; flex-direction: column; gap: 4px; }
.game-banner-kicker { font: 500 11px var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.game-banner-title { font: 700 20px var(--font-head); }
.game-banner-text { font-size: 13.5px; color: var(--body); }
.game-banner-arrow {
  width: 38px; height: 38px; margin-right: 6px; border-radius: 50%; border: 1px solid var(--line); background: var(--raised);
  display: flex; align-items: center; justify-content: center;
}
.game-banner:hover .game-banner-arrow { background: var(--accent); border-color: var(--accent); color: var(--on-light); }

/* ---------- 8. Comments ---------- */

.comment-gate {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px;
  padding: 20px 22px; border-radius: var(--r-card); border: 1px solid var(--line); background: var(--card);
}
.gate-title { font-weight: 700; }
.gate-text { font-size: 13.5px; color: var(--muted); }
.gate-actions { display: flex; gap: 8px; }
.gate-primary, .gate-secondary { height: 40px; padding: 0 18px; border-radius: var(--r-pill); font-weight: 600; font-size: 14px; cursor: pointer; }
.gate-primary { background: var(--text); color: var(--bg-main); border: 1px solid var(--text); }
.gate-secondary { background: transparent; border: 1px solid var(--line); }

.comment-form { display: flex; flex-direction: column; gap: 8px; }
.comment-label { font-size: 13px; font-weight: 500; color: var(--body); }
.comment-input-wrap { border: 1px solid var(--field); border-radius: 14px; background: var(--card); overflow: hidden; }
.comment-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.comment-textarea {
  display: block; width: 100%; min-height: 110px; padding: 14px 16px; resize: vertical;
  border: 0; background: transparent; color: var(--text); font: 15px/1.6 var(--font-body);
}
.comment-textarea:focus { outline: none; }
.comment-textarea::placeholder, .comment-author-input::placeholder, .search-input::placeholder { color: var(--muted); }
.comment-form-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); }
.posting-as { font-size: 13px; color: var(--muted); margin-right: auto; }
.posting-as strong { color: var(--text); }
.guest-fields { display: flex; gap: 8px; margin-right: auto; flex-wrap: wrap; }
.comment-author-input {
  height: 38px; width: 150px; padding: 0 12px; border-radius: var(--r-input);
  border: 1px solid var(--field); background: var(--bg-main); color: var(--text); font: 14px var(--font-body);
}
.comment-author-input:focus { outline: none; border-color: var(--accent); }
.submit-comment-btn {
  margin-left: auto; height: 38px; padding: 0 18px; border-radius: var(--r-pill); border: 0;
  background: var(--text); color: var(--bg-main); font-weight: 700; font-size: 14px; cursor: pointer;
}
.submit-comment-btn:disabled { opacity: .5; }
.guest-hint { font-size: 12.5px; color: var(--muted); }
.form-status { font-size: 13px; color: var(--muted); min-height: 1em; }
.form-status.is-error { color: var(--story-red); }
.local-note { font-size: 12.5px; color: var(--muted); padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; }

.comments-list { display: flex; flex-direction: column; gap: 10px; }
.comments-empty { color: var(--muted); font-size: 14px; padding: 18px 0; }
.comment-card { padding: 16px 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }
.comment-card.is-author { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.comment-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.comment-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.comment-name { font-weight: 700; font-size: 14px; }
.comment-badge {
  font: 500 10px var(--font-mono); letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--r-pill); border: 1px solid var(--line); color: var(--muted);
}
.comment-badge.author { border-color: rgba(255, 90, 95, .5); color: var(--story-red); background: rgba(255, 90, 95, .08); }
.comment-badge.guest { border-style: dashed; }
.comment-meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.comment-delete { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.comment-delete:hover { color: var(--story-red); }
.comment-body { font-size: 14.5px; color: var(--body); white-space: pre-wrap; overflow-wrap: anywhere; }

.delete-confirm { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--raised); display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; }
.delete-confirm.is-warning { border: 1px solid rgba(255, 90, 95, .4); }
.delete-warning { display: flex; gap: 10px; align-items: flex-start; }
.delete-warning svg { color: var(--story-red); flex-shrink: 0; margin-top: 2px; }
.delete-row { display: flex; flex-wrap: wrap; gap: 8px; }
.delete-password { height: 38px; padding: 0 12px; border-radius: var(--r-input); border: 1px solid var(--field); background: var(--bg-main); color: var(--text); flex: 1; min-width: 140px; }
.delete-yes, .delete-no { height: 38px; padding: 0 16px; border-radius: var(--r-pill); font-weight: 600; font-size: 13.5px; cursor: pointer; }
.delete-yes { background: var(--story-red); color: var(--on-spark); border: 0; }
.delete-no { background: transparent; border: 1px solid var(--line); }
.delete-error { color: var(--story-red); font-size: 13px; }
.delete-error:empty { display: none; }

/* ---------- 9. Footer + phone bar ---------- */

.site-footer {
  border-top: 1px solid var(--line); padding: 32px 24px 40px; text-align: center;
  display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; color: var(--body);
}
.footer-links { display: flex; justify-content: center; gap: 20px; font-weight: 600; }
.footer-links a:hover { color: var(--accent); }
.copyright { font-size: 12px; color: var(--muted); max-width: 560px; margin: 0 auto; }

.mobile-chapter-bar { display: none; }

/* ---------- 10. Chapter list (drawer) ---------- */

.drawer-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(4, 6, 12, .6); opacity: 0; pointer-events: none; transition: opacity .25s; }
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer-panel {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 61; width: min(380px, 92vw);
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .28s ease; visibility: hidden;
}
.drawer-panel.open { transform: none; visibility: visible; }
.drawer-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 22px 22px 14px; }
.drawer-title { display: block; font: 700 24px var(--font-head); }
.drawer-sub { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.drawer-close-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.drawer-search { padding: 0 22px 12px; }
.search-input { width: 100%; height: 42px; padding: 0 14px; border-radius: var(--r-input); border: 1px solid var(--field); background: var(--bg-main); color: var(--text); font: 14px var(--font-body); }
.search-input:focus { outline: none; border-color: var(--accent); }
.chapter-list { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.chapter-item {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "k d" "t d";
  gap: 2px 12px; align-items: center; padding: 12px 12px; border-radius: 10px; border-left: 3px solid transparent;
}
.chapter-item:hover { background: var(--raised); }
.chapter-item.active { background: var(--accent-glow); border-left-color: var(--accent); }
.chapter-item-kicker { grid-area: k; font: 500 11px var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.chapter-item-title { grid-area: t; font-weight: 600; font-size: 14.5px; }
.chapter-item-date { grid-area: d; font-size: 12px; color: var(--muted); }
.chapter-item-tag.latest { margin-left: 6px; padding: 2px 7px; border-radius: var(--r-pill); background: var(--spark); color: var(--on-spark); font-weight: 600; letter-spacing: .06em; }
.chapter-upcoming { margin: 8px 12px 0; padding: 12px; border-radius: 10px; border: 1px dashed var(--line); display: flex; flex-direction: column; gap: 2px; }
.chapter-upcoming .chapter-item-title { color: var(--muted); }
.chapter-empty { padding: 16px 12px; color: var(--muted); font-size: 14px; }
.drawer-footer { display: flex; gap: 18px; padding: 16px 22px 22px; border-top: 1px solid var(--line); font-size: 13.5px; font-weight: 600; }
.drawer-footer a:hover { color: var(--accent); }

/* ---------- 11. Sign in / account ---------- */

.auth-page {
  position: fixed; inset: 0; z-index: 80; overflow-y: auto; padding: 48px 16px;
  background: rgba(4, 6, 12, .72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; justify-content: center; align-items: flex-start;
}
.auth-card {
  width: 100%; max-width: 440px; padding: 22px 28px 28px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.auth-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.auth-brand { display: inline-flex; align-items: center; gap: 8px; font: 700 16px var(--font-head); }
.auth-close { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.auth-view { display: flex; flex-direction: column; gap: 14px; }
.auth-view form { display: flex; flex-direction: column; gap: 14px; }
.auth-icon { color: var(--accent); }
.auth-step { font: 500 11px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.auth-title { font-size: 28px; font-weight: 800; }
.auth-title:focus { outline: none; }
.auth-sub { color: var(--body); font-size: 14.5px; }
.auth-sub strong { color: var(--text); }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field label { font-size: 13px; font-weight: 600; color: var(--body); }
.auth-input-wrap { position: relative; }
.auth-input-wrap input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: var(--r-input);
  border: 1px solid var(--field); background: var(--bg-main); color: var(--text); font: 15px var(--font-body);
}
.auth-input-wrap.has-toggle input { padding-right: 46px; }
.auth-input-wrap input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.pw-toggle { position: absolute; right: 6px; top: 6px; width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.pw-toggle[aria-pressed="true"] { color: var(--accent); }
.auth-hint { font-size: 12.5px; color: var(--muted); }
.auth-options { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.auth-options legend { font-size: 13px; font-weight: 600; color: var(--body); margin-bottom: 8px; padding: 0; }
.auth-options legend span { font-weight: 400; color: var(--muted); }
.auth-check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; }
.auth-check:has(input:checked) { border-color: var(--accent); background: var(--accent-glow); }
.auth-check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.auth-check strong { display: block; font-size: 14px; }
.auth-check small { display: block; font-size: 12.5px; color: var(--muted); }
.auth-fine { font-size: 12.5px; color: var(--muted); }
.auth-inline-end { display: flex; justify-content: flex-end; margin-top: -6px; font-size: 13px; }
.auth-error { color: var(--story-red); font-size: 13.5px; }
.auth-error:empty { display: none; }
.auth-primary, .auth-secondary {
  width: 100%; height: 46px; border-radius: var(--r-pill); font-weight: 700; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.auth-primary { border: 0; background: var(--text); color: var(--bg-main); }
.auth-primary.danger { background: var(--story-red); color: var(--on-spark); }
.auth-primary:disabled { opacity: .6; }
.auth-secondary { background: transparent; border: 1px solid var(--line); font-weight: 600; }
.auth-secondary:hover { background: var(--raised); }
.auth-switch { text-align: center; font-size: 13.5px; color: var(--muted); }
.auth-skip { background: none; border: 0; color: var(--muted); font-size: 13.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.auth-admin-link { text-align: center; font-weight: 600; color: var(--accent); font-size: 14px; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.auth-danger { text-align: center; padding-top: 6px; border-top: 1px solid var(--line); font-size: 13.5px; }
.auth-danger .link-btn { margin-top: 10px; }
.auth-preview-note { margin-top: 18px; font-size: 12px; color: var(--muted); padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }

/* ---------- 12. Lightbox, toast, print ---------- */

.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(2, 4, 8, .92); display: flex; align-items: center; justify-content: center; padding: 24px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.lightbox.open { opacity: 1; pointer-events: auto; }
.lightbox-frame { position: relative; max-width: 100%; max-height: 100%; }
.lightbox-frame img { max-height: 88vh; width: auto; border-radius: 10px; }
.lightbox-close { position: absolute; top: 16px; right: 16px; width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .25); background: rgba(8, 11, 20, .6); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 95; transform: translate(-50%, 20px); opacity: 0;
  padding: 12px 18px; border-radius: var(--r-pill); background: var(--text); color: var(--bg-main);
  font-weight: 600; font-size: 14px; box-shadow: 0 12px 30px rgba(0, 0, 0, .35); transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.print-notice { display: none; }
@media print {
  body > *:not(.print-notice) { display: none !important; }
  .print-notice { display: block; padding: 40px; font-size: 18px; color: #000; }
}

/* ---------- 13. Phones ---------- */

@media (max-width: 599px) {
  .top-bar { height: 58px; padding: 0 12px; }
  .progress-bar-container { top: 58px; }
  .menu-btn { padding: 0 10px; }
  .menu-label { display: none; }
  .brand-title { font-size: 17px; }
  .brand-title img { width: 24px; height: 24px; }
  .nav-right { gap: 6px; position: relative; }
  .account-pill .account-label { display: none; }
  .account-pill:not(.is-signed-in) .account-label { display: inline; }
  .account-pill:not(.is-signed-in) svg { display: none; }
  .account-pill.is-signed-in { padding: 0 4px; }

  /* "Aa" opens a small panel with text size and theme */
  .reading-btn { display: inline-flex; }
  .reading-panel {
    display: none; position: absolute; top: 46px; right: 0; z-index: 45;
    padding: 10px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 16px 40px rgba(0, 0, 0, .4);
  }
  .reading-panel.open { display: flex; flex-wrap: wrap; width: max-content; max-width: calc(100vw - 24px); }

  .hero-banner { min-height: 300px; }
  .header-bg-art { background-position: 70% center; opacity: .6 !important; }
  .header-gradient-overlay { background: linear-gradient(0deg, var(--bg-main) 5%, color-mix(in srgb, var(--bg-main) 50%, transparent) 70%, transparent 100%); }
  .hero-content { padding: 56px 16px 28px; }
  .chapter-headline { font-size: 34px; }
  .edit-chapter-btn { margin-left: 0; }

  .main-wrapper { padding: 32px 16px 0; }
  .chapter-nav-bottom { grid-template-columns: 1fr 1fr; }
  .chapter-nav-bottom .nav-note { grid-column: 1 / -1; grid-row: 1; }
  .chapter-nav-bottom #nextBtn { justify-self: end; }

  .game-banner { grid-template-columns: 76px 1fr; gap: 14px; }
  .game-banner-art { height: 76px; }
  .game-banner-arrow { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; margin: 0; }
  .game-banner-info { padding-right: 32px; }
  .game-banner-title { font-size: 17px; }

  .comment-gate { flex-direction: column; align-items: stretch; }
  .gate-actions > * { flex: 1; }
  .guest-fields { width: 100%; }
  .comment-author-input { flex: 1; width: auto; min-width: 0; }
  .submit-comment-btn { width: 100%; }

  /* Bottom bar fixed to the screen */
  body { padding-bottom: 64px; }
  .mobile-chapter-bar {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; height: 60px; padding: 0 12px calc(env(safe-area-inset-bottom));
    background: var(--topbar-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  }
  .m-nav { height: 40px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line); display: inline-flex; align-items: center; font-weight: 600; font-size: 14px; }
  .m-nav.disabled { opacity: .35; }
  #mNextBtn:not(.disabled) { background: var(--text); color: var(--bg-main); border-color: var(--text); }
  .m-where { text-align: center; font: 500 11px var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .toast { bottom: 80px; }

  .auth-page { padding: 0; align-items: stretch; }
  .auth-card { max-width: none; min-height: 100%; border-radius: 0; border: 0; padding: 16px 20px 32px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
