.reader {
  --rd-bg: #1a130c;
  --rd-stage: #120d08;
  --rd-lamp: #2c2014;
  --rd-text: #ece2c8;
  --rd-dim: #bba67c;
  --rd-rule: rgba(217, 184, 120, .2);
  --rd-gold: #d9b878;
  --rd-hover: rgba(236, 226, 200, .09);
  --rd-paper: #f3ecdd;
  --rd-ease: cubic-bezier(.16, 1, .3, 1);

  padding: 0;
  border: 0;
  margin: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  background: transparent;
  color: var(--rd-text);
  font-family: 'Spectral', Georgia, serif;
  overflow: hidden;
}
[data-theme="dark"] .reader {
  --rd-bg: #0f1222;
  --rd-stage: #0a0c18;
  --rd-lamp: #1b2140;
  --rd-text: #e8dcc0;
  --rd-dim: #b3a074;
  --rd-hover: rgba(232, 220, 192, .08);
}
.reader::backdrop {
  background: rgba(14, 9, 5, .66);
  backdrop-filter: blur(4px);
}
[data-theme="dark"] .reader::backdrop { background: rgba(6, 8, 20, .7); }
.reader ::selection { background: var(--rd-gold); color: #1a130c; }
html:has(.reader[open]) { overflow: hidden; }

.reader-window {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
  background: var(--rd-bg);
  position: relative;
}

/* ===== Pasek tytułu ===== */
.reader-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 8px 8px 8px 16px;
  border-bottom: 1px solid var(--rd-rule);
}
.reader-title {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
  margin: 0;
  font-weight: 400;
}
.reader-series {
  display: none;
  flex: none;
  font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
  font-size: .75rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--rd-dim);
}
.reader-issue {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: .02em;
  text-wrap: balance;
}
.reader-tools { display: flex; align-items: center; gap: 2px; flex: none; }

.reader-btn,
.reader-zoom-level {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--rd-text);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, transform .1s ease;
}
.reader-btn:hover,
.reader-zoom-level:hover { background: var(--rd-hover); }
.reader-btn:active { transform: scale(.94); }
.reader-btn:disabled { opacity: .35; cursor: default; background: transparent; transform: none; }
.reader-btn:focus-visible,
.reader-zoom-level:focus-visible,
.reader-lens:focus-visible,
.reader-turn:focus-visible,
.reader-scrub:focus-visible { outline: 2px solid var(--rd-gold); outline-offset: 2px; }
.reader-btn[hidden] { display: none; }
.reader-icon { width: 20px; height: 20px; }
.reader-btn[aria-pressed="true"] { background: var(--rd-hover); color: var(--rd-gold); }

.reader-icon-exit, .reader-icon-done { display: none; }
.reader-btn[aria-pressed="true"] .reader-icon-enter { display: none; }
.reader-btn[aria-pressed="true"] .reader-icon-exit { display: block; }
.reader-btn-copy.is-done .reader-icon-link { display: none; }
.reader-btn-copy.is-done .reader-icon-done { display: block; color: var(--rd-gold); }

.reader-zoom {
  display: none;
  align-items: center;
  margin-right: 6px;
  padding: 1px;
  border: 1px solid var(--rd-rule);
  border-radius: 6px;
}
.reader-zoom .reader-btn { width: 38px; height: 38px; }
.reader-zoom .reader-scrub-zoom { width: 104px; height: 38px; margin: 0 4px 0 6px; }
.reader-zoom-level {
  width: auto;
  min-width: 3.5rem;
  height: 38px;
  font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
  font-size: .8125rem;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  color: var(--rd-dim);
}
.reader-sep { width: 1px; height: 24px; margin: 0 6px; background: var(--rd-rule); }
@media (max-width: 767px), (max-height: 599px) {
  .reader-bar { gap: 8px; }
  .reader-btn-copy, .reader-sep { display: none; }
}
@media (max-height: 599px) {
  .reader-bar { min-height: 48px; padding-top: 2px; padding-bottom: 2px; }
  .reader-issue { -webkit-line-clamp: 1; }
  .reader-foot { min-height: 52px; padding-top: 2px; padding-bottom: max(2px, env(safe-area-inset-bottom)); }
  .reader-nav { grid-auto-flow: column; grid-template-columns: auto minmax(0, 1fr); gap: 16px; width: 100%; }
}

/* ===== Scena ===== */
.reader-stage {
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse 62% 58% at 50% 48%, var(--rd-lamp), var(--rd-stage) 78%);
  outline: none;
}
.reader-stage.is-zoomed .reader-turn:not(:disabled) {
  color: var(--rd-text);
  background: color-mix(in srgb, var(--rd-bg) 88%, transparent);
  border-color: var(--rd-rule);
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .7);
}
.reader-book {
  position: absolute;
  inset: 12px 8px;
  opacity: 0;
  transition: opacity .35s ease;
}
.reader-book.is-ready { opacity: 1; }
.reader-book-mount { width: 100%; height: 100%; transition: transform .45s var(--rd-ease); }
.reader-spine {
  position: absolute;
  z-index: 2;
  width: 64px;
  margin-left: -32px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(40, 28, 14, .16) 42%, rgba(40, 28, 14, .3) 50%, rgba(40, 28, 14, .16) 58%, transparent);
}
.reader-spine[hidden] { display: none; }
.reader-book.is-covered { visibility: hidden; }

.reader-page { background: var(--rd-paper); overflow: hidden; }
.reader-page img { display: block; width: 100%; height: 100%; object-fit: fill; }
.reader-page img:not([src]) { visibility: hidden; }
.reader-page-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-style: italic;
  font-size: 1.5rem;
  color: #7a6a4c;
  font-variant-numeric: oldstyle-nums;
}
.reader-page.is-rendered .reader-page-num { display: none; }

.reader-turn {
  position: absolute;
  top: 50%;
  z-index: 5;
  display: none;
  place-items: center;
  width: 48px;
  height: 112px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--rd-dim);
  cursor: pointer;
  transform: translateY(-50%);
  transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}
.reader-turn .reader-icon { width: 28px; height: 28px; }
.reader-turn:hover:not(:disabled) { color: var(--rd-text); background: var(--rd-hover); border-color: var(--rd-rule); }
.reader-turn:disabled { opacity: .25; cursor: default; }
.reader-turn-prev { left: 12px; }
.reader-turn-next { right: 12px; }

.reader-lens {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  cursor: grab;
  scrollbar-color: rgba(217, 184, 120, .4) var(--rd-stage);
}
.reader-lens[hidden] { display: none; }
.reader-lens:focus-visible { outline-offset: -3px; }
.reader-lens.is-dragging { cursor: grabbing; user-select: none; }
.reader-lens-sheet { display: flex; margin: auto; padding: 12px 8px; }
.reader-lens-sheet canvas {
  display: block;
  background: var(--rd-paper);
  box-shadow: 0 18px 48px -18px rgba(0, 0, 0, .7);
}

.reader-status {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}
.reader-status[hidden] { display: none; }
.reader-status-cover { height: min(52vh, 460px); aspect-ratio: 2 / 3; }
.reader-status-cover img {
  display: block;
  height: 100%;
  width: auto;
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .8);
}
.reader-status-cover[hidden] { display: none; }
.reader-status-text {
  position: relative;
  margin: 0;
  padding-bottom: 10px;
  font-style: italic;
  color: var(--rd-dim);
}
.reader-status-text::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 120px;
  height: 1px;
  margin-left: -60px;
  background: linear-gradient(90deg, transparent, var(--rd-gold), transparent) 0 0 / 50% 100% no-repeat;
  animation: reader-sweep 1.4s ease-in-out infinite;
}
@keyframes reader-sweep {
  from { background-position: -100% 0; }
  to { background-position: 200% 0; }
}
.reader-status-error { display: grid; justify-items: center; gap: 18px; max-width: 34ch; pointer-events: auto; }
.reader-status-error[hidden] { display: none; }
.reader-status-error p { margin: 0; color: var(--rd-text); line-height: 1.6; }

/* ===== Stopka: foliacja i suwak ===== */
.reader-foot {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rd-rule);
}
.reader-nav { display: grid; justify-items: center; gap: 2px; min-width: 0; }
.reader-folio {
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: oldstyle-nums tabular-nums;
}
.reader-folio-pages { font-size: 1.1875rem; font-weight: 500; letter-spacing: .02em; }
.reader-folio-total { font-style: italic; color: var(--rd-dim); }

.reader-scrub {
  --fill: 0%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.reader-scrub::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--rd-gold) var(--fill), var(--rd-rule) var(--fill));
}
.reader-scrub::-moz-range-track { height: 2px; background: var(--rd-rule); }
.reader-scrub::-moz-range-progress { height: 2px; background: var(--rd-gold); }
.reader-scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -9px;
  border: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 1.5 18.5 10 10 18.5 1.5 10Z' fill='%231a130c' stroke='%23d9b878' stroke-width='1.4'/%3E%3Cpath d='M10 6 14 10 10 14 6 10Z' fill='%23d9b878'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform .15s ease;
}
.reader-scrub::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 1.5 18.5 10 10 18.5 1.5 10Z' fill='%231a130c' stroke='%23d9b878' stroke-width='1.4'/%3E%3Cpath d='M10 6 14 10 10 14 6 10Z' fill='%23d9b878'/%3E%3C/svg%3E") center / contain no-repeat;
}
.reader-scrub:hover::-webkit-slider-thumb,
.reader-scrub:active::-webkit-slider-thumb { transform: scale(1.2); }
.reader-scrub:disabled { opacity: .4; cursor: default; }

.reader-help { display: none; }

/* ===== Desktop: okno nad stroną ===== */
@media (max-width: 767px), (max-height: 599px) {
  .reader-bar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
  .reader-foot { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
}

@media (min-width: 768px) and (min-height: 600px) {
  .reader {
    width: min(100vw - 48px, 1680px);
    height: calc(100dvh - 48px);
    margin: auto;
    overflow: visible;
  }
  .reader-window {
    border: 1px solid var(--rd-rule);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 32px 90px -24px rgba(0, 0, 0, .75), 0 8px 24px -12px rgba(0, 0, 0, .5);
  }
  .reader-bar { padding-left: 24px; }
  .reader-series { display: inline; }
  .reader-issue { -webkit-line-clamp: 1; font-size: 1.125rem; }
  .reader-zoom { display: inline-flex; }
  .reader-btn-loupe { display: none; }
  .reader-book { inset: 24px 76px; }
  .reader-turn { display: grid; }
  .reader-foot { grid-template-columns: minmax(0, 1fr); min-height: 64px; padding: 8px 24px; }
  .reader-foot-turn { display: none; }
  .reader-nav { grid-auto-flow: column; grid-template-columns: auto minmax(0, 520px); justify-content: center; gap: 24px; width: 100%; }
  .reader-folio { min-width: 7.5em; text-align: right; }

  .reader-foot { position: relative; }
  .reader-help { position: absolute; top: 50%; right: 24px; z-index: 10; display: block; transform: translateY(-50%); }
  .reader-help-toggle {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--rd-rule);
    border-radius: 50%;
    background: transparent;
    color: var(--rd-dim);
    font-style: italic;
    font-size: 1.0625rem;
    line-height: 1;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease, background-color .15s ease;
  }
  .reader-help-toggle:focus-visible { outline: 2px solid var(--rd-gold); outline-offset: 2px; }
  .reader-help:hover .reader-help-toggle,
  .reader-help.is-open .reader-help-toggle { color: var(--rd-gold); border-color: color-mix(in srgb, var(--rd-gold) 55%, transparent); background: var(--rd-hover); }
  .reader-help-panel {
    position: absolute;
    right: -8px;
    bottom: calc(100% + 14px);
    width: 360px;
    padding: 16px 18px 14px;
    border: 1px solid var(--rd-rule);
    border-radius: 8px;
    background: var(--rd-bg);
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .8);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transform-origin: bottom right;
    transition: opacity .16s ease, transform .22s var(--rd-ease), visibility 0s linear .22s;
  }
  .reader-help-panel::after { content: ""; position: absolute; inset: 100% 0 -16px; }
  .reader-help:hover .reader-help-panel,
  .reader-help:focus-within .reader-help-panel,
  .reader-help.is-open .reader-help-panel {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity .16s ease .08s, transform .26s var(--rd-ease) .08s, visibility 0s;
  }
  .reader-help-head {
    margin: 0 0 6px;
    font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
    font-size: .6875rem;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--rd-gold);
  }
  .reader-help-list { display: grid; gap: 5px; margin: 0 0 14px; }
  .reader-help-list:last-child { margin-bottom: 0; }
  .reader-help-list div { display: grid; grid-template-columns: 6.75rem minmax(0, 1fr); gap: 14px; align-items: baseline; }
  .reader-help-list dt { white-space: nowrap; font-size: .875rem; color: var(--rd-text); }
  .reader-help-list dd { margin: 0; font-size: .875rem; line-height: 1.35; color: var(--rd-dim); }
  .reader-help kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 1px 5px;
    border: 1px solid var(--rd-rule);
    border-bottom-width: 2px;
    border-radius: 4px;
    font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
    font-size: .75rem;
    font-style: normal;
    line-height: 1.4;
    text-align: center;
    color: var(--rd-text);
    background: var(--rd-hover);
  }
}


/* ===== Wejście ===== */
.reader[open] .reader-window {
  transition: opacity .2s ease, transform .34s var(--rd-ease);
}
.reader[open]::backdrop { transition: opacity .25s ease; }
@starting-style {
  .reader[open] .reader-window { opacity: 0; transform: translateY(18px) scale(.985); }
  .reader[open]::backdrop { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .reader[open] .reader-window,
  .reader[open]::backdrop,
  .reader-book,
  .reader-btn,
  .reader-turn,
  .reader-book-mount,
  .reader-help-panel { transition: none; }
  .reader-status-text::after { animation: none; background-position: 50% 0; }
}
