/* Share link viewer. Paper stays opaque and warm; chrome stays quiet. */

:root {
  /* Palette: Floral White, Dust Grey, Charcoal Brown, Carbon Black and
     Spicy Paprika. --accent is Paprika dark enough for text (AA);
     --accent-fill is Paprika itself, with Carbon Black text on it. */
  --bg: #f5f1e7;
  --surface: #fffcf2;
  --text: #252422;
  --muted: #5c5853;
  --line: #ccc5b9;
  --accent: #b9461a;
  --accent-fill: #eb5e28;
  --accent-text: #252422;
  --shadow: 0 1px 2px rgb(60 40 20 / 0.12), 0 8px 24px rgb(60 40 20 / 0.14);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #252422;
    --surface: #403d39;
    --text: #fffcf2;
    --muted: #ccc5b9;
    --line: #4a4743;
    --accent: #f5926b;
    --accent-fill: #eb5e28;
    --accent-text: #252422;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 28px rgb(0 0 0 / 0.45);
  }
}

@media (prefers-contrast: more) {
  :root { --muted: var(--text); --line: var(--text); }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}

.brand {
  font: 700 15px/1 ui-rounded, -apple-system, system-ui, sans-serif;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-decoration: none;
  flex-shrink: 0;
}

.titles { min-width: 0; }

h1 {
  margin: 0;
  font: 600 1.35rem/1.2 ui-serif, "New York", Georgia, serif;
  overflow-wrap: anywhere;
}

h2 { margin: 0 0 8px; font-size: 1.2rem; }

.meta { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  outline: none;
}

.status {
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
  padding: 48px 16px;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

.card {
  width: min(420px, calc(100% - 32px));
  margin: 32px auto;
  padding: 24px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.card p { margin: 0 0 16px; color: var(--muted); }

label { display: block; font-weight: 600; margin-bottom: 6px; }

input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-fill);
  color: var(--accent-text);
  cursor: pointer;
}

button:disabled { opacity: 0.4; cursor: default; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.error { color: var(--accent) !important; font-weight: 600; }

.book { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }

.pages {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  outline: none;
}

.pages::-webkit-scrollbar { display: none; }

.page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  margin: 0;
  padding: 12px 16px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 10px;
}

.page img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 230px);
  width: auto;
  height: auto;
  border-radius: 3px;
  background: #fff;
  box-shadow: var(--shadow);
}

.page figcaption { color: var(--muted); font-size: 0.9rem; text-align: center; }

/* A board: one continuous canvas, fitted to the window. Tap for full width. */
.pages.boards {
  flex-direction: column;
  overflow-x: visible;
  scroll-snap-type: none;
  gap: 24px;
}

.canvas {
  margin: 0;
  padding: 12px 16px;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(var(--columns), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  aspect-ratio: var(--aspect);
  width: min(100%, calc((100dvh - 200px) * var(--aspect)));
  overflow: hidden;
  border-radius: 3px;
  background: #fff;
  box-shadow: var(--shadow);
  cursor: zoom-in;
}

.canvas.full-width .tiles { width: 100%; cursor: zoom-out; }

/* 1px overlap hides hairline seams between tiles when the browser scales them. */
.tiles img {
  display: block;
  width: calc(100% + 1px);
  height: calc(100% + 1px);
  min-width: 0;
  object-fit: cover;
}

.canvas figcaption { color: var(--muted); font-size: 0.9rem; text-align: center; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.round { width: 44px; height: 44px; padding: 0; font-size: 1.6rem; line-height: 1; }

.bottom {
  padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.bottom p { margin: 4px 0; }

.links { display: flex; justify-content: center; flex-wrap: wrap; gap: 16px; }

.links a { padding: 8px 0; }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  .pages { scroll-behavior: auto; }
}
