:root {
  --bg: #000;
  --bg-2: #141414;
  --fg: #f2f2f2;
  --muted: #9a9a9a;
  --accent: #ff5a5f;
  --border: #2e2e2e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* the visible height on phones, even with the address bar showing */
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; }

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar-actions { display: flex; gap: 8px; }

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
}
.ghost:hover { border-color: var(--muted); }

/* ---------- Upload ---------- */
.upload-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 16px;
}

.drop-zone {
  width: min(560px, 100%);
  padding: 48px 24px;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: 16px;
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.drop-zone:hover,
.drop-zone.dragging { border-color: var(--accent); transform: scale(1.01); }
.drop-zone h1 { margin: 8px 0; font-size: 1.5rem; }
.drop-zone p { margin: 4px 0; color: var(--muted); }
.drop-icon { font-size: 2.5rem; color: var(--accent); }
.link { color: var(--accent); text-decoration: underline; }
.hint { font-size: 0.85rem; }

.progress { width: min(560px, 100%); }
.progress-label { margin-bottom: 6px; color: var(--muted); }
.progress-track {
  height: 8px;
  border-radius: 4px;
  background: var(--bg-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s;
}

.error { color: var(--accent); }

/* ---------- Viewer ---------- */
.viewer-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 0 0;
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  overflow: hidden;
  position: relative;
  touch-action: none; /* pinch and swipe on the book are handled by the app */
}

.book-wrap {
  flex: 1;
  max-width: 1400px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stf__parent { margin: 0 auto; }

/* Drop shadow that hugs the visible pages (cover alone or a full spread),
   so the book lifts off the black background. drop-shadow follows the
   painted pages rather than the book's full bounding box. */
.stf__block {
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.3));
}

/* Gutter shading where the two pages meet the spine. */
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.page.--left::after {
  background: linear-gradient(to left, rgba(0, 0, 0, 0.07), rgba(0, 0, 0, 0) 4%);
}
.page.--right::after {
  background: linear-gradient(to right, rgba(0, 0, 0, 0.07), rgba(0, 0, 0, 0) 4%);
}

.page-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.nav {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-2);
  font-size: 1.6rem;
  line-height: 1;
}
.nav:hover { border-color: var(--accent); }
.nav:disabled { opacity: 0.3; cursor: default; }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--muted);
}
.doc-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-info { white-space: nowrap; }
.page-info input {
  width: 4em;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-2);
  color: var(--fg);
  text-align: center;
}

.thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 20px 16px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
}
.thumbs img {
  flex: none;
  height: 72px;
  border: 2px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  background: #fff;
}
.thumbs img.active { border-color: var(--accent); }

.primary {
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 12px;
  color: #fff;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.1); }
.primary:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Library ---------- */
.library { width: min(560px, 100%); }
.library h2 { font-size: 1rem; margin: 8px 0; color: var(--muted); font-weight: 600; }
.library ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.library a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--fg);
  text-decoration: none;
}
.library a:hover { border-color: var(--accent); }
.library .meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }

/* ---------- Share bar ---------- */
.share-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--muted);
}
.share-bar input {
  flex: 1;
  min-width: 200px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

@media (max-width: 640px) {
  .nav { display: none; }
  .thumbs img { height: 56px; }
}

/* ---------- Sign-in ---------- */
.card {
  width: min(400px, 100%);
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-2);
}
.sign-in { display: grid; gap: 12px; }
.sign-in h1 { margin: 0; font-size: 1.4rem; }
.sign-in p { margin: 0; }
.sign-in label { display: grid; gap: 4px; color: var(--muted); font-size: 0.9rem; }
.sign-in input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
.sign-in .primary { padding: 10px; }

/* ---------- Library rows ---------- */
.library li { display: flex; gap: 6px; }
.library li a { flex: 1; min-width: 0; }
.library li a span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library li button { flex: none; }

/* ---------- Recipient link mode: only the deck, nothing else ---------- */
.link-mode .drop-zone,
.link-mode .library,
.link-mode #newBtn { display: none !important; }

/* ---------- Download option ---------- */
.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.topbar-actions { align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* Pages can't be selected, long-pressed (iOS "Save image") or dragged out. */
.book-wrap, .thumbs {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- Page curl ----------
   StPageFlip draws .stf__innerShadow as a band on the turning page, with the
   fold at the edge its gradient starts from ("to left" or "to right"). This
   adds a rounded-paper look on top: crease, highlight, then a soft shade.
   --curl (0 to ~0.55) is set per frame in app.js, so the curl fades in and out. */
.stf__innerShadow::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--curl, 0);
}
.stf__innerShadow[style*="to left"]::after {
  background: linear-gradient(to left,
    rgba(0, 0, 0, 0.22) 0%,
    rgba(0, 0, 0, 0.04) 5%,
    rgba(255, 255, 255, 0.6) 13%,
    rgba(0, 0, 0, 0.14) 32%,
    rgba(0, 0, 0, 0) 70%);
}
.stf__innerShadow[style*="to right"]::after {
  background: linear-gradient(to right,
    rgba(0, 0, 0, 0.22) 0%,
    rgba(0, 0, 0, 0.04) 5%,
    rgba(255, 255, 255, 0.6) 13%,
    rgba(0, 0, 0, 0.14) 32%,
    rgba(0, 0, 0, 0) 70%);
}

/* ---------- Page overview toggle ---------- */
.controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ghost.small {
  padding: 3px 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.ghost.small:hover { color: var(--fg); }

/* ---------- Zoom ---------- */
.book-wrap {
  transform-origin: 50% 50%;
  transition: transform 0.18s ease-out;
}
.stage.live .book-wrap { transition: none; } /* drag/pinch/scroll follow the pointer exactly */
.pan-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: grab;
  touch-action: none;
}
.pan-layer.dragging { cursor: grabbing; }
.nav { position: relative; z-index: 3; } /* arrows stay clickable above the zoomed book */
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom .ghost.small { min-width: 30px; }
.zoom-label { min-width: 56px !important; font-variant-numeric: tabular-nums; }
.zoom .ghost.small:disabled { opacity: 0.35; cursor: default; }
.controls { flex-wrap: wrap; row-gap: 6px; }
.controls-right { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) {
  .controls-right { gap: 8px; }
}

/* Blank sheet revealed when turning onto a lone cover (see blankUnderCovers). */
.page-blank { background: var(--bg); }
.page-blank::after { display: none; }

/* ---------- Background colour ----------
   --bg is set on <html> by app.js from the deck's saved colour. Custom colours
   switch the controls to translucent tints so they suit any colour, and light
   colours get dark text. */
:root[data-tone="dark"] {
  --bg-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.18);
}
:root[data-tone="light"] {
  --fg: #161616;
  --muted: #555555;
  --bg-2: rgba(0, 0, 0, 0.06);
  --border: rgba(0, 0, 0, 0.18);
}
:root[data-tone="light"] .topbar,
:root[data-tone="light"] .thumbs { background: rgba(0, 0, 0, 0.04); }
html { background: var(--bg); }
body, .topbar, .thumbs { transition: background-color 0.2s ease; }

.bg-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}
.bg-picker input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.bg-picker input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.bg-picker input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.bg-picker input[type="text"] {
  width: 5.5em;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--fg);
  font: 0.85rem ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}
.bg-picker input.invalid { border-color: var(--accent); }

/* ---------- Room for the host's badge (see watchHostBadge in app.js) ----------
   Computers: our controls stop short of the badge's corner.
   Phones: too narrow to share a row, so the badge gets its own strip below. */
:root { --host-badge-w: 214px; --host-badge-h: 64px; }
.has-host-badge .controls,
.has-host-badge .thumbs { padding-right: var(--host-badge-w); }
@media (max-width: 640px) {
  .has-host-badge .controls,
  .has-host-badge .thumbs { padding-right: 20px; }
  .has-host-badge .viewer-view { padding-bottom: var(--host-badge-h); }
}

/* ---------- Replace / Delete ---------- */
.library li { flex-wrap: wrap; }
.ghost.danger { color: #ff8a8d; }
.ghost.danger:hover { border-color: var(--accent); color: var(--accent); }
.replace-note {
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 28em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
