:root {
  --bg: #0f1f1e;
  --bg-2: #1c3532;
  --ink: #f3efe6;
  --muted: #a9b8b3;
  --line: rgba(243, 239, 230, .16);
  --accent: #e9b949;
  --bar-h: 56px;
  --foot-h: 40px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, var(--bg-2) 0%, var(--bg) 70%);
  color: var(--ink);
  font: 15px/1.4 "Heebo", "Assistant", "Arial Hebrew", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- top bar ---------- */
.bar {
  flex: 0 0 var(--bar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { font-weight: 400; color: var(--muted); margin-inline-start: 8px; }

.actions { display: flex; align-items: center; gap: 4px; flex: none; }
.actions button, .actions a:not(.cta), .close {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.actions button:hover, .actions a:not(.cta):hover, .close:hover { background: rgba(255, 255, 255, .1); }
.cta {
  margin-inline-start: 8px; padding: 9px 16px; border-radius: 999px;
  background: var(--accent); color: #1c1a10; font-weight: 700; text-decoration: none; white-space: nowrap;
}
.cta:hover { filter: brightness(1.07); }
.cta-short { display: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- stage ---------- */
.stage {
  flex: 1 1 auto; min-height: 0;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 16px 64px;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}
.touch #book { touch-action: pan-y pinch-zoom; }
.shift { transition: transform .55s cubic-bezier(.3, .7, .2, 1); }
.book-size { width: 300px; opacity: 0; transition: opacity .35s; }
.book-size.ready { opacity: 1; }
/* app.js steers spread vs single page through the library's minWidth setting; keep that out of the layout */
#book { min-width: 0 !important; min-height: 0 !important; max-width: none !important; }
#book { filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .45)); }

.page { background: #14201f; overflow: hidden; }
.page img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; pointer-events: none; }

.nav {
  position: absolute; top: 50%; z-index: 5;
  width: 46px; height: 46px; margin-top: -23px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  background: rgba(15, 31, 30, .7); color: var(--ink); cursor: pointer;
  transition: opacity .2s, background .2s;
}
.nav:hover { background: rgba(255, 255, 255, .14); }
.nav:disabled { opacity: .25; cursor: default; }
.nav-prev { right: 10px; }
.nav-next { left: 10px; }

/* ---------- footer ---------- */
.foot {
  flex: 0 0 var(--foot-h);
  display: flex; align-items: center; justify-content: center; gap: 18px;
  padding-bottom: env(safe-area-inset-bottom);
  color: var(--muted); font-size: 13px;
}
#counter { color: var(--ink); font-variant-numeric: tabular-nums; }
.hint { transition: opacity .6s; }
.hint.gone { opacity: 0; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: rgba(8, 16, 15, .96);
}
.overlay[hidden] { display: none; }
.overlay-head {
  flex: 0 0 var(--bar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--line); font-weight: 700;
}
.close { font-size: 18px; }

.thumbs {
  flex: 1; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 18px;
  padding: 20px 16px 32px; width: 100%; max-width: 980px; margin: 0 auto; align-content: start;
}
.thumbs button {
  padding: 0; border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px;
}
.thumbs img {
  display: block; width: 100%; aspect-ratio: 595 / 841; margin-bottom: 6px;
  border-radius: 4px; outline: 2px solid transparent; outline-offset: 2px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .5);
}
.thumbs button:hover img, .thumbs button[aria-current="true"] img { outline-color: var(--accent); }
.thumbs button[aria-current="true"] { color: var(--ink); }

.zoom-body {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 12px 0 32px; touch-action: pan-x pan-y pinch-zoom;
}
.zoom-body img { display: block; width: min(100%, 1100px); height: auto; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .brand span, #btn-full, .hint, .cta-long { display: none; }
  .cta-short { display: inline; }
  .stage { padding: 8px 8px; }
  .bar { gap: 6px; }
  /* arrows move out of the page and into the footer row */
  .nav { position: fixed; top: auto; bottom: calc(env(safe-area-inset-bottom) + 3px); width: 34px; height: 34px; margin: 0; }
  .nav-prev { right: 20%; }
  .nav-next { left: 20%; }
  .cta { padding: 8px 12px; font-size: 14px; margin-inline-start: 4px; }
  .actions { gap: 0; }
  .nav::after { content: ""; position: absolute; inset: -8px; }   /* larger tap target */
}
@media (max-width: 340px) {
  .brand { display: none; }
  .bar { justify-content: center; }
}
@media (max-height: 480px) {
  :root { --bar-h: 44px; --foot-h: 28px; }
  .stage { padding-block: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .shift, .book-size, .hint { transition: none; }
}
