:root {
  --bg: #14110f;
  --bg-2: #241e1a;
  --fg: #f4ecdf;
  --muted: #b8a995;
  --accent: #d4a24c;
  --accent-2: #b3812e;
  --card: #1e1915;
  --line: #3a312a;
  --bar-h: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* light background theme (viewer only, toggled with the sun/moon button) */
body.light {
  --bg: #efe9df;
  --bg-2: #fbf8f2;
  --fg: #221b14;
  --muted: #6d604f;
  --card: #fbf8f2;
  --line: #d9cfc0;
}
body.light .backdrop.show { opacity: .5; }
body.light .dock { background: rgba(255,255,255,.55); border-color: rgba(0,0,0,.08); box-shadow: 0 6px 24px rgba(0,0,0,.12); }
body.light .dock .sep { background: rgba(0,0,0,.12); }
body.light .ctl:hover { background: rgba(0,0,0,.07); }
body.light .ctl:active { background: rgba(0,0,0,.12); }
body.light .book { filter: drop-shadow(0 18px 40px rgba(0,0,0,.28)); }
body.light .hint { background: rgba(40,30,20,.85); color: #fff; }
body.light .loader { background: var(--bg); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, a.btn, a.ctl { font: inherit; cursor: pointer; }

/* ---------- viewer ---------- */

body.viewer {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: calc(var(--bar-h) + var(--safe-t)) 1fr auto calc(var(--bar-h) + var(--safe-b));
  position: relative;
  touch-action: none;
}

.backdrop {
  position: fixed; inset: 0;
  z-index: 0;
  opacity: 0;
  transition: opacity 1.1s ease;
  pointer-events: none;
}
.backdrop.show { opacity: .6; }
body { transition: background-color .9s ease; }

.bar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 14px;
}
.bar.top { padding-top: var(--safe-t); grid-row: 1; }
.bar.bottom { padding-bottom: var(--safe-b); justify-content: center; grid-row: 4; }
.stage { grid-row: 2; }
.thumbs { grid-row: 3; }
.logo {
  display: block; height: 34px; max-width: min(46vw, 260px); width: auto; object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
.title {
  font-weight: 600; letter-spacing: .01em; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: .92;
}

/* page strip (Canva-style) */
.thumbs {
  position: relative; z-index: 2;
  display: flex; gap: 10px; align-items: flex-end;
  padding: 10px 14px 6px;
  overflow-x: auto; overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}
.thumbs[hidden] { display: none; }
.thumb {
  flex: 0 0 auto;
  position: relative;
  padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 6px;
  opacity: .72;
  transition: opacity .15s, transform .15s;
}
.thumb img {
  display: block; height: 76px; width: auto;
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  background: #fff;
  outline: 2px solid transparent; outline-offset: 1px;
  transition: outline-color .15s;
}
.thumb span {
  position: absolute; left: 50%; bottom: -2px; transform: translate(-50%, 100%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.thumb:hover { opacity: 1; }
.thumb.active { opacity: 1; }
.thumb.active img { outline-color: var(--accent); }
.thumb.active span { color: var(--fg); font-weight: 600; }
.thumbs { padding-bottom: 20px; }   /* room for the numbers */
@media (max-height: 560px) { .thumb img { height: 56px; } }
.ctl[aria-pressed="true"] { background: rgba(255,255,255,.16); }
body.light .ctl[aria-pressed="true"] { background: rgba(0,0,0,.1); }

/* frosted pill that holds the controls */
.dock {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  box-shadow: 0 8px 28px rgba(0,0,0,.22);
}
.dock.small { padding: 3px; }
.dock .sep { width: 1px; height: 20px; margin: 0 3px; background: rgba(255,255,255,.14); }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.bar.top .right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.ctl.icon { min-width: 36px; width: 36px; padding: 0; font-size: 17px; }

.ctl {
  min-width: 40px; height: 36px; padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font-size: 14px; font-weight: 500;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, opacity .15s;
  user-select: none; -webkit-user-select: none;
}
.ctl:hover { background: rgba(255,255,255,.12); }
.ctl:active { background: rgba(255,255,255,.2); }
.ctl:disabled { opacity: .3; cursor: default; background: transparent; }
#prev, #next { font-size: 16px; min-width: 44px; }
.ctl .ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl .ic + .lbl { margin-left: 7px; }
@media (max-width: 480px) {
  .ctl .lbl { display: none; }                 /* icons only on phones so the dock always fits */
  .ctl { padding: 0 10px; min-width: 40px; }
  .bar { padding: 0 10px; }
}
.dock.small .ctl { height: 32px; min-width: 34px; }

.stage {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 0; min-width: 0;
  overflow: hidden;
}
.book {
  position: relative;
  filter: drop-shadow(0 18px 40px rgba(0,0,0,.6));
}
.book canvas { display: block; }

.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px;
  background: rgba(0,0,0,.6); color: var(--fg); font-size: 13px;
  white-space: nowrap; pointer-events: none;
  transition: opacity .5s;
}
.hint.hide { opacity: 0; }

.loader {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); color: var(--muted);
  transition: opacity .4s; padding: 24px; text-align: center;
}
.loader.hide { opacity: 0; pointer-events: none; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: min(260px, 70vw); height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.notfound { text-align: center; padding: 20vh 24px; }
.notfound h1 { font-weight: 600; }

/* ---------- uploader (index) ---------- */

body.home {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 16px 48px;
  background: radial-gradient(1200px 600px at 50% -10%, #3a2c1d 0%, var(--bg) 60%);
}
.home header { text-align: center; margin: 32px 0 28px; }
.home h1 { margin: 0 0 6px; font-size: clamp(26px, 5vw, 38px); font-weight: 700; letter-spacing: -.01em; }
.home h1 span { color: var(--accent); }
.home header p { margin: 0; color: var(--muted); }

.card {
  width: min(560px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.drop {
  display: block;
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.drop.over, .drop:hover { border-color: var(--accent); background: rgba(212,162,76,.06); }
.drop strong { display: block; color: var(--fg); font-size: 17px; margin-bottom: 4px; }
.drop input { display: none; }
.drop .file { margin-top: 12px; color: var(--accent); word-break: break-all; }

label.field { display: block; margin: 16px 0 6px; color: var(--muted); font-size: 13px; }
.logorow { display: flex; align-items: center; gap: 12px; }
.logorow .logopick {
  flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 10px 14px; border: 1px dashed var(--line); border-radius: 10px;
  color: var(--muted); font-size: 14px; cursor: pointer;
}
.logorow .logopick:hover { border-color: var(--accent); }
.logorow .logopick input { display: none; }
.logorow .logopick img { height: 32px; max-width: 140px; object-fit: contain; border-radius: 4px; background: rgba(255,255,255,.06); }
.logorow .logopick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logorow .clear { width: auto; margin: 0; padding: 0 14px; height: 44px; }
.or { display: flex; align-items: center; gap: 12px; margin: 16px 0 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.linkrow { display: flex; gap: 8px; }
.linkrow input { flex: 1; min-width: 0; }
.linkrow .btn { width: auto; margin: 0; padding: 0 18px; }
input[type=text], input[type=url] {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-2); color: var(--fg); font: inherit;
}
input[type=text]:focus, input[type=url]:focus { outline: none; border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 18px; padding: 14px 18px;
  border: 0; border-radius: 12px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #1a1207; font-weight: 700; font-size: 16px;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); font-weight: 500; }

.status { margin-top: 12px; color: var(--muted); font-size: 14px; min-height: 1.4em; }
.progress.upload { width: 100%; margin-top: 16px; }
.note { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.status.err { color: #ff8a80; }

.result { display: none; }
.result.show { display: block; }
.result .link {
  display: flex; gap: 8px; margin-top: 10px;
}
.result .link input { flex: 1; }
.result .link button { flex-shrink: 0; width: auto; margin: 0; padding: 0 16px; }
.result .row { display: flex; gap: 10px; flex-wrap: wrap; }
.result .row .btn { flex: 1; min-width: 140px; }
.result .preview {
  display: block; width: 120px; margin: 16px auto 0;
  border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

.foot { margin-top: 28px; color: var(--muted); font-size: 12px; text-align: center; }
.foot a { color: var(--muted); }

.book { transform-origin: center center; }
.book.animate { transition: transform .4s cubic-bezier(.4,0,.2,1); }
.book.zoomed { cursor: grab; }
.zoomctl { display: inline-flex; align-items: center; gap: 4px; }
.zoom-level { min-width: 40px; text-align: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .zoom-level { display: none; } }


.ctl:focus:not(:focus-visible) { outline: none; }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
