:root {
  color-scheme: light;
  --bg: #f5f1ea;
  --surface: #fffdf8;
  --surface-2: #eee5d8;
  --ink: #221d18;
  --muted: #71685e;
  --line: rgba(45, 36, 25, 0.13);
  --primary: #1d6f70;
  --primary-dark: #144c4d;
  --accent: #b85b33;
  --gold: #d8ad55;
  --danger: #aa3d36;
  --shadow: 0 18px 44px rgba(34, 28, 20, 0.12);
  --reader-bg: #fffdf8;
  --reader-ink: #221d18;
  --reader-muted: #71685e;
  --reader-font: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --reader-font-size: 18px;
  --reader-line-height: 1.88;
}

:root[data-site-theme="dark"] {
  color-scheme: dark;
  --bg: #101312;
  --surface: #171c1b;
  --surface-2: #202826;
  --ink: #f1eee8;
  --muted: #b7ada2;
  --line: rgba(255, 255, 255, 0.14);
  --primary: #49aaa6;
  --primary-dark: #78c9c4;
  --accent: #e18b62;
  --gold: #e3bd68;
  --danger: #d35f58;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

a {
  color: inherit;
}

.container {
  width: min(1160px, 92vw);
  margin: 0 auto;
}

.site-hero,
.story-hero {
  position: relative;
  color: #fff;
  background-image:
    linear-gradient(90deg, rgba(12, 18, 18, 0.88), rgba(12, 18, 18, 0.62) 54%, rgba(12, 18, 18, 0.24)),
    url("assets/story-hero.png");
  background-size: cover;
  background-position: center;
}

.site-hero {
  min-height: 520px;
}

.story-hero {
  min-height: 470px;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  font-size: 1.12rem;
  font-weight: 900;
  text-decoration: none;
}

.nav-donate {
  margin-right: auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  font-weight: 900;
  text-decoration: none;
}

.nav-donate:hover {
  background: rgba(255, 255, 255, 0.22);
}

.user-panel,
.hero-actions,
.form-actions,
.story-actions,
.story-footer,
.meta-row,
.reader-actions,
.panel-heading,
.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.user-panel {
  justify-content: flex-end;
}

.user-status {
  color: rgba(255, 255, 255, 0.88);
  font-weight: 800;
}

.site-theme-control {
  display: flex;
  align-items: center;
}

.site-theme-select {
  min-height: 40px;
  width: auto;
  margin: 0;
  padding: 9px 34px 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  font: inherit;
  font-weight: 800;
}

.site-theme-select option {
  color: var(--ink);
  background: var(--surface);
}

.hero-content,
.story-cover {
  min-height: calc(520px - 74px);
  display: grid;
  align-content: center;
  max-width: 760px;
  padding: 40px 0 86px;
}

.story-cover {
  min-height: calc(470px - 74px);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.site-hero .eyebrow,
.story-hero .eyebrow {
  color: var(--gold);
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 820px;
  margin: 0;
  font-size: clamp(2.25rem, 5vw, 4.35rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: clamp(1.5rem, 2.7vw, 2.15rem);
  line-height: 1.15;
}

h3 {
  margin: 0;
  font-size: 1.16rem;
  line-height: 1.25;
}

.hero-content > p:not(.eyebrow),
.story-cover > div > p:not(.eyebrow) {
  max-width: 650px;
  margin: 18px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 1.05rem;
  line-height: 1.7;
}

.hero-actions {
  margin-top: 26px;
}

.button,
.icon-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 9px 15px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease;
}

.button:hover,
.icon-button:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.button-secondary,
.icon-button {
  background: var(--surface-2);
  color: var(--ink);
}

.button-secondary:hover,
.icon-button:hover {
  background: color-mix(in srgb, var(--surface-2) 82%, var(--primary) 18%);
}

.button-ghost {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.36);
}

.button-danger,
.icon-button.danger {
  background: var(--danger);
  color: #fff;
}

.hidden {
  display: none !important;
}

.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;
}

.panel,
.search-panel,
.story-card,
.reader-panel,
.story-sidebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel,
.search-panel {
  padding: 24px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 18px;
}

.login-panel {
  position: absolute;
  top: 86px;
  right: max(4vw, calc((100vw - 1160px) / 2));
  z-index: 4;
  width: min(360px, 92vw);
  color: var(--ink);
}

.auth-panel {
  width: min(720px, 92vw);
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.auth-grid h3 {
  margin-bottom: 14px;
}

.library-dashboard {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  gap: 18px;
  align-items: stretch;
  margin-top: -46px;
  position: relative;
  z-index: 2;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stats-strip div {
  min-height: 128px;
  padding: 22px;
  background: var(--surface);
}

.stats-strip strong {
  display: block;
  color: var(--primary);
  font-size: 1.72rem;
}

.stats-strip span,
.section-note,
.small-text,
.empty-state {
  color: var(--muted);
}

.search-panel {
  display: grid;
  align-content: center;
}

.search-panel label {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 1.05rem;
}

.search-row {
  flex-wrap: nowrap;
}

.search-row input {
  margin-top: 0;
}

.library-intro,
.section-heading,
.footer-grid {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
}

.library-intro {
  padding: 56px 0 28px;
}

.library-intro p:last-child {
  max-width: 540px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.admin-panel {
  margin-bottom: 34px;
}

.history-panel {
  margin-top: 24px;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.history-item p {
  margin: 6px 0 0;
  color: var(--muted);
}

.story-form,
.chapter-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.story-form label:nth-child(5),
.checkbox-label,
.form-actions,
.chapter-form label:nth-child(3) {
  grid-column: 1 / -1;
}

label {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="url"],
input[type="search"],
select,
textarea {
  width: 100%;
  margin-top: 7px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

input[type="search"] {
  min-height: 44px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

input[type="color"] {
  width: 100%;
  height: 44px;
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

textarea {
  resize: vertical;
}

.checkbox-label {
  display: flex;
  gap: 10px;
  align-items: center;
}

.stories-section {
  padding-bottom: 76px;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.story-card {
  display: grid;
  grid-template-columns: 138px minmax(0, 1fr);
  min-height: 250px;
  overflow: hidden;
}

.cover-frame {
  display: block;
  min-height: 100%;
  background: var(--surface-2);
  overflow: hidden;
}

.cover-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 220ms ease;
}

.story-card:hover .cover-frame img {
  transform: scale(1.035);
}

.story-card-body {
  display: flex;
  min-height: 250px;
  flex-direction: column;
  padding: 20px;
}

.story-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.story-card p {
  color: var(--muted);
  line-height: 1.62;
}

.story-card .story-meta {
  margin-top: auto;
}

.story-footer {
  margin-top: 14px;
  justify-content: space-between;
}

.story-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.tag,
.ai-badge,
.meta-row span {
  display: inline-flex;
  align-items: center;
  min-height: 29px;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 0.82rem;
  font-weight: 900;
}

.tag {
  background: var(--surface-2);
  color: var(--primary-dark);
}

.ai-badge {
  background: #ffe08a;
  color: #5d3a00;
  white-space: nowrap;
}

.search-empty {
  grid-column: 1 / -1;
  padding: 34px;
  text-align: center;
}

.search-empty p {
  margin-bottom: 0;
}

.meta-row {
  margin-top: 22px;
}

.meta-row span {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.back-link {
  display: inline-flex;
  margin-bottom: 20px;
  color: rgba(255, 255, 255, 0.84);
  text-decoration: none;
  font-weight: 900;
}

.story-detail-wrap {
  width: min(960px, 100%);
}

.story-detail-card {
  display: grid;
  grid-template-columns: minmax(132px, 190px) minmax(0, 1fr);
  gap: clamp(18px, 4vw, 34px);
  align-items: stretch;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(10, 15, 15, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.story-detail-cover {
  width: 100%;
  height: 100%;
  min-height: 260px;
  display: block;
  object-fit: cover;
}

.story-detail-body {
  display: flex;
  min-height: 260px;
  flex-direction: column;
  justify-content: center;
  padding: clamp(18px, 4vw, 34px);
}

.story-detail-body h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
}

.story-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.story-layout {
  display: grid;
  grid-template-columns: minmax(230px, 310px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  padding: 50px 0 80px;
}

.reader-page .story-layout {
  display: block;
  width: min(920px, 92vw);
  padding-top: 28px;
}

.reader-page .reader-column {
  width: 100%;
}

.reader-page .reader-panel {
  min-height: 70vh;
  padding: clamp(24px, 5vw, 58px);
}

.story-toc-panel {
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 4px;
}

.story-toc-panel .panel-heading {
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.story-toc-panel h2 {
  margin: 0;
  font-size: 1.2rem;
}

.toc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.story-toc-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
}

.story-toc-list .chapter-link {
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 4px;
  text-align: left;
}

.story-toc-list .chapter-link span {
  min-width: 72px;
  color: var(--accent);
}

.reader-hero {
  min-height: 360px;
}

.reader-hero .story-cover {
  min-height: calc(360px - 74px);
  padding-bottom: 60px;
}

.reading-toolbar {
  position: sticky;
  top: 10px;
  z-index: 5;
  width: fit-content;
  max-width: calc(100vw - 24px);
  margin: -26px auto 0;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  transition: transform 180ms ease, opacity 180ms ease;
}

.reading-toolbar.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-18px);
}

.reading-toolbar .icon-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chapter-select {
  width: min(260px, 38vw);
  min-height: 40px;
  margin: 0;
  font-weight: 800;
}

.toolbar-chapter-search {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar-chapter-search input {
  width: min(190px, 28vw);
  min-height: 40px;
  margin: 0;
}

.chapter-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 16px;
}

.chapter-search input {
  margin-top: 0;
}

.app-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 30;
  max-width: min(520px, calc(100vw - 28px));
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  line-height: 1.45;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -14px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.app-toast.is-error {
  background: #b3261e;
}

.ad-slot {
  width: min(1160px, 92vw);
  min-height: 92px;
  margin: 24px auto;
  display: grid;
  place-items: center;
  gap: 4px;
  border: 1px dashed color-mix(in srgb, var(--muted) 42%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 84%, var(--surface-2) 16%);
  color: var(--muted);
  text-align: center;
}

.ad-slot span {
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.ad-slot strong {
  color: var(--ink);
}

.reader-page .ad-slot {
  width: min(920px, 92vw);
}

.ad-hero {
  margin-top: -38px;
  position: relative;
  z-index: 2;
}

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

.chapter-ad-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 8, 0.62);
}

.chapter-ad-card {
  position: relative;
  width: min(520px, 94vw);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  text-align: center;
}

.chapter-ad-card h2 {
  margin-bottom: 16px;
}

.ad-modal-slot {
  width: 100%;
  min-height: 180px;
  margin: 14px 0 18px;
}

.forum-button {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 12;
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  font: inherit;
  font-weight: 900;
}

.forum-panel {
  position: fixed;
  right: 18px;
  bottom: 74px;
  z-index: 13;
  width: min(390px, calc(100vw - 24px));
  max-height: min(680px, calc(100vh - 100px));
  overflow-y: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.forum-heading,
.forum-profile,
.forum-form {
  display: grid;
  gap: 10px;
}

.forum-heading {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  margin-bottom: 14px;
}

.forum-profile {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.forum-form {
  margin-bottom: 14px;
}

.forum-form textarea {
  margin-top: 0;
}

.forum-list {
  display: grid;
  gap: 10px;
}

.forum-post {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 86%, var(--surface-2) 14%);
}

.forum-post div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.forum-post strong {
  color: var(--ink);
}

.forum-post p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(13, 12, 10, 0.38);
}

.reader-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 9;
  width: min(380px, 92vw);
  overflow-y: auto;
  padding: 22px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.reader-drawer-right {
  inset: 0 0 0 auto;
  border-right: 0;
  border-left: 1px solid var(--line);
}

.drawer-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.drawer-heading h2 {
  margin: 0;
}

.story-sidebar,
.reader-panel {
  padding: 24px;
}

.story-sidebar {
  position: sticky;
  top: 18px;
}

.story-sidebar h2 {
  margin-bottom: 16px;
  font-size: 1.22rem;
}

.chapter-list {
  display: grid;
  gap: 10px;
}

.chapter-link {
  width: 100%;
  display: grid;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--surface-2);
  color: var(--primary-dark);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  line-height: 1.35;
  text-align: left;
}

.chapter-link span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.chapter-link.is-active {
  border-color: color-mix(in srgb, var(--primary) 42%, transparent);
  background: color-mix(in srgb, var(--surface-2) 74%, var(--primary) 26%);
}

.reader-column {
  display: grid;
  gap: 18px;
}

.reader-panel {
  background: var(--reader-bg);
  color: var(--reader-ink);
  font-family: var(--reader-font);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
}

.reader-panel h2 {
  color: var(--reader-ink);
  margin-bottom: 18px;
}

.reader-lock {
  max-width: 560px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 42px) 0;
  text-align: center;
}

.reader-lock p:not(.eyebrow) {
  color: var(--reader-muted);
}

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

.donate-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 8, 0.62);
}

.donate-card {
  position: relative;
  width: min(430px, 94vw);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.donate-qr-frame {
  display: grid;
  place-items: center;
  min-height: 300px;
  margin: 18px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.donate-qr-frame img {
  width: min(300px, 80vw);
  max-height: 360px;
  display: block;
  object-fit: contain;
}

.donate-missing {
  display: none;
  margin: 0;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.donate-qr-frame.is-missing img {
  display: none;
}

.donate-qr-frame.is-missing .donate-missing {
  display: block;
}

.donate-bank-info {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.reader-actions {
  margin-bottom: 20px;
}

.chapter-content {
  white-space: normal;
}

.chapter-content p {
  margin: 0 0 20px;
  white-space: pre-wrap;
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4 {
  margin: 28px 0 16px;
  color: var(--reader-ink);
  line-height: 1.25;
}

.chapter-content h1 {
  font-size: clamp(2rem, 4vw, 3rem);
}

.chapter-content h2 {
  font-size: clamp(1.65rem, 3vw, 2.35rem);
}

.chapter-content h3 {
  font-size: 1.35rem;
}

.chapter-content ul,
.chapter-content ol {
  margin: 0 0 20px 24px;
  padding: 0;
}

.chapter-content li {
  margin-bottom: 8px;
}

.chapter-content blockquote {
  margin: 0 0 20px;
  padding: 12px 16px;
  border-left: 4px solid var(--primary);
  background: color-mix(in srgb, var(--reader-bg) 88%, var(--primary) 12%);
  color: var(--reader-muted);
}

.chapter-admin-panel {
  box-shadow: none;
}

.import-panel {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.import-panel .form-actions {
  margin-top: 10px;
}

.progress-panel {
  margin-top: 16px;
  padding: 18px;
  box-shadow: none;
}

.reader-settings {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 18px;
  box-shadow: none;
}

.reader-settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reader-settings-heading h2 {
  margin: 0;
}

.reader-settings label {
  font-size: 0.92rem;
}

footer {
  background: #171513;
  color: rgba(255, 255, 255, 0.78);
}

.footer-grid {
  min-height: 86px;
}

.footer-grid p {
  margin: 0;
}

.footer-grid p:first-child {
  color: #fff;
  font-weight: 900;
}

footer a {
  color: #fff;
  font-weight: 800;
  text-decoration-color: rgba(255, 255, 255, 0.38);
}

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
}

@media (max-width: 900px) {
  .library-dashboard,
  .story-layout {
    grid-template-columns: 1fr;
  }

  .story-sidebar {
    position: static;
  }
}

@media (max-width: 760px) {
  .site-hero,
  .story-hero {
    min-height: auto;
    background-position: 58% center;
  }

  .topbar,
  .library-intro,
  .section-heading,
  .footer-grid {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-panel {
    justify-content: flex-start;
  }

  .reading-toolbar {
    width: calc(100vw - 18px);
    flex-wrap: wrap;
  }

  .chapter-select {
    order: 5;
    width: 100%;
  }

  .toolbar-chapter-search {
    order: 6;
    width: 100%;
  }

  .toolbar-chapter-search input {
    width: 100%;
  }

  .chapter-search {
    grid-template-columns: 1fr;
  }

  .hero-content,
  .story-cover {
    min-height: 520px;
    padding-bottom: 72px;
  }

  .login-panel {
    position: static;
    margin: 0 auto 24px;
  }

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

  .stats-strip,
  .story-form,
  .chapter-form {
    grid-template-columns: 1fr;
  }

  .library-dashboard {
    margin-top: 18px;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .story-card {
    grid-template-columns: 1fr;
  }

  .history-item {
    align-items: stretch;
    flex-direction: column;
  }

  .cover-frame {
    aspect-ratio: 16 / 10;
  }
}

/* --- ADMIN DASHBOARD TABS --- */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
}

.admin-tabs .tab-button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 8px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  position: relative;
}

.admin-tabs .tab-button:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.admin-tabs .tab-button.active {
  color: var(--primary);
  background: var(--surface-2);
}

.admin-tabs .tab-button.active::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
}

.admin-tabs .badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: bold;
}

.admin-tabs .badge.hidden {
  display: none;
}

/* --- UPDATE REQUESTS LIST --- */
.requests-list {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.request-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.request-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.05);
}

.request-info h4 {
  margin: 0 0 6px 0;
  font-size: 1.1rem;
  color: var(--ink);
}

.request-info p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.request-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.request-actions label {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.request-actions input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: bold;
  text-align: center;
}

/* --- CLIENT-SIDE TRANSLATION STYLES --- */
.stv-word {
  cursor: pointer;
  border-bottom: 1px dashed var(--primary);
  position: relative;
  transition: background-color 0.2s ease;
}

.stv-word:hover {
  background-color: rgba(29, 111, 112, 0.12);
  border-bottom-style: solid;
}

/* Tooltip nổi chỉnh sửa nghĩa dịch */
.stv-tooltip {
  position: absolute;
  z-index: 10000;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  width: 280px;
  color: var(--ink);
  font-family: var(--reader-font);
  font-size: 0.9rem;
  line-height: 1.4;
  animation: fadeInTooltip 0.15s ease-out;
}

@keyframes fadeInTooltip {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.stv-tooltip-header {
  font-weight: bold;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stv-tooltip-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--muted);
  line-height: 1;
}

.stv-tooltip-close:hover {
  color: var(--ink);
}

.stv-tooltip-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stv-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.stv-tooltip-row span {
  font-size: 0.85rem;
  color: var(--muted);
}

.stv-tooltip-row strong {
  word-break: break-all;
}

.stv-tooltip-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stv-tooltip-input-group label {
  font-size: 0.8rem;
  color: var(--muted);
}

.stv-tooltip-input-group input {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink);
}

.stv-tooltip-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.stv-tooltip-actions button {
  padding: 6px 12px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.stv-tooltip-save {
  background: var(--primary);
  color: #fff;
}

.stv-tooltip-save:hover {
  background: var(--primary-dark);
}

.stv-tooltip-cancel {
  background: var(--surface-2);
  color: var(--ink);
}

.stv-tooltip-cancel:hover {
  background: var(--line);
}

/* --- HEADER SEARCH STYLES --- */
.header-search {
  flex: 1;
  max-width: 320px;
  margin: 0 20px;
  display: flex;
  align-items: center;
}

.header-search input {
  width: 100%;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.4);
  color: var(--ink);
  font-size: 0.88rem;
  transition: all 0.25s ease;
  margin: 0;
}

.header-search input:focus {
  background: rgba(15, 23, 42, 0.85);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 111, 112, 0.25);
  outline: none;
}

/* Responsive topbar search */
@media (max-width: 600px) {
  .header-search {
    display: none; /* Ẩn search trên màn hình quá nhỏ để tránh tràn header */
  }
}

/* --- LIKES & FOLLOWS BUTTONS --- */
.story-detail-actions .button.liked {
  background: #e11d48 !important; /* Màu hồng đỏ khi đã thích */
  color: #fff !important;
  border-color: #e11d48 !important;
}

.story-detail-actions .button.followed {
  background: #059669 !important; /* Màu xanh lục khi đã theo dõi */
  color: #fff !important;
  border-color: #059669 !important;
}

/* --- NOTIFICATIONS BOX --- */
.notifications-box {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

.notifications-box::before {
  content: '🔔';
  font-size: 1.2rem;
}

.notifications-box.empty {
  display: none;
}

/* --- STORY COMMENTS PANEL --- */
.story-details-extra {
  margin-top: 24px;
}

.comments-panel {
  padding: clamp(20px, 4vw, 32px) !important;
}

.comments-list {
  display: grid;
  gap: 14px;
  margin: 20px 0;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.comment-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.comment-author {
  font-weight: 700;
  color: var(--accent);
}

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

.comment-card p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
  word-break: break-word;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.comment-form textarea {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  resize: vertical;
  margin-top: 4px;
}

.comment-form textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.comment-form button {
  align-self: flex-end;
}

/* --- WebNovel ID compact portal theme, inspired by dense web-fiction indexes --- */
:root {
  --bg: #f1f3f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #222831;
  --muted: #68717d;
  --line: #dce2e8;
  --primary: #1e63d6;
  --primary-dark: #164aa1;
  --accent: #d8612c;
  --gold: #f3b342;
  --shadow: 0 1px 2px rgba(18, 28, 38, 0.06);
}

body {
  background: var(--bg);
  font-size: 14px;
}

.container {
  width: min(1180px, calc(100vw - 24px));
}

.site-hero,
.story-hero {
  color: var(--ink);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.site-hero {
  min-height: 0;
}

.story-hero,
.reader-hero {
  min-height: 0;
}

.topbar {
  min-height: 54px;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.brand {
  flex: 0 0 auto;
  color: var(--primary);
  font-size: 1.28rem;
  letter-spacing: 0;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  border-radius: 3px;
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.stv-main-nav {
  display: flex;
  flex: 1 1 auto;
  gap: 3px;
  align-items: center;
  min-width: 280px;
}

.stv-main-nav a {
  padding: 8px 10px;
  border-radius: 4px;
  color: #415064;
  font-weight: 800;
  text-decoration: none;
}

.stv-main-nav a:hover {
  background: var(--surface-2);
  color: var(--primary);
}

.header-search {
  flex: 0 1 260px;
}

.header-search input {
  min-height: 34px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--surface-2);
}

.user-panel {
  flex: 0 0 auto;
  gap: 6px;
}

.user-status {
  color: var(--muted);
  font-size: 0.84rem;
}

.site-theme-select,
.button,
.icon-button,
.nav-donate {
  min-height: 34px;
  border-radius: 4px;
  padding: 7px 11px;
  box-shadow: none;
}

.site-theme-select,
.button-secondary,
.icon-button,
.nav-donate,
.button-ghost {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

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

.button-secondary:hover,
.icon-button:hover,
.nav-donate:hover,
.button-ghost:hover {
  background: #eaf1ff;
  color: var(--primary);
  transform: none;
}

.nav-donate {
  margin-right: 0;
  font-weight: 800;
}

.hero-content,
.story-cover,
.reader-hero .story-cover {
  min-height: 0;
  max-width: none;
  padding: 18px 0;
}

.hero-content h1 {
  max-width: 780px;
  font-size: 1.55rem;
  line-height: 1.25;
}

.hero-content > p:not(.eyebrow),
.story-cover > div > p:not(.eyebrow) {
  max-width: 760px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.55;
}

.site-hero .eyebrow,
.story-hero .eyebrow,
.eyebrow {
  color: var(--accent);
}

.portal-notice {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #f1d7b8;
  border-radius: 4px;
  background: #fff8ed;
  color: #7a4a16;
  line-height: 1.45;
}

.hero-actions {
  margin-top: 12px;
}

.panel,
.search-panel,
.story-card,
.reader-panel,
.story-sidebar,
.stats-strip,
.quick-panel {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel,
.search-panel,
.quick-panel {
  padding: 14px;
}

.library-dashboard {
  grid-template-columns: 220px minmax(260px, 0.7fr) minmax(320px, 1fr);
  gap: 10px;
  margin-top: 12px;
  align-items: stretch;
}

.quick-panel h2 {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 1rem;
}

.quick-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.45;
}

.stats-strip {
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  overflow: hidden;
}

.stats-strip div {
  min-height: auto;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
}

.stats-strip div:last-child {
  border-right: 0;
}

.stats-strip strong {
  font-size: 1.2rem;
}

.search-panel {
  align-content: start;
}

.search-row {
  gap: 8px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="url"],
input[type="search"],
select,
textarea {
  border-radius: 4px;
  padding: 9px 10px;
}

.library-intro {
  padding: 24px 0 10px;
  align-items: center;
}

.library-intro h2,
.panel-heading h2 {
  color: var(--primary);
  font-size: 1.2rem;
}

.stories-section {
  padding-bottom: 36px;
}

.story-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.story-card {
  grid-template-columns: 72px minmax(0, 1fr);
  min-height: 0;
  overflow: visible;
}

.cover-frame {
  min-height: 96px;
  border-right: 1px solid var(--line);
}

.cover-frame img {
  height: 96px;
}

.story-card-body {
  min-height: 0;
  padding: 10px 12px;
}

.story-card-header {
  align-items: center;
}

.story-card-header h3 {
  font-size: 1rem;
}

.story-card-header h3 a {
  color: var(--primary-dark);
  text-decoration: none;
}

.story-card-header h3 a:hover {
  text-decoration: underline;
}

.story-card-desc {
  display: -webkit-box;
  margin: 5px 0 7px;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.story-tags {
  gap: 5px;
  margin: 6px 0;
}

.tag,
.ai-badge,
.meta-row span {
  min-height: 22px;
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 0.76rem;
}

.tag {
  background: #eef3f9;
  color: #526173;
}

.ai-badge {
  background: #ffe9ad;
}

.story-card .story-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.story-card .story-meta strong {
  color: var(--ink);
}

.story-footer {
  margin-top: 8px;
  justify-content: flex-start;
}

.story-actions {
  gap: 6px;
}

.story-detail-card {
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  backdrop-filter: none;
}

.story-detail-body h1 {
  color: var(--primary-dark);
  font-size: clamp(1.5rem, 3vw, 2.3rem);
}

.story-detail-body {
  min-height: 220px;
}

.story-detail-cover {
  min-height: 220px;
}

.back-link {
  color: var(--primary);
}

.meta-row {
  margin-top: 12px;
}

.meta-row span {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--muted);
}

.story-detail-actions {
  margin-top: 14px;
}

.reading-toolbar {
  top: 6px;
  margin-top: 10px;
  border-radius: 4px;
}

.reader-page .reader-panel {
  min-height: 68vh;
  padding: clamp(18px, 4vw, 44px);
}

.reader-panel h2 {
  color: var(--primary-dark);
}

footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
  }

  .stv-main-nav {
    order: 4;
    flex-basis: 100%;
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .library-dashboard {
    grid-template-columns: 1fr;
  }

  .stats-strip {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .container {
    width: min(100% - 16px, 1180px);
  }

  .topbar {
    min-height: 0;
    padding: 8px 0;
  }

  .header-search {
    flex-basis: 100%;
    order: 3;
  }

  .user-panel {
    justify-content: flex-start;
  }

  .hero-content h1 {
    font-size: 1.25rem;
  }

  .story-card {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .cover-frame,
  .cover-frame img {
    min-height: 82px;
    height: 82px;
  }

  .story-card-desc {
    -webkit-line-clamp: 1;
  }

  .story-footer .button {
    width: auto;
  }

  .story-toc-list {
    grid-template-columns: 1fr;
    max-height: 360px;
  }

  .toc-actions {
    width: 100%;
  }
}
