:root{
  --bg: #ffffff;
  --fg: #111827;
  --muted:#4b5563;
  --card:#ffffff;
  --card2:#ffffff;
  --accent:#0a58ca;
  --backlink:#dc2626;
  --btn:#f3f4f6;
  --btnHover:#e5e7eb;
  --border: rgba(0,0,0,0.14);
  --shadow: 0 8px 24px rgba(0,0,0,0.08);
  --readerFontSize: 19px;
  --readerLineHeight: 1.78;
  --readerFontFamily: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  --glass: rgba(255,255,255,0.92);
}


/* ===== Themes (V3) ===== */
body[data-theme="light"]{
  /* defaults from :root */
}
body[data-theme="sepia"]{
  --bg: #f7f1e1;
  --fg: #1f2937;
  --muted:#4b5563;
  --card:#fffaf0;
  --card2:#fffaf0;
  --accent:#0a58ca;
  --backlink:#dc2626;
  --btn:#f3e7cf;
  --btnHover:#ead9b9;
  --border: rgba(0,0,0,0.14);
  --shadow: 0 10px 26px rgba(0,0,0,0.10);
  --glass: rgba(247,241,225,0.92);
}
body[data-theme="dark"]{
  --bg: #0b1220;
  --fg: #e5e7eb;
  --muted:#9ca3af;
  --card:#0f172a;
  --card2:#0f172a;
  --accent:#93c5fd;
  --backlink:#f87171;
  --btn:#111827;
  --btnHover:#1f2937;
  --border: rgba(255,255,255,0.14);
  --shadow: 0 10px 26px rgba(0,0,0,0.35);
  --glass: rgba(15,23,42,0.88);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color:var(--fg);
}

a{ color: var(--accent); text-decoration:none; }
a:hover{ text-decoration:underline; }

.container{
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.header{
  display:flex;
  gap:12px;
  align-items:flex-start;
  justify-content:space-between;
  margin-bottom: 14px;
}

.brand{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.brand h1{
  font-size: 20px;
  margin:0;
}
.brand .subtitle{
  color: var(--muted);
  font-size: 13px;
}

.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.chapters{
  list-style:none;
  padding:0;
  margin:0;
  display:grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 1024px){
  .chapters{ grid-template-columns: 1fr 1fr; }
}

.chapterLink{
  display:block;
  padding: 12px 12px;
  border-radius: 14px;
  background: var(--card2);
  border: 1px solid var(--border);
}
.chapterLink:hover{
  background: #fafafa;
}
.chapterLink .meta{
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.chapterLink .title{
  color: var(--fg);
  font-size: 15px;
  line-height: 1.2;
}

.volTitle{
  margin: 18px 0 10px;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* Reader page */
.readerHeader{
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  position: sticky;
  top: 0;
  backdrop-filter: blur(8px);
  z-index: 5;
}
.readerHeader .topRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}
.readerHeader .back{
  font-size: 14px;

  color: var(--backlink);
  font-weight: 600;
}
.readerHeader .back:visited{ color: var(--backlink); }
.readerHeader .back:hover{ color: var(--backlink); text-decoration: underline; }

.readerHeader .meta{
  color: var(--muted);
  font-size: 12px;
  text-align:right;
}
.readerHeader h1{
  margin: 10px 0 0;
  font-size: 18px;
  line-height:1.2;
}

.readerMain{
  min-height: calc(100vh - 180px);
  padding: 18px 16px 92px;
  max-width: 920px;
  margin: 0 auto;
}

.paraCard{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 16px;
  box-shadow: var(--shadow);
}


#para{
  margin:0;
  font-family: var(--readerFontFamily);
  font-size: var(--readerFontSize);
  line-height: var(--readerLineHeight);
}
#para p{ margin:0; }
.paraCard p{
  margin:0;
  font-family: var(--readerFontFamily);
  font-size: var(--readerFontSize);
  line-height: var(--readerLineHeight);
}
@media (min-width: 1024px){
  :root{ --readerFontSize: 20px; }
}
.paraCard p.center{ text-align:center; }
.paraCard p.justify{ text-align:justify; }

.controls{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px env(safe-area-inset-bottom);
  background: var(--glass);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  z-index: 6;
}
.controls .progress{
  color: var(--muted);
  font-size: 13px;
  text-align:center;
  flex: 1;
}

button{
  appearance:none;
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  cursor:pointer;
  min-width: 104px;
}
button:hover{ background: var(--btnHover); }
button:disabled{
  opacity: 0.45;
  cursor: not-allowed;
}

.hint{
  color: var(--muted);
  font-size: 12px;
  text-align:center;
  margin-top: 10px;
}

.swipeToast{
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1.2;
  z-index: 9999;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 22px rgba(0,0,0,0.18);
  opacity: 0;
  transition: opacity .25s ease;
}
.swipeToast.show{ opacity: .92; }
@media (max-width: 600px){
  .swipeToast{ bottom: 76px; font-size: 12.5px; padding: 9px 12px; }
}



/* ===== V2 improvements ===== */

/* Slightly wider homepage, but keep reading measure comfortable */
.container{ max-width: 980px; }

/* Reader: keep line length comfortable */
.readerMain{
  max-width: 780px;
}

/* Paragraph typography improvements */
.paraCard{
  padding: 22px 20px;
}
.paraCard p{
  font-family: var(--readerFontFamily);
  font-size: var(--readerFontSize);
  line-height: var(--readerLineHeight);
}
@media (max-width: 420px){
  .paraCard{ padding: 18px 16px; }
  :root{ --readerFontSize: 18px; --readerLineHeight: 1.75; }
}
@media (min-width: 900px){
  :root{ --readerFontSize: 21px; }
}

/* Progress (tap-to-jump) */
.controls .progress{
  display:flex;
  flex-direction:column;
  gap: 6px;
  align-items:center;
  justify-content:center;
  cursor: pointer;
  user-select:none;
}
.progressText{ font-size: 13px; color: var(--muted); }
.progressHint{ font-size: 11px; color: var(--muted); opacity: .8; }
.progressBar{
  width: 100%;
  max-width: 280px;
  height: 6px;
  background: rgba(0,0,0,0.10);
  border-radius: 999px;
  overflow:hidden;
}
.progressFill{
  height: 100%;
  width: 0%;
  background: rgba(0,0,0,0.42);
}

/* Make controls a bit taller to fit the progress bar comfortably */
.controls{
  padding-top: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* Header actions */
.readerHeader .topRow{
  gap: 10px;
}
.readerHeader .actions{
  display:flex;
  align-items:center;
  gap: 10px;
}
.iconBtn{
  border: 1px solid var(--border);
  background: var(--btn);
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 13px;
  cursor:pointer;
}
.iconBtn:hover{ background: var(--btnHover); }

/* Homepage: continue + search */
.homeTools{
  display:flex;
  flex-direction:column;
  gap: 10px;
  margin: 10px 0 14px;
}
@media (min-width: 1024px){
  .homeTools{ flex-direction:row; align-items:center; justify-content:space-between; flex-wrap:wrap; }
}
.searchBox{
  flex: 1;
  display:flex;
  flex-direction:column;
  gap: 6px;
  align-items:stretch;
}
.searchBox input{
  width: 100%;
  max-width: none;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
}
#searchCount{ min-width:0 !important; text-align:right; }
.continueCard{
  border: 1px dashed rgba(0,0,0,0.25);
  border-radius: 16px;
  padding: 12px 12px;
  background: #fff;
}
.continueCard .meta{ color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.continueCard .title{ color: var(--fg); font-size: 15px; line-height: 1.25; }
.continueCard .row{ display:flex; align-items:center; justify-content:space-between; gap: 10px; }
.continueCard .smallBtn{
  border: 1px solid var(--border);
  background: var(--btn);
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 13px;
  cursor:pointer;
  white-space: nowrap;
}
.continueCard .smallBtn:hover{ background: var(--btnHover); }

/* Optional highlight for last read chapter */
.chapterLink.lastRead{
  border-color: rgba(0,0,0,0.28);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
}


/* ===== V3 UI: settings + bookmarks + active buttons ===== */
.iconBtn.active{
  background: var(--accent);
  color: #ffffff;
  border-color: rgba(0,0,0,0.08);
}

.headerRight{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap: 8px;
}

.bookmarksCard{
  margin-top: 10px;
}
.bookmarkList{
  list-style:none;
  padding:0;
  margin: 0;
  display:flex;
  flex-direction:column;
  gap: 10px;
}
.bookmarkItem{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  border-radius: 14px;
  padding: 12px 12px;
}
.bookmarkItem .left{
  display:flex;
  flex-direction:column;
  gap: 4px;
  min-width: 0;
}
.bookmarkItem .left .bTitle{
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.bookmarkItem .left .bMeta{
  font-size: 12px;
  color: var(--muted);
}
.smallIconBtn{
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
  cursor:pointer;
}
.smallIconBtn:hover{ background: var(--btnHover); }

/* Settings modal */
.modalOverlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  display:none;
  align-items:center;
  justify-content:center;
  padding: 18px;
  z-index: 50;
}
.modalOverlay.show{ display:flex; }

.modal{
  width: 100%;
  max-width: 520px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow:hidden;
}
.modalHeader{
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}
.modalHeader h2{
  margin:0;
  font-size: 16px;
}
.modalBody{
  padding: 14px 16px 16px;
  display:flex;
  flex-direction:column;
  gap: 14px;
}
.setRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
}
.setRow .label{
  font-size: 13px;
  color: var(--muted);
}
.pills{
  display:flex;
  gap: 8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.pill{
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor:pointer;
}
.pill.active{
  background: var(--accent);
  color: #fff;
  border-color: rgba(0,0,0,0.08);
}
.range{
  display:flex;
  align-items:center;
  gap: 10px;
}
.range input[type="range"]{
  width: 180px;
}
.checkbox{
  display:flex;
  align-items:center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg);
}
.modalFooter{
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}


/* Home page tip */
.homeTip{
  display:inline-block;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--glass);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  max-width: 720px;
}
@media (max-width: 520px){
  .homeTip{
    display:block;
    width: 100%;
  }
}


/* Header domain link */
.headerRight .subtitle a{
  color: #ff2da6; /* bright pink */
  font-weight: 600;

}
.headerRight .subtitle a:visited{
  color: #ff2da6;
}
.headerRight .subtitle a:hover{
  color: #ff2da6;
  text-decoration: underline;
}


/* Header domain link sizing */
.headerRight .subtitle{
  font-size: 14px;
  margin-top: 8px;
}
.headerRight .subtitle a{
  font-weight: 600;
}
@media (max-width: 520px){
  .headerRight .subtitle{
    font-size: 13px;
  }
}


/* ===== Mobile polish ===== */
@media (max-width: 520px){
  /* Settings button: icon-only on mobile */
  .settingsBtn{
    font-size: 0;           /* hide "Settings" text */
    padding: 10px 12px;
    border-radius: 14px;
    min-width: 44px;
  }
  .settingsBtn::before{
    content: "⚙";
    font-size: 16px;
    line-height: 1;
  }

  /* Domain mark: smaller + calmer (still pink) */
  .headerRight .subtitle a{
    font-size: 12px;
    font-weight: 600;
    opacity: 0.9;
  }

  /* Continue card: solid border (less busy than dashed) */
  .continueCard{
    border-style: solid !important;
    background: var(--glass);
  }
}

@media (min-width: 1024px){
  .continueCard .title{ max-width: 60ch; }
}

/* Desktop overrides for search */
@media (min-width: 1024px){
  .searchBox{ flex-direction:row; align-items:center; justify-content:flex-end; gap: 10px; }
  .searchBox input{ max-width: 520px; min-width: 260px; }
}
