:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --ink: #16160f;
  --muted: #6a6a60;
  --line: #d9d9d2;
  --accent: #8a5a2b;
  --box: rgba(138, 90, 43, 0.38);
  --sel: rgba(120, 160, 255, 0.40);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16160f;
    --panel: #1e1e17;
    --ink: #ecece4;
    --muted: #9a9a8e;
    --line: #33332a;
    --accent: #d2a06a;
    --box: rgba(210, 160, 106, 0.42);
    --sel: rgba(120, 160, 255, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.titles h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.titles p  { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

nav { display: flex; align-items: center; gap: 10px; }

nav button {
  width: 34px; height: 34px;
  font-size: 19px; line-height: 1;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
nav button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
nav button:disabled { opacity: 0.35; cursor: default; }

.jump { display: flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--muted); }
.jump input {
  width: 62px; padding: 6px 8px;
  font: inherit; text-align: right;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

main { padding: 24px 20px 40px; }

.stage { display: flex; justify-content: center; }

/* The page box is the shared coordinate space. Its aspect ratio comes from the
   built page dimensions, and every word is placed as a PERCENTAGE of it -- so
   the overlay stays registered at any rendered size, with no rescaling maths. */
.page {
  position: relative;
  container-type: inline-size;
  width: min(100%, 900px);
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.14), 0 12px 32px rgba(0,0,0,.12);
}

.page img { display: block; width: 100%; height: auto; }

.layer { position: absolute; inset: 0; }

.layer span {
  position: absolute;
  margin: 0;
  color: transparent;
  white-space: pre;
  transform-origin: 0 0;
  cursor: text;
}

.layer span::selection { background: var(--sel); }

.page.boxes .layer span { outline: 1px solid var(--box); }

footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px 40px;
  font-size: 13px;
  color: var(--muted);
}
footer strong { color: var(--ink); font-weight: 600; }
