/* Reader interface for the book. The book pages themselves are images in /book. */

/* Layout: one full-screen stage (the "table") with the book centred on it,
   and a small control bar below (beside it on short landscape screens). */
:root {
  --table: #e5e2dd;          /* quiet warm grey, lets the cover's blues and sand read */
  --table-hi: #eeece8;       /* soft pool of light behind the book */
  --table-lo: #d8d4ce;
  --ink: #2b2e33;
  --muted: #62666c;
  --bar: rgba(250, 249, 247, 0.78);
  --bar-line: rgba(40, 36, 30, 0.12);
  --btn-hover: rgba(40, 36, 30, 0.08);
  --focus: #1d5fc9;
  --edge-a: #f7f5f0;         /* page-block edges */
  --edge-b: #dcd7cd;
  --edge-c: #b9b3a7;
  --paper: #fbfaf7;
  --shadow-1: rgba(46, 36, 24, 0.20);   /* book on the table: contact, mid and ambient shadow */
  --shadow-2: rgba(46, 36, 24, 0.12);
  --shadow-3: rgba(46, 36, 24, 0.13);
  --shadow-edge: rgba(46, 36, 24, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ui-font: system-ui, -apple-system, "Segoe UI", "Arial Hebrew", "Noto Sans Hebrew", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --table: #1d1f22; --table-hi: #26292d; --table-lo: #16181a;
    --ink: #e8e6e3; --muted: #a3a8ae;
    --bar: rgba(38, 41, 45, 0.82); --bar-line: rgba(255, 255, 255, 0.10); --btn-hover: rgba(255, 255, 255, 0.10);
    --focus: #8ab4ff;
    --edge-a: #dedad2; --edge-b: #b5b0a6; --edge-c: #8c877d;
    --paper: #e9e6df;
    --shadow-1: rgba(0, 0, 0, 0.38); --shadow-2: rgba(0, 0, 0, 0.23); --shadow-3: rgba(0, 0, 0, 0.25); --shadow-edge: rgba(0, 0, 0, 0.30);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --table: #1d1f22; --table-hi: #26292d; --table-lo: #16181a;
  --ink: #e8e6e3; --muted: #a3a8ae;
  --bar: rgba(38, 41, 45, 0.82); --bar-line: rgba(255, 255, 255, 0.10); --btn-hover: rgba(255, 255, 255, 0.10);
  --focus: #8ab4ff;
  --edge-a: #dedad2; --edge-b: #b5b0a6; --edge-c: #8c877d;
  --paper: #e9e6df;
  --shadow-1: rgba(0, 0, 0, 0.38); --shadow-2: rgba(0, 0, 0, 0.23); --shadow-3: rgba(0, 0, 0, 0.25); --shadow-edge: rgba(0, 0, 0, 0.30);
  color-scheme: dark;
}

html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body {
  background: var(--table);
  color: var(--ink);
  font: 14px/1.4 var(--ui-font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: radial-gradient(120% 90% at 50% 42%, var(--table-hi) 0%, var(--table) 55%, var(--table-lo) 100%);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.stage.busy { cursor: progress; }
.stage:focus-visible::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px var(--focus);
  opacity: 0.7;
  pointer-events: none;
  z-index: 5;
}

.book {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  opacity: 0;
  transition: opacity 360ms ease;
}
.app.ready .book { opacity: 1; }
.book.fade-ghost { transition: opacity 220ms ease; z-index: 2; pointer-events: none; }

.slot {
  position: absolute;
  overflow: hidden;
  background: var(--paper);
}
.slot img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
.stack, .book-shadow { position: absolute; pointer-events: none; }
.book-shadow.off { opacity: 0; transition: none; }   /* lifts instantly, settles softly */
.book-shadow {
  transition: opacity 200ms ease;
  box-shadow:
    0 1px 2px var(--shadow-1),
    0 6px 14px var(--shadow-2),
    0 18px 42px var(--shadow-3);
}

canvas.curl {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.hint {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 8px;
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 400ms ease;
  z-index: 4;
}
.hint.gone { opacity: 0; }

.controls {
  flex: none;
  display: flex;
  justify-content: center;
  padding-block: 2px 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--bar);
  border: 1px solid var(--bar-line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.btn {
  appearance: none;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.btn svg { width: 20px; height: 20px; display: block; }
.btn:hover:not([aria-disabled="true"]) { background: var(--btn-hover); }
.btn:active:not([aria-disabled="true"]) { transform: scale(0.94); }
.btn[aria-disabled="true"] { cursor: default; }
.btn[aria-disabled="true"] svg { opacity: 0.32; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.grp { display: flex; align-items: center; gap: 2px; }
.sep { width: 1px; height: 20px; background: var(--bar-line); margin: 0 4px; flex: none; }
@media (any-pointer: coarse) {
  .btn { width: 46px; height: 46px; }
  .btn svg { width: 22px; height: 22px; }
}

/* Narrow portrait screens: the two groups of controls stack in two rows */
@media (orientation: portrait) and (max-width: 520px) {
  .bar { flex-direction: column; gap: 0; border-radius: 26px; }
  .gsep { display: none; }
}

/* Short landscape screens (phones on their side): controls move beside the book, in two columns */
@media (orientation: landscape) and (max-height: 520px) {
  .app { flex-direction: row; }
  .controls {
    flex-direction: column;
    justify-content: center;
    padding-block: 8px;
    padding-left: 4px;
    padding-right: 10px;
  }
  .bar { border-radius: 26px; }
  .grp { flex-direction: column; }
  .grp .sep { width: 20px; height: 1px; margin: 4px 0; }
  .gsep { height: auto; align-self: stretch; margin: 8px 2px; }
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Plain list of pages when scripting is unavailable */
.noscript-pages { padding: 16px max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 16px; justify-items: center; }
.noscript-pages img { width: min(100%, 720px); height: auto; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18); }
