/* MediaCon Lab — webnovel reader.
 * Library chrome uses the site tokens; the reading surface has its own
 * user-picked themes, scoped to #reader-view[data-theme].
 */

:root {
  --paper: #f6f5f2;
  --card: #ffffff;
  --ink: #22252a;
  --muted: #6e7278;
  --line: #e4e2dc;
  --cyan: #0093bc;
  --magenta: #d63793;
  --yellow: #e8b823;
  --ok: #1e8e5a;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
  --reading-serif: Charter, "Bitstream Charter", Cambria, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- shared bits ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 500;
}
.btn.primary { background: var(--cyan); border-color: var(--cyan); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.icon-btn {
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.12); }
.icon-btn.aa { font-size: 15px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.dots { display: inline-flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dots i:nth-child(1) { background: var(--cyan); }
.dots i:nth-child(2) { background: var(--magenta); }
.dots i:nth-child(3) { background: var(--yellow); }
.dots.working i { animation: dotpulse 1s infinite ease-in-out; }
.dots.working i:nth-child(2) { animation-delay: 0.15s; }
.dots.working i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotpulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.45); } }

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: min(520px, 90vw);
  z-index: 60;
}

/* ---------- library ---------- */
#library-view { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); margin-right: auto; }
.wordmark { font-weight: 600; letter-spacing: 0.01em; }

.lib-main { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 32px) 48px; }
.hero { padding: 28px 0 8px; }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: clamp(30px, 5vw, 40px); margin: 0 0 6px; }
.subtitle { color: var(--muted); margin: 0; font-size: 15px; max-width: 56ch; }

.dropzone {
  position: relative;
  margin: 20px 0 8px;
  padding: 44px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
}
.corner { position: absolute; width: 14px; height: 14px; border: 2px solid var(--ink); opacity: 0.55; }
.corner.tl { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.corner.tr { top: 10px; right: 10px; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 10px; left: 10px; border-right: 0; border-top: 0; }
.corner.br { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }
.dz-line { font-size: 18px; font-weight: 500; margin: 0 0 4px; }
.dz-sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.privacy-line { display: block; color: var(--muted); font-size: 12.5px; margin-top: 14px; }

#book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
  padding: 20px 0 8px;
}
.book-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cover-btn {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: var(--card);
  aspect-ratio: 32 / 46;
}
.cover-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pct-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 999px;
}
.book-info h3 { font-size: 14px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-meta { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.mini-bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: var(--ok); transition: width 0.3s; }
.card-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 7px; }

.prose, .faq, .related { margin-top: 40px; }
.prose h2, .faq h2, .related h2 { font-family: var(--display); font-weight: 400; font-size: 24px; margin: 0 0 10px; }
.prose p { line-height: 1.65; max-width: 72ch; color: #3a3e44; }
.faq details { border-bottom: 1px solid var(--line); padding: 10px 0; max-width: 72ch; }
.faq summary { font-weight: 500; cursor: pointer; }
.faq p { color: #3a3e44; line-height: 1.6; }
.related ul { list-style: none; padding: 0; display: flex; gap: 18px; flex-wrap: wrap; }
.related a, .page-foot a { color: var(--cyan); }
.page-foot { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.page-foot .privacy-line { margin: 0 0 0 auto; }

#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 147, 188, 0.12);
  border: 3px dashed var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: var(--cyan);
  pointer-events: none;
}

#import-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(34, 37, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px 28px;
  width: min(420px, 100%);
  text-align: center;
}
.modal-card h2 { font-size: 17px; margin: 12px 0 4px; font-weight: 600; overflow-wrap: anywhere; }
.modal-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; min-height: 1.2em; }
.imp-track { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
#imp-bar { height: 100%; width: 0; background: var(--cyan); transition: width 0.2s; }

/* ---------- reader themes ---------- */
#reader-view {
  --rbg: #f6f5f2; --rsurface: #ffffff; --rfg: #26292e; --rmut: #6e7278; --rline: #e4e2dc; --raccent: #0093bc;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--rbg);
  color: var(--rfg);
  display: flex;
  flex-direction: column;
}
#reader-view[data-theme="sepia"] { --rbg: #f3e9d2; --rsurface: #faf3e3; --rfg: #433422; --rmut: #8a7a60; --rline: #e0d3b8; --raccent: #8a6c1f; }
#reader-view[data-theme="mist"]  { --rbg: #e8eaed; --rsurface: #f2f4f6; --rfg: #2b2f36; --rmut: #6b7280; --rline: #d3d7dd; --raccent: #0093bc; }
#reader-view[data-theme="dark"]  { --rbg: #1d2025; --rsurface: #272b31; --rfg: #d4d6da; --rmut: #8b8f96; --rline: #353a41; --raccent: #4db8d8; }
#reader-view[data-theme="black"] { --rbg: #000000; --rsurface: #101114; --rfg: #c9cbce; --rmut: #76797e; --rline: #232529; --raccent: #4db8d8; }

#reader-view .chrome {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--rsurface);
  border-color: var(--rline);
  padding: 8px 10px;
  z-index: 25;
  transition: transform 0.25s ease;
}
#top-bar { top: 0; border-bottom: 1px solid var(--rline); padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
#bottom-bar { bottom: 0; border-top: 1px solid var(--rline); padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
#top-bar.hidden { transform: translateY(-110%); }
#bottom-bar.hidden { transform: translateY(110%); }
.titles { flex: 1; min-width: 0; }
#rb-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#rb-chapter { color: var(--rmut); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#scroll-area { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
#chapter-content {
  margin: 0 auto;
  padding: calc(64px + env(safe-area-inset-top, 0px)) 20px 40px;
  max-width: var(--rwidth, 42rem);
  font-size: var(--r-size, 18px);
  line-height: var(--r-lh, 1.75);
}
#reader-view[data-width="s"] #chapter-content { --rwidth: 34rem; }
#reader-view[data-width="m"] #chapter-content { --rwidth: 42rem; }
#reader-view[data-width="l"] #chapter-content { --rwidth: 54rem; }
#reader-view[data-font="serif"] #chapter-content { font-family: var(--reading-serif); }
#reader-view[data-font="sans"] #chapter-content { font-family: var(--sans); }
#reader-view[data-font="system"] #chapter-content { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
#reader-view[data-justify="1"] #chapter-content p { text-align: justify; hyphens: auto; }
#chapter-content .ch-title {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.7em;
  line-height: 1.25;
  margin: 0 0 1.2em;
  text-wrap: balance;
}
#chapter-content p { margin: 0 0 1em; overflow-wrap: break-word; }
#chapter-content p.standalone { margin: 1.6em 0 1em; letter-spacing: 0.02em; }
#chapter-content ::selection { background: rgba(0, 147, 188, 0.25); }

.chapter-end {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 8px 20px calc(96px + env(safe-area-inset-bottom, 0px));
}
#reader-view .btn { background: var(--rsurface); border-color: var(--rline); color: var(--rfg); }
#reader-view .btn.primary { background: var(--raccent); border-color: var(--raccent); color: #fff; }
#reader-view[data-theme="black"] .btn.primary, #reader-view[data-theme="dark"] .btn.primary { color: #081318; }

#progress-slider { flex: 1; accent-color: var(--raccent); min-width: 0; }
#pct-label { font-size: 12px; color: var(--rmut); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
#auto-btn.on { color: var(--raccent); background: rgba(127, 127, 127, 0.12); }

/* ---------- sheets ---------- */
#toc-drawer, #settings-sheet {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 88vw);
  background: var(--rsurface);
  border-left: 1px solid var(--rline);
  z-index: 35;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top, 0px)) 0 env(safe-area-inset-bottom, 0px);
}
#toc-drawer header, #settings-sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rline);
  position: sticky;
  top: 0;
  background: var(--rsurface);
}
#toc-drawer h2, #settings-sheet h2 { font-size: 15px; margin: 0; font-weight: 600; }
#toc-list { list-style: none; margin: 0; padding: 8px; }
.toc-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.toc-item:hover { background: rgba(127, 127, 127, 0.1); }
.toc-item.current { background: rgba(0, 147, 188, 0.14); font-weight: 600; }
.toc-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-words { color: var(--rmut); font-size: 12px; flex-shrink: 0; }

#settings-sheet { padding-left: 16px; padding-right: 16px; }
#settings-sheet header { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.set-group { margin: 18px 0; }
.set-label, .set-group > label { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--rmut); margin-bottom: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.row-between label { margin: 0; text-transform: none; font-size: 14px; font-weight: 500; color: var(--rfg); letter-spacing: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pick-row { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--rline);
  font-weight: 600;
}
.swatch.auto { background: linear-gradient(135deg, #fff 50%, #1d2025 50%); color: var(--rfg); }
.swatch.paper { background: #f6f5f2; }
.swatch.sepia { background: #f3e9d2; }
.swatch.mist { background: #e8eaed; }
.swatch.dark { background: #1d2025; }
.swatch.black { background: #000; }
.swatch[aria-pressed="true"] { border-color: var(--raccent); box-shadow: 0 0 0 2px rgba(0, 147, 188, 0.25); }
.chip {
  border: 1px solid var(--rline);
  background: transparent;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
}
.chip.serif { font-family: var(--reading-serif); }
.chip[aria-pressed="true"] { border-color: var(--raccent); color: var(--raccent); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 4px; border: 1px solid var(--rline); border-radius: 8px; }
.stepper button { flex: 1; border: 0; background: transparent; font-size: 18px; padding: 7px 0; border-radius: 7px; }
.stepper span { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; }
.switch { width: 40px; height: 22px; accent-color: var(--raccent); }
#speed-range { width: 100%; accent-color: var(--raccent); }
.kbd-hint { color: var(--rmut); font-size: 12px; margin: 22px 0 16px; }

#scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 30; }

@media (max-width: 560px) {
  .two-col { grid-template-columns: 1fr; }
  .page-foot .privacy-line { margin-left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .dots.working i { animation: none; }
  #reader-view .chrome { transition: none; }
  .mini-bar span, #imp-bar { transition: none; }
  #scroll-area { scroll-behavior: auto; }
}
