:root {
  --bar: 44px;
  --strip: 92px;
  --ink: #1c1a17;
  --paper: #24211e;
  --line: rgba(255, 255, 255, .14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100vh;
  height: 100dvh;   /* Safari on iOS: 100vh is the address-bar-less height */
  overflow: hidden;
  background: var(--paper);
  color: #f2efe9;
  font: 14px/1.4 "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
}

body { display: flex; flex-direction: column; }

/* ---- top bar (5) ------------------------------------------------------- */
#bar {
  flex: none;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: #1a1815;
}

#bar .group { display: flex; gap: 6px; align-items: center; }
#bar .spacer { flex: 1; }

#bar button {
  font: inherit;
  color: #e9e4dc;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  cursor: pointer;
  white-space: nowrap;
}
#bar button:hover { background: rgba(255, 255, 255, .09); }
#bar button[aria-current="true"] {
  background: #f0ece5;
  border-color: #f0ece5;
  color: #1a1815;
}

#title { font-weight: 600; letter-spacing: .01em; }
#folio { opacity: .6; font-variant-numeric: tabular-nums; }

/* ---- stage ------------------------------------------------------------- */
#stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* flex: none is load-bearing. The spread is a fixed 1332px box that `fit()`
   then scales down; as a shrinkable flex item it would instead be squeezed to
   the viewport width, and the iframe would show only the left part of it. */
#wrap {
  flex: none;
  transform-origin: center center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  background: #fff;
}

#page { width: 100%; height: 100%; border: 0; display: block; }

.arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 76px;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, .3);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  opacity: .35;
  transition: opacity .15s;
}
.arrow:hover { opacity: .95; }
.arrow[disabled] { display: none; }
/* Logical, not physical: in the Hebrew book "previous" lies to the right. */
#prev { inset-inline-start: 10px; }
#next { inset-inline-end: 10px; }

/* ---- thumbnail strip (3) ----------------------------------------------- */
#strip {
  flex: none;
  height: calc(var(--strip) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: #1a1815;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

#thumbs {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  height: 100%;
  align-items: center;
  width: max-content;
}

/* A fixed box per thumbnail: the strip has to have its final width before the
   lazy images arrive, or scrolling the current spread into view lands nowhere. */
#thumbs button {
  flex: none;
  width: 136px;
  height: 66px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #000;
  cursor: pointer;
  line-height: 0;
  position: relative;
}
#thumbs img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  opacity: .72;
}
#thumbs button:hover img { opacity: 1; }
#thumbs button[aria-current="true"] { border-color: #f0ece5; }
#thumbs button[aria-current="true"] img { opacity: 1; }
#thumbs .n {
  position: absolute;
  inset-inline-end: 2px;
  inset-block-end: 1px;
  font-size: 9px;
  padding: 0 3px;
  border-radius: 2px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  line-height: 13px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 620px) {
  :root { --strip: 74px; }
  #title { display: none; }
  #bar { gap: 5px; padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left)); }
  #bar button { font-size: 12px; padding: 4px 9px; }
  #bar .group { gap: 4px; }
  #folio { font-size: 12px; white-space: nowrap; }
  .arrow { width: 34px; height: 60px; font-size: 22px; }
  #thumbs button { width: 106px; height: 52px; }
}

/* Below this the bar cannot hold everything; the spread number is already in
   the window title and on the highlighted thumbnail. */
@media (max-width: 400px) {
  #folio { display: none; }
}
