:root {
  --ink: #171716;
  --paper: #f4e8d0;
  --mint: #0397a7;
  --red: #f03925;
  --yellow: #f2b705;
  --muted: #6e6459;
  --line: rgba(23, 23, 22, 0.22);
  --ui: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  background:
    linear-gradient(rgba(244, 232, 208, 0.91), rgba(244, 232, 208, 0.91)),
    url("assets/ui/comedy-collage-bg.png") center / cover fixed;
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--paper);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.reader {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  padding: 18px clamp(18px, 3vw, 46px) 16px;
  overflow: hidden;
}

.reader-header,
.reader-toolbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 44px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
}

.back-link:hover { color: var(--mint); }

.back-link svg,
.page-edge svg {
  width: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.reader-title {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  white-space: nowrap;
}

.reader-title strong {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.06em;
}

.reader-title strong span { color: var(--red); }

.reader-title small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.reader-actions {
  display: flex;
  justify-content: flex-end;
  gap: clamp(14px, 2vw, 28px);
}

.reader-actions a {
  padding: 5px 0;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
}

.reader-actions a:hover { color: var(--mint); }

.reader-workspace {
  position: relative;
  display: grid;
  grid-template-columns: clamp(34px, 5vw, 76px) minmax(0, 1fr) clamp(34px, 5vw, 76px);
  min-height: 0;
  padding: 12px 0;
}

.page-scroll {
  display: grid;
  place-items: start center;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-color: rgba(245, 242, 235, 0.3) transparent;
  scrollbar-width: thin;
}

.script-page {
  position: relative;
  width: min(var(--page-width, 612px), 100%);
  aspect-ratio: 612 / 792;
  margin: 0 auto;
  background: white;
  border: 3px solid var(--ink);
  box-shadow: 10px 12px 0 rgba(23, 23, 22, 0.18), 0 24px 70px rgba(62, 47, 27, 0.25);
  transform: rotate(-0.15deg);
  transition: width 180ms ease;
}

.script-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  transition: opacity 130ms ease;
}

.script-page.is-loading img { opacity: 0.34; }

.page-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  margin: -17px;
  border: 2px solid rgba(10, 10, 10, 0.16);
  border-top-color: var(--ink);
  border-radius: 50%;
  opacity: 0;
  animation: spin 700ms linear infinite;
}

.script-page.is-loading .page-loader { opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }

.page-edge {
  display: grid;
  place-items: center;
  align-self: center;
  width: 100%;
  height: 110px;
  border: 0;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.page-edge:hover { color: var(--mint); }
.page-edge:disabled { opacity: 0.2; cursor: default; }

.reader-toolbar { gap: 22px; }

.page-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-control input {
  width: 44px;
  padding: 5px 4px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fffdf6;
  text-align: center;
  appearance: textfield;
}

.page-control input::-webkit-inner-spin-button { appearance: none; }

.reader-progress {
  width: min(36vw, 440px);
  height: 5px;
  overflow: hidden;
  border: 1px solid var(--ink);
  background: #fffdf6;
}

.reader-progress span {
  display: block;
  width: calc(100% / 28);
  height: 100%;
  background: var(--red);
  transition: width 180ms ease;
}

.zoom-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.zoom-controls button {
  min-width: 34px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border: 2px solid var(--ink);
  color: var(--ink);
  background: #fffdf6;
  box-shadow: 2px 2px 0 var(--ink);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
}

.zoom-controls button:hover { color: var(--ink); background: var(--yellow); }
.zoom-controls button:disabled { opacity: 0.28; cursor: default; }

.reader-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  padding: 11px 14px;
  color: var(--ink);
  background: var(--paper);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.reader-toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 720px) {
  .reader { padding: 12px 10px 10px; }

  .reader-header,
  .reader-toolbar { grid-template-columns: 1fr auto; }

  .reader-title { justify-content: flex-start; grid-column: 1; grid-row: 1; }
  .back-link { grid-column: 2; grid-row: 1; }
  .back-link span { display: none; }
  .reader-actions { display: none; }

  .reader-workspace { grid-template-columns: 36px minmax(0, 1fr) 36px; padding: 8px 0; }
  .page-edge { height: 76px; }
  .page-edge svg { width: 22px; }

  .reader-toolbar { gap: 12px; }
  .reader-progress { display: none; }
  .zoom-controls { justify-self: end; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .reader { padding-top: 8px; padding-bottom: 6px; }
  .reader-header, .reader-toolbar { min-height: 34px; }
  .reader-workspace { padding: 4px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
