:root {
  --green-950: #0c2b1c;
  --green-900: #123d29;
  --green-800: #185033;
  --green-700: #1f6b3a;
  --gold-600: #a9782f;
  --gold-500: #c89a4b;
  --gold-300: #e4c98f;
  --paper: #f8f6ef;
  --surface: rgba(255,255,255,.94);
  --surface-solid: #fff;
  --text: #18231d;
  --muted: #67736c;
  --line: rgba(18,61,41,.14);
  --stage: radial-gradient(circle at 50% 15%, #f7f1e3 0, #e7e1d5 46%, #cdc7bb 100%);
  --shadow: 0 18px 45px rgba(10,31,21,.22);
  --radius: 16px;
  color-scheme: light;
}

body[data-theme="dark"] {
  --surface: rgba(20,28,24,.95);
  --surface-solid: #151d19;
  --text: #eef2ef;
  --muted: #aeb8b2;
  --line: rgba(255,255,255,.12);
  --stage: radial-gradient(circle at 50% 16%, #34443a 0, #1d2822 47%, #101713 100%);
  --shadow: 0 22px 55px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--green-950);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }


.app-splash {
  position: fixed; inset: 0; z-index: 9999;
  display: grid; place-items: center;
  padding: 8vh 8vw;
  background: #fff;
  opacity: 1; visibility: visible;
  transition: opacity .34s ease, visibility .34s ease;
}
.app-splash img {
  display: block;
  width: min(78vw, 480px);
  max-height: 78vh;
  object-fit: contain;
}
.app-splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: 68px minmax(0,1fr) 72px;
  background: var(--stage);
}

.topbar {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  color: white;
  background:
    linear-gradient(110deg, rgba(255,255,255,.04), transparent 35%),
    linear-gradient(90deg, var(--green-950), var(--green-800));
  box-shadow: 0 2px 16px rgba(0,0,0,.18);
}
.brand-block, .top-actions, .page-status, .zoom-controls { display: flex; align-items: center; }
.brand-block { gap: 11px; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; flex: 0 0 auto;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.55), 0 5px 14px rgba(0,0,0,.18);
}
.brand-mark img {
  display: block;
  width: 92%; height: 92%;
  object-fit: contain;
}
.brand-copy { min-width: 0; line-height: 1.08; }
.brand-copy strong { display:block; letter-spacing:.05em; font-size:14px; white-space:nowrap; }
.brand-copy strong span { color: var(--gold-300); font-weight:600; }
.brand-copy small { display:block; margin-top:5px; opacity:.8; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.top-actions { gap: 7px; }
.icon-btn, .mini-btn, .turn-btn, .zoom-value, .pdf-btn {
  border: 0; cursor: pointer; text-decoration: none;
  display: inline-grid; place-items: center;
}
.icon-btn {
  width: 39px; height: 39px; border-radius: 11px;
  color: inherit; background: rgba(255,255,255,.09);
  font-size: 20px;
}
.icon-btn:hover { background: rgba(255,255,255,.17); }
.menu-btn { font-size:18px; }
.pdf-btn {
  height: 39px; padding: 0 13px; border-radius: 11px;
  color: var(--green-950); background: linear-gradient(135deg, #ecd7a0, var(--gold-500));
  font-weight: 800; font-size: 13px; letter-spacing:.05em;
}

.viewer { position: relative; min-height: 0; overflow: hidden; }
.viewer-stage {
  position: absolute; inset: 0;
  overflow: auto;
  display: grid;
  place-items: safe center;
  padding: 22px 58px 30px;
  scrollbar-width: thin;
  scrollbar-color: rgba(18,61,41,.35) transparent;
}
.viewer-stage::before {
  content:"";
  position: fixed; left:8%; right:8%; bottom:88px; height:25px;
  border-radius:50%;
  background:rgba(0,0,0,.22);
  filter:blur(22px);
  pointer-events:none;
}
/* Core layout required by StPageFlip */
.stf__parent {
  position: relative;
  display: block;
  box-sizing: border-box;
  transform: translateZ(0);
  -ms-touch-action: pan-y;
  touch-action: pan-y;
}
.stf__wrapper { position: relative; width: 100%; box-sizing: border-box; }
.stf__parent canvas { position: absolute; width: 100%; height: 100%; left: 0; top: 0; }
.stf__block { position: absolute; width: 100%; height: 100%; box-sizing: border-box; perspective: 2000px; }
.stf__item { display: none; position: absolute; transform-style: preserve-3d; }
.stf__outerShadow, .stf__innerShadow, .stf__hardShadow, .stf__hardInnerShadow {
  position: absolute; left: 0; top: 0;
}

.zoom-layer {
  position: relative;
  width: min(1420px, calc(100vw - 116px));
  min-width: 1px; min-height: 1px;
  margin: 0 auto;
}
#book {
  position: relative;
  width: 100%;
  margin: 0 auto;
  filter: drop-shadow(0 20px 22px rgba(0,0,0,.24));
}
.page {
  background: #fff;
  overflow: hidden;
}
.page img {
  display:block;
  width:100%; height:100%;
  object-fit:cover;
  user-select:none;
  -webkit-user-drag:none;
  pointer-events:none;
}
.page[data-density="hard"] { background:#f8f6ef; }

.loading-card {
  position:absolute; left:50%; top:50%; transform:translate(-50%,-50%);
  width:min(310px, 80vw); padding:26px; border-radius:18px;
  display:grid; justify-items:center; gap:8px;
  text-align:center; background:var(--surface); box-shadow:var(--shadow);
  z-index:15;
}
.loading-card span { color:var(--muted); font-size:13px; }
.loader {
  width:36px; height:36px; border-radius:50%;
  border:3px solid rgba(31,107,58,.16); border-top-color:var(--gold-500);
  animation:spin .8s linear infinite;
}
@keyframes spin { to { transform:rotate(360deg); } }
.loading-card.hidden { opacity:0; pointer-events:none; transition:opacity .3s; }

.floating-nav { position:absolute; z-index:16; top:50%; transform:translateY(-50%); }
.prev-wrap { left:14px; }
.next-wrap { right:14px; }
.turn-btn {
  width:48px; height:76px; border-radius:15px;
  color:white; background:rgba(12,43,28,.72);
  box-shadow:0 8px 22px rgba(0,0,0,.22);
  font-family:Georgia,serif; font-size:43px; line-height:1;
  backdrop-filter:blur(7px);
}
.turn-btn:hover { background:var(--green-800); transform:translateY(-1px); }
.turn-btn:disabled { opacity:.25; cursor:default; }

.controlbar {
  position:relative; z-index:35;
  display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:18px;
  padding: 9px 18px;
  background: var(--surface);
  border-top:1px solid var(--line);
  box-shadow:0 -8px 25px rgba(15,35,24,.08);
  backdrop-filter:blur(15px);
}
.page-status { min-width:0; gap:14px; }
#pageTitle { font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:320px; }
.page-jump { display:flex; align-items:center; gap:6px; color:var(--muted); font-size:13px; white-space:nowrap; }
.page-jump input {
  width:52px; height:34px; padding:0 6px; text-align:center;
  border:1px solid var(--line); border-radius:9px;
  color:var(--text); background:var(--surface-solid); outline:none;
}
.page-jump input:focus { border-color:var(--gold-500); box-shadow:0 0 0 3px rgba(200,154,75,.18); }
.zoom-controls { justify-self:center; gap:8px; }
.mini-btn, .zoom-value {
  height:34px; min-width:34px; border-radius:9px;
  color:var(--text); background:var(--surface-solid); border:1px solid var(--line);
}
.mini-btn { font-size:21px; }
.zoom-value { padding:0 9px; font-size:12px; font-weight:700; }
#zoomRange { width:110px; accent-color:var(--green-700); }
.help-text { justify-self:end; color:var(--muted); font-size:12px; text-align:right; }

.side-panel {
  position:fixed; z-index:70; top:0; bottom:0; left:0;
  width:min(390px, 92vw);
  display:grid; grid-template-rows:68px 52px minmax(100px,1fr) auto;
  color:var(--text); background:var(--surface-solid);
  box-shadow:18px 0 45px rgba(0,0,0,.28);
  transform:translateX(-105%); transition:transform .25s ease;
}
.social-section {
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 58dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
  background: var(--surface-solid);
}
.social-section > strong { display:block; margin-bottom:9px; font-size:13px; }
.social-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.social-btn {
  text-decoration:none;
  min-height:48px; border:0; border-radius:12px; padding:0 10px;
  display:flex; align-items:center; justify-content:center; gap:8px;
  color:#fff; cursor:pointer; font-size:13px; font-weight:700;
}
.social-btn span {
  width:22px; height:22px; border-radius:7px; display:grid; place-items:center;
  background:rgba(255,255,255,.16); font-size:16px; font-weight:900;
}
.social-btn.facebook { background:#1877f2; }
.social-btn.instagram { background:linear-gradient(135deg,#833ab4,#e1306c 55%,#f77737); }
.social-btn:focus-visible { outline:3px solid var(--gold-300); outline-offset:2px; }
.side-panel.open { transform:translateX(0); }
.panel-head {
  display:flex; align-items:center; justify-content:space-between;
  padding:0 16px 0 20px; color:white;
  background:linear-gradient(90deg,var(--green-950),var(--green-800));
}
.panel-head .icon-btn { font-size:27px; }
.panel-tabs {
  display:grid; grid-template-columns:repeat(4,1fr);
  border-bottom:1px solid var(--line); background:var(--surface-solid);
}
.tab-btn {
  border:0; border-bottom:3px solid transparent; padding:0 4px;
  color:var(--muted); background:transparent; cursor:pointer; font-size:12px;
}
.tab-btn.active { color:var(--green-700); border-bottom-color:var(--gold-500); font-weight:700; }
body[data-theme="dark"] .tab-btn.active { color:var(--gold-300); }
.panel-body { min-height:0; overflow:hidden; }
.tab-panel { display:none; height:100%; overflow:auto; padding:14px; }
.tab-panel.active { display:block; }
.panel-scrim {
  position:fixed; z-index:65; inset:0; background:rgba(0,0,0,.42);
  opacity:0; pointer-events:none; transition:opacity .22s;
}
.panel-scrim.visible { opacity:1; pointer-events:auto; }

.toc-list, .bookmark-list { display:grid; gap:7px; }
.toc-item, .bookmark-item, .search-result {
  width:100%; border:1px solid var(--line); border-radius:12px;
  padding:12px; text-align:left; color:var(--text); background:var(--surface-solid);
  cursor:pointer;
}
.toc-item:hover, .bookmark-item:hover, .search-result:hover { border-color:rgba(200,154,75,.7); background:rgba(200,154,75,.08); }
.toc-item { display:grid; grid-template-columns:1fr auto; align-items:center; gap:10px; }
.toc-item small, .bookmark-item small, .result-meta { color:var(--muted); }
.empty-state { padding:35px 16px; text-align:center; color:var(--muted); }

.thumb-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.thumb-item {
  border:2px solid transparent; border-radius:10px; padding:5px;
  background:rgba(127,127,127,.08); cursor:pointer; position:relative;
}
.thumb-item img { display:block; width:100%; border-radius:6px; box-shadow:0 4px 11px rgba(0,0,0,.18); }
.thumb-item span {
  position:absolute; right:8px; bottom:8px; min-width:24px; height:22px; padding:0 6px;
  display:grid; place-items:center; border-radius:7px;
  background:rgba(12,43,28,.84); color:white; font-size:11px; font-weight:700;
}
.thumb-item.current { border-color:var(--gold-500); background:rgba(200,154,75,.13); }

.search-box {
  display:flex; align-items:center; gap:8px;
  border:1px solid var(--line); border-radius:12px; padding:0 12px;
  background:var(--surface-solid);
}
.search-box:focus-within { border-color:var(--gold-500); box-shadow:0 0 0 3px rgba(200,154,75,.16); }
.search-box input { width:100%; height:44px; border:0; outline:0; color:var(--text); background:transparent; }
.search-hint { color:var(--muted); font-size:12px; padding:9px 3px 12px; }
.result-list { display:grid; gap:8px; }
.search-result strong { display:block; margin-bottom:5px; }
.search-result p { margin:6px 0 0; color:var(--muted); font-size:12px; line-height:1.45; }

@media (max-width: 900px) {
  .controlbar { grid-template-columns:1fr auto; }
  .help-text { display:none; }
  #pageTitle { max-width:230px; }
}

@media (max-width: 650px) {
  .app-shell { grid-template-rows:58px minmax(0,1fr) 78px; }
  .topbar { padding:0 10px; }
  .brand-mark { width:36px; height:36px; border-radius:10px; }
  .brand-copy strong { font-size:12px; }
  .brand-copy small { font-size:10px; max-width:180px; }
  .top-actions { gap:4px; }
  .top-actions .icon-btn { width:34px; height:34px; }
  .pdf-btn { height:34px; padding:0 10px; }
  .viewer-stage { padding:15px 28px 24px; }
  .zoom-layer { width: calc(100vw - 56px); }
  .floating-nav { top:auto; bottom:14px; transform:none; }
  .prev-wrap { left:10px; }
  .next-wrap { right:10px; }
  .turn-btn { width:42px; height:44px; border-radius:12px; font-size:34px; }
  .controlbar { grid-template-columns:1fr auto; gap:8px; padding:7px 10px; }
  .page-status { display:grid; gap:4px; }
  #pageTitle { max-width:190px; font-size:12px; }
  .page-jump { font-size:11px; }
  .page-jump input { width:42px; height:30px; }
  #zoomRange { display:none; }
  .mini-btn, .zoom-value { height:31px; min-width:31px; }
  .zoom-value { padding:0 6px; }
  .side-panel { grid-template-rows:58px 52px minmax(100px,1fr) auto; }
  .thumb-grid { grid-template-columns:repeat(3,1fr); }
}

@media (max-width: 390px) {
  .brand-mark { display:grid; width:34px; height:34px; }
  .brand-copy small { display:none; }
  .brand-block { gap:6px; }
  .brand-copy strong span { display:none; }
  .zoom-value { display:none; }
}
/* Android app shell adjustments */
.pdf-btn { display: none !important; }
@media (max-width: 700px) {
  .help-text { display: none !important; }
}


/* v1.4: fullscreen and Telbija audio removed for stability */
.social-section .install-btn { display:flex; align-items:center; justify-content:center; min-height:52px; padding:12px; text-align:center; border-radius:14px; font-size:14px; line-height:1.4; }
.social-section .share-app-btn { margin-bottom:12px; color:var(--text); background:var(--surface-solid); border:1px solid var(--line); }
.action-icon { display:grid; place-items:center; flex:0 0 36px; height:36px; border-radius:10px; background:rgba(127,127,127,.12); font-size:23px; }
.action-copy { flex:1; font-size:14px; line-height:1.3; }
.action-copy small { display:block; margin-top:4px; font-size:11px; font-weight:400; opacity:.8; }
.action-arrow { font-size:24px; opacity:.6; }
.social-section button:focus-visible { outline:3px solid var(--gold-500); outline-offset:3px; }
.social-section [hidden] { display:none; }
#shareDialog { width:min(420px,92vw); max-height:90dvh; overflow:auto; border:0; border-radius:16px; padding:24px; color:var(--text); background:var(--surface-solid); text-align:center; box-shadow:var(--shadow); }
#shareDialog::backdrop { background:rgba(0,0,0,.55); }
#shareDialog h2 { font-size:20px; margin:8px 0; }
#shareDialog p { font-size:14px; }
.share-close { float:right; }
.share-qr { display:block; width:min(220px,100%); height:auto; margin:12px auto; }
#shareLink { display:block; width:100%; padding:10px; margin:8px 0; border:1px solid var(--line); border-radius:8px; color:var(--text); background:var(--surface-solid); font-size:14px; }
.share-actions { display:flex; gap:8px; margin:12px 0; }
.share-actions [hidden] { display:none; }
#shareDialog a { color:var(--text); }

#pwaTools { margin-bottom:18px; padding-bottom:14px; border-bottom:1px solid var(--line); }
.install-btn { width:100%; border:0; border-radius:10px; padding:10px; background:var(--green-900); color:white; font:inherit; font-weight:700; cursor:pointer; }
#pwaTools [hidden] { display:none; }
#offlineStatus, #installHelp { margin:8px 0; font-size:12px; line-height:1.45; color:var(--muted); }

/* Keep all reader and menu controls above Netlify's fixed attribution. */
body:has(#nl-badge-frame) .app-shell {
  height:calc(100dvh - 80px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
body:has(#nl-badge-frame) .side-panel {
  bottom:calc(80px + env(safe-area-inset-bottom));
}
body:has(#nl-badge-frame) .social-section {
  max-height:min(58dvh, calc(100dvh - 290px));
}
