/* Listovací katalog HHW – prohlížeč (generuje scripts/flipbook/build_flipbook.py) */
:root {
  --green: #50af32;
  --green-ink: #3b8125;
  --green-soft: #e8f4e2;
  --dark: #002218;
  --ink: #2d3a31;
  --muted: #5c6b60;
  --line: #dfe5df;
  --stage: #e6eae6;
  --bar-h: 56px;
  --panel-w: 380px;
  --ease: cubic-bezier(.45, .05, .25, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: var(--bar-h) minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--stage);
  color: var(--ink);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- horní lišta ---------- */
.bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 20;
  min-width: 0;
}
.brand { display: flex; align-items: center; flex: none; }
.brand img { display: block; height: 34px; width: auto; }
.doc-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 16px;
  border-left: 1px solid var(--line);
  font-size: 15px;
}
.doc-title strong { font-weight: 600; color: var(--dark); }
.tools { display: flex; align-items: center; gap: 2px; flex: none; }
.tool {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.tool:hover { background: #f1f4f1; }
.tool[aria-pressed="true"] { background: var(--green-soft); color: var(--green-ink); }
.tool.icon-only { padding: 0 9px; }
.tool:disabled { opacity: .35; cursor: default; background: transparent; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.download {
  margin-left: 6px;
  background: var(--green);
  color: #fff;
  font-weight: 600;
}
.download:hover { background: var(--green-ink); }
.download small { font-weight: 400; opacity: .85; margin-left: 2px; }

/* ---------- scéna s knihou ---------- */
.stage {
  grid-row: 2;
  grid-column: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #f3f5f3 0%, var(--stage) 70%);
  min-height: 0;
}
.viewport {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: hidden;
  touch-action: none;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}
.viewport.zoomed {
  overflow: auto;
  touch-action: pan-x pan-y;
  cursor: grab;
  padding: 16px;
  overscroll-behavior: contain;
}
.viewport.zoomed.dragging { cursor: grabbing; }
.book {
  position: relative;
  margin: auto;
  flex: none;
  perspective: 2800px;
  transition: transform .55s var(--ease);
}
.book[data-shift="l"] { transform: translateX(-25%); }
.book[data-shift="r"] { transform: translateX(25%); }
.viewport.zoomed .book { transform: none; transition: none; }

.page {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .1), 0 12px 32px -10px rgba(0, 34, 24, .35);
  overflow: hidden;
}
.page.l { left: 0; }
.page.r { left: 50%; }
.page.s { left: 0; width: 100%; }
.page.empty { visibility: hidden; }
.book.solo .page { left: 0; width: 100%; }
.book.solo .page.empty { display: none; }
.page img, .face img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}
/* stín ve hřbetu */
.page.l::after, .page.r::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.page.l::after { background: linear-gradient(to left, rgba(0, 0, 0, .13), rgba(0, 0, 0, .03) 4%, transparent 9%); }
.page.r::after { background: linear-gradient(to right, rgba(0, 0, 0, .15), rgba(0, 0, 0, .03) 4%, transparent 9%); }
.book.solo .page::after { display: none; }

/* klikací oblasti (odkazy z PDF) */
.links { position: absolute; inset: 0; z-index: 2; }
.links a {
  position: absolute;
  display: block;
  border-radius: 2px;
  transition: background-color .15s, box-shadow .15s;
}
@media (hover: hover) {
  .links a:hover { background: rgba(80, 175, 50, .16); box-shadow: inset 0 0 0 1px rgba(80, 175, 50, .75); }
}
.links a:focus-visible { outline: 2px solid var(--green); outline-offset: 0; }
.links.flash a { animation: flash 1.6s ease-out 1; }
@keyframes flash {
  0%, 35% { background: rgba(80, 175, 50, .24); box-shadow: inset 0 0 0 1px rgba(80, 175, 50, .8); }
  100% { background: transparent; box-shadow: none; }
}

/* otáčený list */
.leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 5;
  transform-style: preserve-3d;
  transition: transform .65s var(--ease);
}
.leaf.right { left: 50%; transform-origin: 0 50%; }
.leaf.left { left: 0; transform-origin: 100% 50%; }
.leaf.right.go { transform: rotateY(-180deg); }
.leaf.left.go { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.face.back { transform: rotateY(180deg); }
.face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity .65s var(--ease);
}
.leaf.right .face.front::after { background: linear-gradient(to right, rgba(0, 0, 0, .25), transparent 60%); opacity: 0; }
.leaf.right.go .face.front::after { opacity: 1; }
.leaf.right .face.back::after { background: linear-gradient(to left, rgba(0, 0, 0, .28), transparent 60%); opacity: 1; }
.leaf.right.go .face.back::after { opacity: 0; }
.leaf.left .face.front::after { background: linear-gradient(to left, rgba(0, 0, 0, .25), transparent 60%); opacity: 0; }
.leaf.left.go .face.front::after { opacity: 1; }
.leaf.left .face.back::after { background: linear-gradient(to right, rgba(0, 0, 0, .28), transparent 60%); opacity: 1; }
.leaf.left.go .face.back::after { opacity: 0; }

/* jedna strana (mobil) */
.page.s.anim { transition: transform .28s var(--ease), opacity .28s var(--ease); }
.page.s.from-right { transform: translateX(35%); opacity: 0; }
.page.s.from-left { transform: translateX(-35%); opacity: 0; }
.page.s.leave-left { transform: translateX(-35%); opacity: 0; }
.page.s.leave-right { transform: translateX(35%); opacity: 0; }

/* šipky po stranách */
.turn {
  position: absolute;
  top: 50%;
  width: 46px;
  height: 46px;
  margin-top: -23px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  color: var(--dark);
  box-shadow: 0 2px 10px rgba(0, 34, 24, .18);
  z-index: 10;
  transition: opacity .2s, background-color .15s, color .15s;
}
.turn svg { width: 24px; height: 24px; stroke-width: 2.2; }
.turn:hover { background: var(--green); color: #fff; }
.turn.prev { left: 14px; }
.turn.next { right: 14px; }
.turn[disabled] { opacity: 0; pointer-events: none; }

.loading {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 3px solid rgba(80, 175, 50, .25);
  border-top-color: var(--green);
  animation: spin .8s linear infinite;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 9;
}
.loading.on { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- spodní lišta ---------- */
.pager {
  grid-row: 3;
  grid-column: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas: "chap ctrl scrub";
  align-items: center;
  column-gap: 16px;
  height: 52px;
  padding: 0 16px;
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid var(--line);
  z-index: 20;
}
.pg-ctrl { grid-area: ctrl; display: flex; align-items: center; gap: 2px; }
.pg-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
}
.pg-btn:hover { background: #f1f4f1; }
.pg-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.goto { display: flex; align-items: center; gap: 6px; margin: 0 6px; }
.goto input {
  width: 92px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9f7;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--dark);
}
.goto input.txt { font-size: 12px; font-weight: 600; padding: 0 4px; }
.goto input:focus { border-color: var(--green); background: #fff; outline: none; box-shadow: 0 0 0 3px rgba(80, 175, 50, .18); }
.goto .total { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chapter-now {
  grid-area: chap;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}
.chapter-now b { color: var(--green-ink); font-weight: 600; }
.scrub { grid-area: scrub; position: relative; display: flex; align-items: center; justify-content: flex-end; min-width: 0; }
.scrub input {
  --fill: 0%;
  width: 100%;
  max-width: 360px;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.scrub input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--green) var(--fill), var(--line) var(--fill));
}
.scrub input::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
.scrub input::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--green); }
.scrub input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 1px 4px rgba(0, 34, 24, .35);
}
.scrub input::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 1px 4px rgba(0, 34, 24, .35);
}
.scrub input:focus-visible { outline: none; }
.scrub input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(80, 175, 50, .3); }
.scrub-tip {
  position: absolute;
  bottom: 34px;
  right: 0;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--dark);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- boční panel ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 34, 24, .35);
  z-index: 40;
}
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(100%, var(--panel-w));
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: -8px 0 30px rgba(0, 34, 24, .18);
  z-index: 50;
  animation: panel-in .22s var(--ease);
}
@keyframes panel-in { from { transform: translateX(30px); opacity: 0; } }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 10px 18px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--dark); }
.panel-close { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 8px; background: transparent; }
.panel-close:hover { background: #f1f4f1; }
.panel-search { padding: 14px 16px 6px; flex: none; }
.panel-search input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9f7;
}
.panel-search input:focus { border-color: var(--green); background: #fff; outline: none; box-shadow: 0 0 0 3px rgba(80, 175, 50, .18); }
.search-info { margin: 8px 2px 4px; color: var(--muted); font-size: 13px; }
.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 0 16px; }

@media (min-width: 1100px) {
  body.panel-open { grid-template-columns: minmax(0, 1fr) var(--panel-w); }
  body.panel-open .panel {
    position: relative;
    grid-row: 2 / 4;
    grid-column: 2;
    width: auto;
    box-shadow: none;
    border-left: 1px solid var(--line);
    z-index: 15;
    animation: none;
  }
  body.panel-open .scrim { display: none; }
}

/* obsah kapitol */
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  padding: 10px 18px 10px 15px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
}
.toc-item:hover { background: #f4f7f4; }
.toc-item .tt { flex: 1; }
.toc-item .pn { color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-item.on { border-left-color: var(--green); background: var(--green-soft); color: var(--dark); font-weight: 600; }
.toc-item.on .pn { color: var(--green-ink); }

/* přehled stránek */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px 12px; padding: 10px 16px; }
.thumb { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.thumb img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--ar);
  background: #f1f4f1;
  box-shadow: 0 0 0 1px var(--line);
  transition: box-shadow .15s;
}
.thumb:hover img { box-shadow: 0 0 0 2px var(--green); }
.thumb.on img { box-shadow: 0 0 0 3px var(--green); }
.thumb.on { color: var(--green-ink); font-weight: 600; }
.grid-chap {
  grid-column: 1 / -1;
  margin: 10px 0 -4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--dark);
  font-weight: 600;
  font-size: 13px;
}
.grid-chap:first-child { border-top: 0; margin-top: 0; padding-top: 0; }

/* výsledky hledání */
.results { list-style: none; margin: 0; padding: 0; }
.result {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 9px 16px;
  border: 0;
  background: transparent;
  text-align: left;
  align-items: flex-start;
}
.result:hover { background: #f4f7f4; }
.result.on { background: var(--green-soft); }
.result img { width: 46px; height: auto; aspect-ratio: var(--ar); flex: none; box-shadow: 0 0 0 1px var(--line); background: #f1f4f1; }
.result .rt { min-width: 0; }
.result .rp { font-weight: 600; color: var(--dark); }
.result .rp span { font-weight: 400; color: var(--muted); }
.result .rd { color: var(--ink); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result mark { background: #d4edc6; color: inherit; border-radius: 2px; padding: 0 1px; }
.empty-msg { padding: 18px; color: var(--muted); }

/* tip */
.toast {
  position: fixed;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 10px 14px 10px 16px;
  border-radius: 10px;
  background: var(--dark);
  color: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 60;
  animation: toast-in .3s var(--ease);
}
.toast button { border: 0; background: transparent; color: #c3d6ca; padding: 4px; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.noscript { position: fixed; inset: auto 0 50% 0; text-align: center; font-size: 16px; }
.noscript a { color: var(--green-ink); font-weight: 600; }

/* ---------- menší obrazovky ---------- */
@media (max-width: 1000px) {
  .tool span { display: none; }
  .tool { padding: 0 9px; }
  .download span { display: inline; }
  .download small { display: none; }
}
@media (max-width: 760px) {
  :root { --bar-h: 52px; }
  .bar { gap: 8px; padding: 0 6px 0 12px; }
  .brand img { height: 28px; }
  .doc-title { display: none; }
  .tools { flex: 1; justify-content: flex-end; }
  .sep, .zoom-btn { display: none; }
  .download { margin-left: 2px; }
  .pager { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "ctrl scrub"; padding: 0 8px; column-gap: 8px; }
  .chapter-now { display: none; }
  .pg-btn[data-act="first"], .pg-btn[data-act="last"] { display: none; }
  .goto input { width: 78px; }
  .turn { width: 38px; height: 38px; margin-top: -19px; opacity: .85; }
  .turn.prev { left: 6px; }
  .turn.next { right: 6px; }
  .toast { bottom: 64px; }
}
@media (max-width: 600px) {
  .turn { display: none; }
}
@media (max-width: 420px) {
  .download span { display: none; }
  .scrub { display: none; }
  .pager { grid-template-columns: 1fr; grid-template-areas: "ctrl"; justify-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
