:root {
  color-scheme: dark;
  --bg: #12171d;
  --bg-soft: #1b232c;
  --panel: #202832;
  --panel-2: #293441;
  --paper: #f4efe4;
  --paper-shadow: rgba(0, 0, 0, .35);
  --text: #eef2f5;
  --muted: #aeb9c4;
  --accent: #b1473d;
  --accent-hover: #cb5a4e;
  --line: rgba(255, 255, 255, .11);
  --page-ratio: .7;
  --radius: 16px;
  --topbar-height: 76px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 78% 10%, rgba(177, 71, 61, .12), transparent 28rem),
    linear-gradient(180deg, #1b2229 0%, var(--bg) 55%);
  color: var(--text);
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem clamp(1rem, 3vw, 2.5rem);
  background: rgba(18, 23, 29, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .8rem;
  border: 0;
  padding: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 50%;
  background: linear-gradient(145deg, #2d3742, #171d23);
  color: #f6f1e8;
  font-family: Georgia, serif;
  font-weight: 700;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.03);
}
.brand-text { display: grid; gap: .1rem; }
.brand-text strong { font-family: Georgia, serif; font-size: clamp(.93rem, 1.4vw, 1.13rem); }
.brand-text small { color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: .45rem; }
.toolbar-button,
.icon-button,
.text-button,
.page-control button,
.primary-action,
.secondary-action,
.resume-link,
.search-form button,
.zoom-step {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background .18s ease, transform .18s ease, border-color .18s ease;
}
.toolbar-button {
  display: inline-flex;
  align-items: center;
  gap: .42rem;
  padding: .62rem .82rem;
  font-size: .9rem;
}
.toolbar-button:hover,
.icon-button:hover,
.text-button:hover,
.page-control button:hover,
.secondary-action:hover,
.search-form button:hover,
.zoom-step:hover { background: var(--panel-2); border-color: rgba(255,255,255,.24); }

.landing {
  min-height: calc(100vh - var(--topbar-height));
  display: grid;
  place-items: center;
  padding: clamp(2rem, 5vw, 5rem) clamp(1rem, 5vw, 5rem);
}
.landing-inner {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: minmax(260px, 410px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(2rem, 6vw, 6rem);
}
.cover-card {
  margin: 0;
  perspective: 1800px;
}
.cover-card img {
  display: block;
  width: 100%;
  aspect-ratio: 7 / 10;
  object-fit: cover;
  border-radius: 3px 12px 12px 3px;
  box-shadow: -14px 18px 38px rgba(0,0,0,.52), 12px 8px 25px rgba(0,0,0,.32);
  transform: rotateY(8deg) rotateX(1deg);
  transform-origin: left center;
}
.book-intro { max-width: 700px; }
.eyebrow {
  margin: 0 0 .8rem;
  color: #d1796f;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.book-intro h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.25rem, 4.7vw, 4.9rem);
  font-weight: 500;
  line-height: .97;
  letter-spacing: -.04em;
}
.author {
  margin: 1rem 0 1.4rem;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  color: #e3e7eb;
}
.description {
  max-width: 68ch;
  margin: 1.25rem 0 0;
  color: #cad2d9;
  font-size: clamp(.96rem, 1.15vw, 1.08rem);
  line-height: 1.62;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  overflow: hidden;
}
.motto { margin: 1.3rem 0; font-family: Georgia, serif; font-style: italic; color: #e8dfd2; }
.book-facts { display: flex; flex-wrap: wrap; gap: .7rem; margin: 1.5rem 0; }
.book-facts span {
  padding: .55rem .8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.025);
}
.book-facts strong { color: var(--text); }
.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  margin-top: 1.15rem;
  position: relative;
  z-index: 3;
}
.primary-action, .secondary-action { padding: .88rem 1.25rem; font-weight: 750; }
.primary-action { background: var(--accent); border-color: var(--accent); }
.primary-action:hover { background: var(--accent-hover); transform: translateY(-1px); }
.secondary-action { display: inline-flex; align-items: center; background: transparent; }
.resume-link {
  margin-top: 1rem;
  padding: .65rem .85rem;
  background: transparent;
  color: #e0b3ae;
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.reader {
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
  background: #11161b;
}
.reader-toolbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  flex-wrap: wrap;
  padding: .7rem clamp(.55rem, 2vw, 1.4rem);
  border-bottom: 1px solid var(--line);
  background: rgba(28, 35, 43, .96);
}
.icon-button { min-width: 42px; min-height: 40px; padding: .45rem .75rem; font-size: 1.18rem; }
.text-button { min-height: 40px; padding: .48rem .75rem; }
.page-control { display: flex; align-items: center; gap: .42rem; }
.page-control label { color: var(--muted); font-size: .86rem; }
.page-control input {
  width: 72px;
  height: 40px;
  padding: .35rem .5rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #11171d;
  color: var(--text);
  text-align: center;
}
.page-control span { min-width: 74px; color: var(--muted); font-size: .85rem; text-align: center; }
.page-control button { height: 40px; padding: .4rem .7rem; }
.progress-range { width: min(260px, 24vw); accent-color: var(--accent); }
.reader-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: clamp(.65rem, 2vh, 1.5rem);
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,.055), transparent 58%),
    repeating-linear-gradient(90deg, transparent 0 56px, rgba(255,255,255,.012) 57px 58px),
    #0c1014;
}
.book {
  position: relative;
  width: min(94vw, calc((100vh - 190px) * 1.4), 1240px);
  aspect-ratio: 1.4 / 1;
  perspective: 2600px;
  filter: drop-shadow(0 26px 22px rgba(0,0,0,.44));
}
.page-slot,
.turn-sheet,
.sheet-face {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
}
.page-slot {
  overflow: hidden;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(40,35,30,.08);
}
.left-page { left: 0; border-radius: 7px 0 0 7px; }
.right-page { right: 0; border-radius: 0 7px 7px 0; }
.left-page::after,
.right-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.left-page::after { background: linear-gradient(90deg, rgba(0,0,0,.08), transparent 7%, transparent 84%, rgba(0,0,0,.18)); }
.right-page::after { background: linear-gradient(90deg, rgba(0,0,0,.2), transparent 16%, transparent 94%, rgba(0,0,0,.06)); }
.page-content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #f7f3e9;
}
.page-content img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}
.page-content.blank {
  background:
    linear-gradient(90deg, rgba(80,68,50,.04), transparent 12%),
    #f5f0e5;
}
.page-content.loading::before {
  content: "";
  width: 34px;
  height: 34px;
  border: 3px solid rgba(30,30,30,.14);
  border-top-color: rgba(30,30,30,.55);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.page-content.error::before { content: "Nie udało się wczytać strony"; color: #6d302a; font-size: .8rem; }
.turn-sheet {
  display: none;
  z-index: 12;
  transform-style: preserve-3d;
  transition: transform .72s cubic-bezier(.22,.61,.36,1);
}
.turn-sheet.active { display: block; }
.turn-sheet.forward { left: 50%; transform-origin: left center; transform: rotateY(0deg); }
.turn-sheet.forward.turning { transform: rotateY(-180deg); }
.turn-sheet.backward { left: 0; transform-origin: right center; transform: rotateY(0deg); }
.turn-sheet.backward.turning { transform: rotateY(180deg); }
.sheet-face {
  inset: 0;
  width: 100%;
  backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 18px rgba(0,0,0,.26);
}
.sheet-front { transform: rotateY(0deg); }
.sheet-back { transform: rotateY(180deg); }
.turn-sheet.forward .sheet-front::after,
.turn-sheet.backward .sheet-back::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.18), transparent 28%, rgba(255,255,255,.08));
  pointer-events: none;
}
.edge-zone {
  position: absolute;
  z-index: 30;
  top: 0;
  bottom: 0;
  width: 14%;
  min-width: 48px;
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
}
.edge-prev { left: 0; }
.edge-next { right: 0; }
.edge-zone:hover { background: linear-gradient(90deg, rgba(177,71,61,.14), transparent 70%); }
.edge-next:hover { background: linear-gradient(-90deg, rgba(177,71,61,.14), transparent 70%); }
.edge-zone:focus-visible {
  outline: 2px solid rgba(177,71,61,.75);
  outline-offset: -2px;
}
.mobile-book { display: none; position: relative; perspective: 2200px; }
.mobile-page,
.mobile-turn,
.mobile-face {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  overflow: hidden;
  background: var(--paper);
}
.mobile-book { width: min(94vw, calc((100vh - 180px) * .7)); aspect-ratio: .7 / 1; filter: drop-shadow(0 22px 20px rgba(0,0,0,.45)); }
.mobile-turn { display: none; z-index: 4; transform-style: preserve-3d; transition: transform .64s cubic-bezier(.22,.61,.36,1); }
.mobile-turn.active { display: block; }
.mobile-turn.forward { transform-origin: left center; transform: rotateY(0); }
.mobile-turn.forward.turning { transform: rotateY(-180deg); }
.mobile-turn.backward { transform-origin: right center; transform: rotateY(0); }
.mobile-turn.backward.turning { transform: rotateY(180deg); }
.mobile-face { backface-visibility: hidden; }
.mobile-back { transform: rotateY(180deg); }
.loading-indicator {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  padding: .38rem .65rem;
  border-radius: 999px;
  background: rgba(0,0,0,.66);
  color: #dbe2e8;
  font-size: .78rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.loading-indicator.visible { opacity: 1; }
.reader-hint { margin: 0; padding: .48rem 1rem .65rem; text-align: center; color: #84909b; font-size: .78rem; background: #11161b; }

.drawer {
  position: fixed;
  z-index: 80;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: 100vh;
  padding: 1rem;
  background: #171e25;
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 45px rgba(0,0,0,.4);
  transform: translateX(105%);
  transition: transform .25s ease;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding-bottom: .8rem; }
.drawer-header h2 { margin: 0; font-family: Georgia, serif; font-weight: 500; }
.close-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #202832;
  color: var(--text);
  font-size: 1.45rem;
  cursor: pointer;
}
.toc-list { display: grid; gap: .25rem; padding: 1rem 0; }
.toc-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: .85rem .7rem;
  border: 0;
  border-bottom: 1px solid rgba(255,255,255,.065);
  background: transparent;
  color: #e5e9ec;
  text-align: left;
  cursor: pointer;
}
.toc-item:hover { background: rgba(255,255,255,.045); }
.toc-page { color: var(--muted); }

.modal {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: none;
  place-items: center;
  padding: 1rem;
}
.modal.open { display: grid; }
.modal-panel {
  width: min(760px, 96vw);
  max-height: min(82vh, 850px);
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #171e25;
  box-shadow: 0 30px 70px rgba(0,0,0,.55);
}
.search-form { display: grid; grid-template-columns: 1fr auto; gap: .6rem; margin: 1rem 0; }
.search-form input {
  min-width: 0;
  height: 46px;
  padding: .65rem .8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f1419;
  color: var(--text);
}
.search-form button { padding: .65rem 1rem; }
.search-status { color: var(--muted); font-size: .88rem; }
.search-results { display: grid; gap: .55rem; }
.search-result {
  padding: .82rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1f2730;
  cursor: pointer;
}
.search-result:hover { border-color: rgba(255,255,255,.23); }
.search-result strong { color: #efb4ad; }
.search-result p { margin: .35rem 0 0; color: #c6cfd6; line-height: 1.45; font-size: .88rem; }
.search-result mark { background: #704139; color: #fff; padding: 0 .12em; }
.backdrop {
  position: fixed;
  z-index: 70;
  inset: 0;
  background: rgba(0,0,0,.64);
  backdrop-filter: blur(2px);
}
.zoom-modal { padding: 0; background: #0c1014; }
.zoom-modal.open { display: flex; flex-direction: column; }
.zoom-toolbar {
  flex: 0 0 auto;
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  padding: .6rem;
  border-bottom: 1px solid var(--line);
  background: #171e25;
}
.zoom-toolbar strong { margin: 0 .7rem; font-family: Georgia, serif; font-weight: 500; }
.zoom-step { width: 40px; height: 40px; font-size: 1.15rem; }
.zoom-scroll { flex: 1; width: 100%; overflow: auto; display: grid; justify-items: center; align-items: start; padding: 1.4rem; }
.zoom-scroll img { display: block; width: min(70vw, 900px); height: auto; box-shadow: 0 20px 55px rgba(0,0,0,.5); background: var(--paper); }

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem clamp(1rem, 3vw, 2.5rem);
  border-top: 1px solid var(--line);
  color: #8e9aa5;
  background: #0d1216;
  font-size: .8rem;
}
.site-footer a { color: #c5ced5; text-underline-offset: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }


@media (min-width: 761px) and (max-height: 820px) {
  .landing { padding-block: 1.25rem; }
  .landing-inner { grid-template-columns: minmax(220px, 330px) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3.5rem); }
  .book-intro h1 { font-size: clamp(2rem, 4.2vw, 4rem); }
  .author { margin: .7rem 0 .9rem; }
  .description { -webkit-line-clamp: 4; margin-top: .9rem; }
  .book-facts { margin: .9rem 0; }
}

@media (max-width: 760px) {
  :root { --topbar-height: 66px; }
  .topbar { padding: .55rem .7rem; }
  .brand-mark { width: 42px; height: 42px; font-size: .88rem; }
  .brand-text strong { font-size: .82rem; }
  .brand-text small { font-size: .7rem; }
  .toolbar-button { width: 42px; height: 42px; justify-content: center; padding: 0; }
  .toolbar-button span { display: none; }
  .landing { padding: 1.5rem 1rem 2.5rem; }
  .landing-inner { grid-template-columns: minmax(0, 1fr); gap: 1.7rem; }
  .cover-card { width: min(76vw, 330px); margin-inline: auto; }
  .book-intro { text-align: center; }
  .book-intro h1 { font-size: clamp(2.4rem, 12vw, 4rem); }
  .description { text-align: left; }
  .book-facts, .landing-actions { justify-content: center; }
  .reader-toolbar { gap: .35rem; padding: .55rem .4rem; }
  .page-control label, .page-control span, .page-control button { display: none; }
  .page-control input { width: 60px; }
  .progress-range { order: 20; width: 92vw; }
  .text-button { padding: .45rem .58rem; font-size: .82rem; }
  .desktop-book { display: none; }
  .mobile-book { display: block; }
  .reader-stage { padding: .55rem; }
  .reader-hint { font-size: .7rem; }
  .zoom-toolbar { gap: .3rem; flex-wrap: wrap; }
  .zoom-toolbar strong { width: 100%; order: -1; text-align: center; margin: 0; }
  .zoom-scroll { padding: .75rem; }
  .zoom-scroll img { width: 92vw; }
  .site-footer { font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}


/* TNG Publication Library generic reader additions */
.page-content canvas { display:block; width:100%; height:100%; object-fit:fill; }
.reader-error {
  margin-top:1.2rem;
  padding:1rem 1.1rem;
  border:1px solid rgba(203,90,78,.55);
  border-radius:12px;
  background:rgba(177,71,61,.12);
  color:#f2d8d4;
  line-height:1.55;
}
.reader-error a { font-weight:700; text-decoration:underline; }
.toc-empty { padding:1rem .7rem; color:var(--muted); line-height:1.55; }
.loading-indicator.visible { opacity:1; }
@media (max-width:760px) {
  .brand-text strong { max-width:48vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
}

/* v1.3.0: readable spread zoom, scrollable single-page view and deep-link controls */
.reader-stage {
  display: block;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.book {
  width: min(96vw, 1660px);
  max-width: none;
  margin: 0 auto;
  flex: 0 0 auto;
}
.mobile-book { margin: 0 auto; }
.page-content img { object-fit: contain; background: #fff; }
.spread-zoom {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #151c22;
}
.spread-zoom .zoom-step { width: 34px; height: 34px; }
.spread-zoom span { min-width: 48px; text-align: center; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.fit-button { min-height: 34px; padding: .35rem .55rem; font-size: .8rem; }
.copy-status { min-width: 1px; color: #b9d7be; font-size: .78rem; }
.zoom-modal { overflow: hidden; }
.zoom-scroll {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  cursor: grab;
}
.zoom-scroll.is-panning { cursor: grabbing; }
.zoom-scroll img {
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: pan-x pan-y;
}
@media (min-width: 761px) {
  .reader-stage { padding: 1rem; }
}
@media (max-width: 760px) {
  .spread-zoom { display: none; }
  #copyLocationButton { width: 42px; height: 42px; overflow: hidden; font-size: 0; padding: 0; }
  #copyLocationButton::before { content: "🔗"; font-size: 1rem; }
  .zoom-scroll { justify-items: start; padding: .5rem; }
  .zoom-scroll img { width: 92vw; }
  .copy-status { width: 100%; text-align: center; order: 10; }
}

/* v1.3.6: desktop mouse dragging for page turns and panning */
@media (min-width: 761px) {
  .reader-stage,
  .reader-stage .desktop-book { cursor: grab; }
  .reader-stage.is-dragging,
  .reader-stage.is-dragging .desktop-book,
  .reader-stage.is-dragging .edge-zone { cursor: grabbing; }
  .reader-stage.is-dragging { user-select: none; }
}
