/* ---- Base ---- */
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f2430;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --brand: #5b8cff;
  --brand-2: #3f6fe0;
  --danger: #e5484d;
  --border: #2a2f3a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Disable selection / image dragging on protected pages. */
.protected, .protected * {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.protected img, .protected canvas {
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: filter .15s ease, border-color .15s ease;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn.primary { background: linear-gradient(180deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { border-color: #5a2a2c; color: #ffb4b6; }
.btn.danger:hover { background: #3a1f21; }

/* ---- Header / footer ---- */
.site-header { padding: 40px 0 18px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, #141823, transparent); }
.brand { margin: 0; font-size: 30px; letter-spacing: .2px; }
.tagline { margin: 6px 0 0; color: var(--muted); }
.site-footer { margin-top: 50px; padding: 26px 0; border-top: 1px solid var(--border); }

/* ---- Gallery grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  padding: 28px 0;
}
.tile {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.tile:hover { transform: translateY(-3px); border-color: #3a4663; text-decoration: none; }
.thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  background: repeating-linear-gradient(45deg, #1b2030, #1b2030 12px, #20283c 12px, #20283c 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.thumb-canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.has-thumb .thumb-badge { display: none; }
.thumb-badge {
  font-size: 13px; letter-spacing: 3px; color: var(--muted);
  border: 1px dashed #44506e; padding: 6px 10px; border-radius: 8px;
}
.tile-body { padding: 14px 16px 18px; }
.tile-body h3 { margin: 0 0 6px; font-size: 16px; }
.pages { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--muted); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.muted { color: var(--muted); }
.empty { padding: 60px 0; text-align: center; color: var(--muted); }

/* ---- Search + folder breadcrumbs ---- */
.search-wrap { padding: 22px 0 2px; }
.search-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 15px;
}
.search-input:focus { outline: none; border-color: var(--brand); }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; word-break: break-word; }
/* Inputs must stay selectable/typable even on "protected" pages. */
.protected input, .protected textarea { -webkit-user-select: text; user-select: text; }

/* ---- Viewer ---- */
.viewer-body { background: #0b0d12; }
.viewer-header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(15, 17, 21, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.viewer-header .row { display: flex; align-items: center; gap: 16px; }
.viewer-header .vtitle { margin: 0; font-size: 16px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { white-space: nowrap; }
.viewer { max-width: 900px; margin: 0 auto; padding: 24px 16px 80px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }
.page {
  position: relative;
  margin: 0 auto 22px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.page-canvas { width: 100%; height: auto; display: block; border-radius: 6px 6px 0 0; opacity: 0; transition: opacity .25s ease; }
.page-canvas.loaded { opacity: 1; }
.page-num { width: 100%; text-align: center; font-size: 12px; color: #6b7280; padding: 6px 0; background: #f3f4f6; border-radius: 0 0 6px 6px; }
.page-error::after { content: "Could not load this page"; color: var(--muted); font-size: 13px; padding: 20px; }

/* ---- Flipbook viewer (StPageFlip) ---- */
/* StPageFlip base (vendored from page-flip 2.0.7 src/Style/stPageFlip.css) */
.stf__parent { position: relative; display: block; box-sizing: border-box; transform: translateZ(0); -ms-touch-action: pan-y; touch-action: pan-y; }
.sft__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; }

/* Stage that holds the book, centered */
.book-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 64px);
  padding: 28px 16px 90px;
  perspective: 2400px;
}
#flipbook {
  margin: 0 auto;
  filter: drop-shadow(0 22px 48px rgba(0, 0, 0, .6));
  /* Allow our own drag/click handling on the book; canvases stay non-draggable. */
  pointer-events: auto;
}
/* Each leaf of the book */
#flipbook .page {
  background: #fff;
  overflow: hidden;
  /* paper-edge gradient gives the famous-site book feel */
  background-image: linear-gradient(to var(--gutter, right), rgba(0,0,0,.10), rgba(0,0,0,0) 6%);
}
#flipbook .page.--right { --gutter: left; }
#flipbook .page .pf-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  opacity: 0;
  transition: opacity .35s ease;
}
#flipbook .page .pf-canvas.loaded { opacity: 1; }
#flipbook .page .pf-num {
  position: absolute;
  bottom: 8px; left: 0; right: 0;
  text-align: center;
  font-size: 11px;
  color: #9aa0aa;
  pointer-events: none;
}
#flipbook .page .pf-spin {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #b6bcc6; font-size: 13px;
}

/* Toolbar controls */
.viewer-toolbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 12px;
  background: linear-gradient(0deg, rgba(15,17,21,.95), rgba(15,17,21,.0));
}
.viewer-toolbar .nav-btn {
  width: 46px; height: 46px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; padding: 0;
}
.viewer-toolbar .nav-btn:disabled { opacity: .35; cursor: default; filter: none; }
.viewer-toolbar .page-indicator {
  min-width: 150px; text-align: center; font-size: 13px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 9px 14px; border-radius: 999px;
}
.viewer-toolbar .page-indicator b { color: var(--text); font-weight: 600; }
.hint {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 0 0 6px;
}

/* DevTools shield blurs the book stage too */
.blurred .book-stage { filter: blur(20px); pointer-events: none; }

/* ---- DevTools shield ---- */
.blurred .viewer { filter: blur(20px); pointer-events: none; }
.dt-shield {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(8, 10, 14, .96);
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.dt-shield h2 { margin: 0 0 8px; }
.dt-shield p { color: var(--muted); margin: 0; }

/* ---- Cards / centered layouts ---- */
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin: 22px 0;
}
.card.narrow { max-width: 420px; text-align: center; }
.big { font-size: 64px; margin: 0 0 6px; }
.error { background: #3a1f21; border: 1px solid #5a2a2c; color: #ffb4b6; padding: 10px 12px; border-radius: 10px; }

/* ---- Print protection: never print preview content ---- */
@media print {
  body.protected, body.viewer-body { display: none !important; }
}
