/* ============================================================
   Horizont — online katalog stanova (flipbook)
   ============================================================ */

:root {
  --stage: #0e1217;
  --stage-lift: #1b2330;
  --paper: #eef2f8;
  --text: #e8edf4;
  --muted: #8f9bab;
  --mint: #a9d5a0;
  --line: rgba(255, 255, 255, 0.1);
  --chip: rgba(255, 255, 255, 0.06);
  --chip-hover: rgba(255, 255, 255, 0.13);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --bar-h: 56px;
  --tool-h: 68px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: var(--bar-h) 1fr var(--tool-h);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--stage);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 clamp(16px, 3vw, 32px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
.topbar__brand img {
  display: block;
  height: 17px;
  width: auto;
  filter: brightness(0) invert(1);
}
.topbar__title {
  padding-left: 18px;
  border-left: 1px solid var(--line);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.topbar__links { margin-left: auto; display: flex; gap: 6px; }
.topbar__link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
  transition: background 0.2s;
}
.topbar__link:hover { background: var(--chip); }
.topbar__link svg { width: 17px; height: 17px; }

/* ---------------- stage + book ---------------- */

.stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 60% at 50% 48%, var(--stage-lift), transparent 75%),
    var(--stage);
}

.book {
  position: relative;
  z-index: 1;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y pinch-zoom;
  cursor: pointer;
}
.book__shadow {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 2px;
  box-shadow:
    0 28px 60px -12px rgba(0, 0, 0, 0.7),
    0 10px 22px rgba(0, 0, 0, 0.35);
}
.book__sheets { position: absolute; inset: 0; }

.sheet {
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--pw);
  height: var(--ph);
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
.book--single .sheet { left: 0; }
.sheet.is-hidden { visibility: hidden; }
.sheet.is-moving { will-change: transform; }

.face {
  position: absolute;
  inset: 0;
  background: var(--paper) center / cover no-repeat;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face--back { transform: rotateY(180deg); }
.face--paper { background: linear-gradient(90deg, #dfe4ec, var(--paper) 30%); }

.face img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s;
  pointer-events: none;
}
.face img.is-loaded { opacity: 1; }

/* Gutter: the fold darkens toward the spine on inner pages. */
.face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.06) 2.5%, transparent 7%);
}
.face--back::after {
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.06) 2.5%, transparent 7%);
}
.face--cover::after { opacity: 0.35; }
.book--single .face::after { opacity: 0.45; }

/* Light and shadow on a page while it is in the air. --lift runs 0 → 1 → 0. */
.face .shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--lift, 0);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.08) 55%, rgba(255, 255, 255, 0.1));
}
.face--back .shade {
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.08) 55%, rgba(255, 255, 255, 0.1));
}
.face::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
  opacity: var(--lift, 0);
}

/* ---------------- side arrows ---------------- */

.side-nav {
  position: absolute;
  top: 50%;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--chip);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.side-nav:hover { background: var(--chip-hover); }
.side-nav:disabled { opacity: 0; pointer-events: none; }
.side-nav--prev { left: clamp(10px, 2vw, 28px); }
.side-nav--next { right: clamp(10px, 2vw, 28px); }
.side-nav svg { width: 24px; height: 24px; }

/* ---------------- hint ---------------- */

.hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 6;
  margin: 0;
  padding: 10px 18px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(14, 18, 23, 0.9);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  white-space: nowrap;
  color: var(--text);
  pointer-events: none;
  animation: hint-in 0.5s ease both;
  transition: opacity 0.4s;
}
.hint.is-leaving { opacity: 0; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------------- toolbar ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 12px;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
}
.toolbar__group { display: flex; align-items: center; gap: 6px; }
.toolbar__sep { width: 1px; height: 26px; background: var(--line); }

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 42px;
  height: 42px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, opacity 0.2s;
}
.tool:hover { background: var(--chip-hover); }
.tool:disabled { opacity: 0.3; pointer-events: none; }
.tool--labelled { padding: 0 16px 0 12px; background: var(--chip); }
.tool--accent { background: var(--mint); color: #13201a; font-weight: 600; }
.tool--accent:hover { background: #bfe3b8; }

.counter {
  min-width: 92px;
  text-align: center;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ---------------- overlays ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: rgba(9, 12, 16, 0.97);
  animation: fade-in 0.2s ease both;
}
.overlay[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }

.overlay__bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
  height: var(--bar-h);
  padding: 0 clamp(12px, 3vw, 28px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
.overlay__title {
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.overlay__bar .tool { margin-left: auto; }

/* grid of all pages */
.grid-panel__list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  align-content: start;
  gap: 22px 18px;
  padding: clamp(16px, 3vw, 36px);
}
.thumb {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}
.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4763 / 3368;
  border-radius: 3px;
  background: var(--paper);
  outline: 2px solid transparent;
  outline-offset: 3px;
  transition: outline-color 0.2s, transform 0.2s;
}
.thumb:hover img { transform: translateY(-2px); }
.thumb.is-current img { outline-color: var(--mint); }
.thumb span { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb.is-current span { color: var(--mint); }

/* zoom viewer */
.zoom__tip { font-size: 0.8rem; color: var(--muted); }
.zoom__viewport {
  position: relative;
  flex: 1;
  display: flex;
  overflow: auto;
  overscroll-behavior: contain;
  cursor: zoom-in;
}
.zoom__viewport.is-zoomed { cursor: grab; }
.zoom__viewport.is-panning { cursor: grabbing; }
/* margin:auto (not justify-content) keeps an overflowing image fully scrollable */
.zoom__img {
  display: block;
  flex: none;
  margin: auto;
  max-width: none;
  user-select: none;
  -webkit-user-select: none;
  background: var(--paper);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.zoom__nav { top: calc(50% + var(--bar-h) / 2); background: rgba(14, 18, 23, 0.78); }
.zoom__nav:hover { background: rgba(14, 18, 23, 0.92); }

/* ---------------- small screens ---------------- */

@media (max-width: 760px) {
  :root { --bar-h: 52px; --tool-h: 64px; }
  .topbar { gap: 12px; }
  .topbar__title { padding-left: 12px; font-size: 0.62rem; letter-spacing: 0.16em; }
  .topbar__link span { display: none; }
  .topbar__link { padding: 8px; }
  .side-nav:not(.zoom__nav) { display: none; }
  .tool--labelled span { display: none; }
  .tool--labelled { padding: 0 10px; }
  .toolbar { gap: 8px; }
  .counter { min-width: 70px; }
  .zoom__tip { display: none; }
  .hint { white-space: normal; width: max-content; max-width: calc(100% - 32px); text-align: center; }
  .zoom__nav { width: 42px; height: 42px; margin-top: -21px; background: rgba(14, 18, 23, 0.75); }
  .grid-panel__list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .hint, .overlay { animation: none; }
}
