/* =====================================================================
   KOMIKO — the reader
   ---------------------------------------------------------------------
   A deliberately quiet room. Chrome fades away while you scroll and comes
   back on tap or mouse move. Pages are painted onto canvases rather than
   dropped into <img> tags, which costs a little complexity and buys two
   things: right-click-save does not hand over the file, and a per-account
   watermark can be composited into the pixels rather than layered over
   them in the DOM where it could simply be deleted.

   None of this stops a camera pointed at a screen. It stops the cheap,
   scalable copying that actually costs creators money.
   ===================================================================== */

.reader-root {
  background: #05070F;
  min-height: 100vh;
  padding-bottom: 0;
}
.reader-root .site-header,
.reader-root .site-footer,
.reader-root .bottom-nav { display: none; }

/* ------------------------------------------------------------------ */
/* Top bar                                                            */
/* ------------------------------------------------------------------ */

.reader-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  height: 56px;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding-inline: clamp(.75rem, 2vw, 1.25rem);
  background: linear-gradient(to bottom, rgb(5 7 15 / .96), rgb(5 7 15 / .78) 70%, transparent);
  color: #fff;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.reader-bar a { color: #fff; }

.reader-bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .85rem clamp(.75rem, 2vw, 1.25rem);
  padding-bottom: calc(.85rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgb(5 7 15 / .96), rgb(5 7 15 / .7) 60%, transparent);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}

/* Chrome hidden while actively scrolling down. */
.is-immersive .reader-bar    { opacity: 0; transform: translateY(-100%); pointer-events: none; }
.is-immersive .reader-bottom { opacity: 0; transform: translateY(100%);  pointer-events: none; }

.reader-title {
  min-width: 0;
  display: grid;
  line-height: 1.25;
}
.reader-title strong {
  font-size: var(--step--1);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-title span { font-size: var(--step--2); color: #9AA3C4; }

/* Thin progress line across the very top. */
.reader-progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  z-index: 50;
  transition: width .12s linear;
}

/* ------------------------------------------------------------------ */
/* Pages                                                              */
/* ------------------------------------------------------------------ */

.reader-stage {
  max-width: 900px;
  margin-inline: auto;
  padding-top: 56px;
  /* The stage itself refuses selection and the long-press menu. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.reader-stage.is-ltr,
.reader-stage.is-rtl {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding-block: 56px;
}

.page-slot {
  position: relative;
  width: 100%;
  background: #0A0E1C;
  margin-bottom: 2px;
  overflow: hidden;
}
.page-slot canvas {
  width: 100%;
  height: auto;
  display: block;
  /* Chromium honours this on drag; it is a speed bump, not a lock. */
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Blurred 4x4 average shown while the real page streams in. */
.page-slot .page-blur {
  position: absolute;
  inset: 0;
  filter: blur(22px);
  transform: scale(1.12);
  opacity: .55;
  transition: opacity .4s var(--ease);
}
.page-slot.is-loaded .page-blur { opacity: 0; }

.page-spinner {
  position: absolute;
  top: 50%; left: 50%;
  translate: -50% -50%;
  width: 30px; height: 30px;
  border: 2.5px solid rgb(255 255 255 / .14);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: page-spin .75s linear infinite;
}
.page-slot.is-loaded .page-spinner { display: none; }
@keyframes page-spin { to { transform: rotate(360deg); } }

.page-failed {
  display: grid;
  place-items: center;
  gap: .75rem;
  min-height: 240px;
  color: #7B85AB;
  font-size: var(--step--1);
  text-align: center;
  padding: 2rem;
}

/* ------------------------------------------------------------------ */
/* Watermark                                                          */
/* ------------------------------------------------------------------ */

/*
  A second, DOM-level tiling of the marker. The canvas composite is the one
  that actually survives a screenshot; this exists so the reader can SEE
  that their account is stamped on the page, which is most of the
  deterrent.
*/
.reader-watermark {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  opacity: .045;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #fff;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  gap: 3rem;
  align-content: center;
  justify-content: center;
  transform: rotate(-24deg) scale(1.5);
  letter-spacing: .1em;
  user-select: none;
}

/* ------------------------------------------------------------------ */
/* Controls                                                           */
/* ------------------------------------------------------------------ */

.reader-btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .55rem 1.1rem;
  border-radius: var(--r-full);
  background: rgb(255 255 255 / .09);
  border: 1px solid rgb(255 255 255 / .13);
  color: #fff;
  font-size: var(--step--1);
  font-weight: 700;
  backdrop-filter: blur(12px);
  transition: background .15s var(--ease);
}
.reader-btn:hover { background: rgb(255 255 255 / .16); color: #fff; }
.reader-btn:disabled { opacity: .35; pointer-events: none; }
.reader-btn svg { width: 16px; height: 16px; }
.reader-btn.is-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
}
.reader-btn.is-primary:hover { background: var(--gold-light); color: var(--gold-ink); }

.reader-icon {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: var(--r-full);
  color: #fff;
  background: rgb(255 255 255 / .07);
  transition: background .15s var(--ease);
}
.reader-icon:hover { background: rgb(255 255 255 / .16); }
.reader-icon svg { width: 18px; height: 18px; }

/* Chapter list slide-over */
.chapter-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 88vw);
  z-index: 90;
  background: var(--surface);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform .28s var(--ease);
  display: flex;
  flex-direction: column;
}
.chapter-drawer.is-open { transform: translateX(0); }
.chapter-drawer header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between;
}
.chapter-drawer .list { overflow-y: auto; padding: .5rem; flex: 1; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgb(5 7 15 / .65);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s var(--ease);
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

.chapter-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem .85rem;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: var(--step--1);
  transition: background .12s var(--ease);
}
.chapter-row:hover { background: var(--surface-2); color: var(--text); }
.chapter-row.is-current { background: rgb(255 184 0 / .12); color: var(--gold); font-weight: 700; }
.chapter-row .num {
  flex-shrink: 0;
  min-width: 42px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chapter-row .lock { margin-left: auto; opacity: .6; }
.chapter-row .lock svg { width: 14px; height: 14px; }

/* ------------------------------------------------------------------ */
/* End-of-chapter card                                                */
/* ------------------------------------------------------------------ */

.chapter-end {
  max-width: 560px;
  margin: 3rem auto 6rem;
  padding: 2rem 1.5rem;
  text-align: center;
}
.chapter-end h3 { color: #fff; margin-bottom: .5rem; }
.chapter-end p { color: #8892B8; margin-bottom: 1.5rem; }

.tip-row {
  display: flex;
  gap: .5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ------------------------------------------------------------------ */
/* Locked chapter screen                                              */
/* ------------------------------------------------------------------ */

.locked-screen {
  min-height: 72vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.locked-card {
  max-width: 460px;
  width: 100%;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: clamp(1.75rem, 4vw, 2.75rem);
}
.locked-icon {
  width: 62px; height: 62px;
  margin: 0 auto 1.25rem;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  background: rgb(255 184 0 / .12);
  color: var(--gold);
}
.locked-icon svg { width: 28px; height: 28px; }

/* ------------------------------------------------------------------ */
/* Settings popover                                                   */
/* ------------------------------------------------------------------ */

.reader-settings {
  position: fixed;
  bottom: 76px;
  left: 50%;
  translate: -50% 0;
  z-index: 45;
  width: min(320px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 1rem;
  display: none;
}
.reader-settings.is-open { display: block; }
.reader-settings .setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .55rem 0;
  font-size: var(--step--1);
  color: var(--text-2);
}

.width-options { display: flex; gap: .35rem; }
.width-options button {
  flex: 1;
  padding: .4rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  color: var(--text-3);
  font-size: var(--step--2);
  font-weight: 700;
}
.width-options button[aria-pressed='true'] {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
}

/* Reading width presets, applied to the stage. */
.reader-stage[data-width='narrow'] { max-width: 680px; }
.reader-stage[data-width='normal'] { max-width: 900px; }
.reader-stage[data-width='wide']   { max-width: 1200px; }
.reader-stage[data-width='full']   { max-width: 100%; }

@media print {
  /* Printing a chapter is not a supported way to read it. */
  .reader-stage, .page-slot, canvas { display: none !important; }
  body::after {
    content: 'Hindi puwedeng i-print ang mga kabanata sa Komiko.';
    display: block;
    padding: 4rem;
    text-align: center;
    font-size: 18px;
  }
}
