@font-face {
  font-family: "Suez One";
  src: url("../fonts/SuezOne-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Frank Ruhl Libre";
  src: url("../fonts/FrankRuhlLibre.ttf") format("truetype");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --cream: #fbf2e9;
  --cream-deep: #f3e6d6;
  --olive: #4f5a35;
  --olive-deep: #3d4628;
  --gold: #c49a6c;
  --gold-soft: #d4b48a;
  --ink: #4a453c;
  --muted: #6b5a44;
  --paper: #fffdf8;
  --shadow: 0 10px 40px rgba(79, 90, 53, 0.16);
  --bar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: "Frank Ruhl Libre", "Times New Roman", serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
}

.topbar {
  flex: 0 0 auto;
  height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, #fffaf3 0%, var(--cream) 100%);
  border-bottom: 1px solid rgba(196, 154, 108, 0.45);
  z-index: 20;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--olive);
  min-width: 0;
}
.brand img {
  width: 36px;
  height: auto;
  display: block;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}
.brand-title {
  font-family: "Suez One", serif;
  font-size: 1.2rem;
  white-space: nowrap;
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.counter {
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(196, 154, 108, 0.5);
  border-radius: 999px;
  padding: 6px 14px;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset;
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  appearance: none;
  border: 1px solid rgba(79, 90, 53, 0.18);
  background: var(--paper);
  color: var(--olive);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--cream-deep); border-color: var(--gold); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn[aria-pressed="true"] { background: var(--olive); color: var(--cream); border-color: var(--olive); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 48px 16px;
  min-height: 0;
}

#book {
  /* RTL: mirror the physical book so the spine sits on the right and the
     cover opens on the left. Page contents are un-mirrored in .page-inner. */
  transform: scaleX(-1) translateZ(0);
  max-width: 100%;
  max-height: 100%;
}

#book .page {
  background: var(--cream-deep);
}
#book .page-inner {
  transform: scaleX(-1);
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
}
#book .page-inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  width: 44px;
  height: 88px;
  border: none;
  background: rgba(255, 253, 248, 0.8);
  color: var(--olive);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  transition: background 0.15s, opacity 0.15s;
}
.nav-arrow:hover { background: #fff; }
.nav-arrow:disabled { opacity: 0.25; cursor: default; box-shadow: none; }
.nav-arrow.prev { right: 6px; } /* previous = toward the start, visual right in RTL */
.nav-arrow.next { left: 6px; }
.nav-arrow svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; }

/* TOC drawer — opens from the start edge (right in RTL) */
.toc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(52, 44, 32, 0.35);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toc-backdrop.open { opacity: 1; pointer-events: auto; }

.toc {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(360px, 92vw);
  background: var(--paper);
  z-index: 50;
  transform: translateX(110%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(79, 90, 53, 0.18);
  border-left: 3px solid var(--gold);
}
.toc.open { transform: translateX(0); }

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 18px 12px;
  border-bottom: 1px solid rgba(196, 154, 108, 0.4);
}
.toc-head h2 {
  margin: 0;
  font-family: "Suez One", serif;
  font-size: 1.2rem;
  color: var(--olive);
  font-weight: 400;
}

.jump {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(196, 154, 108, 0.25);
  color: var(--muted);
  font-size: 0.9rem;
}
.jump input {
  width: 72px;
  height: 36px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  text-align: center;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--cream);
}
.jump button {
  appearance: none;
  border: 0;
  background: var(--olive);
  color: var(--cream);
  border-radius: 8px;
  height: 36px;
  padding: 0 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
}

.toc nav {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0 calc(20px + var(--safe-bottom));
}
.toc a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 18px;
  text-decoration: none;
  color: var(--ink);
  border-right: 3px solid transparent;
}
.toc a:hover { background: var(--cream); }
.toc a.active {
  background: var(--cream);
  border-right-color: var(--gold);
  color: var(--olive);
}
.toc a .name { font-size: 1.02rem; }
.toc a .pg {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

body.toc-open { pointer-events: none; }
body.toc-open .toc,
body.toc-open .toc-backdrop,
body.toc-open .topbar { pointer-events: auto; }

@media (max-width: 720px) {
  :root { --bar-h: 56px; }
  .brand-sub { display: none; }
  .brand-title { font-size: 1.05rem; }
  .counter { font-size: 0.82rem; padding: 5px 10px; }
  .stage { padding: 8px 8px 12px; }
  .nav-arrow {
    width: 36px;
    height: 64px;
    background: rgba(255, 253, 248, 0.55);
    box-shadow: none;
  }
  .nav-arrow.prev { right: 2px; }
  .nav-arrow.next { left: 2px; }
  .icon-btn { width: 36px; height: 36px; }
}

@media (max-width: 420px) {
  .brand img { width: 28px; }
  .topbar { padding-inline: 8px; gap: 6px; }
}

.stage { overflow: hidden; }

#book.stf__parent {
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 100%;
  max-height: 100%;
}
#book .stf__wrapper {
  width: 100%;
  height: 100%;
  padding-bottom: 0 !important;
}
#book .stf__block,
#book .sft__wrapper {
  width: 100%;
  height: 100%;
}

/* The hardcover edge can leave a grey dog-ear on the outer corner after the
   RTL mirror; hide the static hard shadows and keep the flip shadows. */
#book .stf__hardShadow,
#book .stf__hardInnerShadow {
  display: none;
}
