:root {
  --tile: #1d2a38;
  --tile-dark: #24364a;
  --page: #ffffff;
  --panel: #ffffff;
  --panel-alt: #f3f3f3;
  --ink: #1f1f1f;
  --muted: #5a5a5a;
  --red: #b3261e;
  --red-deep: #6f1512;
  --link: #c0261d;
  --visited: #8d1c18;
  --brick: #d63a2b;
  --border: #777777;
  --bevel-light: #ffffff;
  --bevel-dark: #adadad;
  /* The greys the chrome is built from: controls, frames and hairlines. Named
     here so every button and border pulls from the same few values. */
  --surface: #e8e8e8;
  --surface-hover: #f3f3f3;
  --chrome: #ededed;
  --frame: #9a9a9a;
  --hairline: #999999;
  --hairline-soft: #dddddd;
  --dashed: #adadad;
  --panel-line: #1f1f1f;
  --kbd-bg: #eeeeee;
  --kbd-border: #bbbbbb;
  --image-bg: #ffffff;
}

* { box-sizing: border-box; }

html { background: var(--tile); }

body {
  margin: 0;
  padding: 16px 10px 28px;
  color: var(--ink);
  font: 13px/1.5 Verdana, Geneva, Arial, sans-serif;
  background-color: var(--tile);
  background-image:
    linear-gradient(45deg, var(--tile-dark) 25%, transparent 25%, transparent 75%, var(--tile-dark) 75%),
    linear-gradient(45deg, var(--tile-dark) 25%, transparent 25%, transparent 75%, var(--tile-dark) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); }
a:visited { color: var(--visited); }
a:hover { color: var(--brick); }

.page {
  max-width: 900px;
  margin: 0 auto;
  background: var(--page);
  border: 3px ridge var(--frame);
}

.banner {
  padding: 26px 16px 20px;
  text-align: center;
  color: #f7f3f2;
  background: linear-gradient(180deg, #b22a22 0%, #94201b 55%, #741714 100%);
  border-bottom: 3px double var(--red-deep);
}

.banner h1 {
  margin: 0;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  text-shadow: 2px 2px 0 #4a0f0d;
}

.banner-sub {
  margin: 4px 0 0;
  font: italic 13px Georgia, "Times New Roman", serif;
  color: #f0d8d4;
}

.navbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 10px;
  font-size: 11px;
  background: var(--chrome);
  border-bottom: 1px solid var(--hairline);
}

.navbar .sep { color: var(--hairline); }
.navbar .current { color: var(--muted); }

.sheet {
  position: relative;
  margin: 14px;
  padding: clamp(16px, 3.5vw, 30px) clamp(14px, 3.5vw, 32px) clamp(20px, 3.5vw, 30px);
  text-align: center;
  background: var(--panel);
}

.sheet-tools {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  margin: 0;
}

.all-pages-btn {
  padding: 2px 8px;
  font: 10px Verdana, Geneva, Arial, sans-serif;
  color: var(--link);
  background: var(--surface);
  border: 2px outset var(--bevel-light);
  cursor: pointer;
}

.all-pages-btn:hover { color: var(--brick); background: var(--surface-hover); }
.all-pages-btn:active { border-style: inset; }

.page-list {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px 16px;
  overflow: auto;
  background: rgba(15, 23, 32, 0.62);
}

.page-list[hidden] { display: none; }

.page-list-panel {
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow: auto;
  padding: 14px 16px 16px;
  background: var(--panel);
  border: 3px ridge var(--frame);
}

.page-list-panel h2 {
  margin: 0 0 10px;
  padding-bottom: 5px;
  font: bold 18px "Times New Roman", Times, serif;
  border-bottom: 2px solid var(--red);
}

.page-list-items {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}

.page-list-section + .page-list-section { margin-top: 16px; }

.page-list-section h3 {
  margin: 0 0 4px;
  padding-bottom: 3px;
  font: bold 13px "Times New Roman", Times, serif;
  color: var(--red-deep);
  border-bottom: 1px solid var(--hairline-soft);
}

.page-list-section h3 .part {
  font: italic 11px Verdana, Geneva, Arial, sans-serif;
  color: var(--muted);
}

.page-list-item-list {
  margin: 0;
  padding-left: 26px;
  font-size: 12px;
}

.page-list-items li {
  padding: 2px 0;
}

.page-list-items a { text-decoration: none; }
.page-list-items a:hover { text-decoration: underline; }
.page-list-items li.current a { color: var(--muted); font-weight: bold; }
.page-list-items li.current a:hover { color: var(--brick); }

.page-list-actions {
  margin-top: 12px;
  text-align: right;
}

body.page-list-open { overflow: hidden; }

#page { text-align: center; }

.page-title {
  max-width: 680px;
  margin: 0 auto 20px;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(1.15rem, 2.8vw, 1.5rem);
  font-weight: bold;
  color: var(--ink);
}

#page img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto 18px;
  background: var(--image-bg);
  border: 1px solid var(--panel-line);
}

#page img:last-child { margin-bottom: 0; }

.line {
  max-width: 660px;
  margin: 22px auto;
  padding: 0 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.9rem, 1.6vw, 1rem);
  font-weight: bold;
  line-height: 1.6;
  text-align: left;
  white-space: pre-line;
  overflow-wrap: break-word;
  filter: saturate(0.55) brightness(0.72);
}

.line.serif {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.98rem, 1.8vw, 1.08rem);
  font-style: italic;
  line-height: 1.65;
}

.linee {
  max-width: 660px;
  margin: 22px auto;
  padding: 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.95rem, 1.7vw, 1.05rem);
  line-height: 1.65;
  text-align: left;
  white-space: pre-line;
  overflow-wrap: break-word;
}

.shout {
  max-width: 680px;
  margin: 26px auto 16px;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(1.3rem, 3.4vw, 1.8rem);
  font-weight: bold;
  line-height: 1.2;
  text-align: center;
  color: var(--brick);
}

.note {
  max-width: 680px;
  margin: 22px auto;
  padding: 7px 0;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
  border-top: 1px dashed var(--dashed);
  border-bottom: 1px dashed var(--dashed);
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 26px auto 0;
}

#prev,
#next {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0;
  padding: 5px 16px;
  font: bold 12px Verdana, Geneva, Arial, sans-serif;
  text-decoration: none;
  color: var(--link);
  background: var(--surface);
  border: 2px outset var(--bevel-light);
}

#prev[hidden],
#next[hidden] { display: none; }

#prev:visited,
#next:visited { color: var(--link); }
#prev:hover,
#next:hover { color: var(--brick); background: var(--surface-hover); }
#prev:active,
#next:active { border-style: inset; }

.reader-nudge {
  margin: 12px auto 0;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.reader-nudge.is-on { opacity: 1; }

.reader-nudge kbd {
  padding: 0 3px;
  font: inherit;
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
}

.bottom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 14px 14px;
  padding: 8px;
  background: transparent;
}

.save-btn {
  padding: 3px 10px;
  font: 11px Verdana, Geneva, Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
  border: 2px outset var(--bevel-light);
  cursor: pointer;
}

.save-btn:hover { background: var(--surface-hover); }
.save-btn:active { border-style: inset; }

.save-btn.armed {
  color: #fff7f4;
  background: var(--brick);
  border-color: #6f2a1e;
}

.save-status {
  flex-basis: 100%;
  min-height: 1.1em;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

.comic-readme {
  margin: 0 14px 16px;
  padding: 12px 4px 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
  border-top: 1px dashed var(--dashed);
}

.comic-readme[hidden] { display: none; }

.comic-readme .readme-title {
  margin: 0 0 6px;
  font: bold 15px "Times New Roman", Times, serif;
  color: var(--red-deep);
}

.comic-readme p {
  max-width: 640px;
  margin: 0 0 6px;
}

.comic-readme .readme-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 3px 12px;
  margin: 10px 0 0;
}

.comic-readme dt {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--red);
}

.comic-readme dd {
  margin: 0;
}

.autosave {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
}

.autosave input {
  margin: 0;
  accent-color: var(--brick);
}

a:focus-visible,
button:focus-visible {
  outline: 2px dotted var(--brick);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  body { padding: 8px 6px 52px; }
  .banner { padding: 20px 12px 16px; }
  .sheet { margin: 10px; padding: 16px 12px 20px; }
  .sheet-tools { position: static; margin: 0 0 6px; }
  .bottom-bar { margin-left: 10px; margin-right: 10px; }
  .theme-toggle { right: 6px; bottom: 6px; padding: 2px 8px; font-size: 10px; }
}

/* The mode switch floats in the corner, so it is reachable from anywhere in a
   comic without pushing the layout around. */
.theme-toggle {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  padding: 4px 12px;
  font: bold 11px Verdana, Geneva, Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
  border: 2px outset var(--bevel-light);
  box-shadow: 0 0 0 1px var(--hairline);
  cursor: pointer;
}

.theme-toggle:hover { color: var(--brick); background: var(--surface-hover); }
.theme-toggle:active { border-style: inset; }

/* Dark mode darkens the site, not the comic. The panels are drawn on white and
   the dialogue uses the author's own colours (blue, lime, violet...), which
   only read against a light background, so the story keeps its white blocks
   and everything around them goes dark. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --tile: #14120f;
  --tile-dark: #1a1714;
  --page: #1e1b18;
  --panel: #1e1b18;
  --panel-alt: #262220;
  --ink: #eae5dd;
  --muted: #a9a29a;
  --red: #ff7f6e;
  --red-deep: #ffa79b;
  --link: #ff8d7d;
  --visited: #d8948a;
  --brick: #ea5b4a;
  --border: #4a453f;
  --bevel-light: #45403a;
  --bevel-dark: #100e0c;
  --surface: #2a2622;
  --surface-hover: #34302b;
  --chrome: #221f1b;
  --frame: #3a352f;
  --hairline: #393430;
  --hairline-soft: #2c2823;
  --dashed: #3d3833;
  --panel-line: #6b645c;
  --kbd-bg: #2b2724;
  --kbd-border: #4a443e;
  --paper: #ffffff;
  --paper-ink: #1f1f1f;
  --paper-line: #24211e;
}

:root[data-theme="dark"] .banner {
  background: linear-gradient(180deg, #8f2219 0%, #741a14 55%, #52100c 100%);
  border-bottom-color: #3d0b08;
}

/* Plain ink reads straight off the dark sheet. Only the saturation filter
   survives from the light rule: brightness() would dim the text itself. */
:root[data-theme="dark"] .line,
:root[data-theme="dark"] .linee {
  color: var(--ink);
  filter: saturate(0.55);
}

/* A block the author gave a colour to keeps that colour, so it keeps a white
   card to sit on. Black is the exception, handled below. */
:root[data-theme="dark"] .line[style*="color"],
:root[data-theme="dark"] .linee[style*="color"] {
  padding: 12px 14px;
  color: var(--paper-ink);
  background: var(--paper);
  border: 1px solid var(--paper-line);
}

/* Black text would vanish on a dark sheet, so it flips to the theme's ink
   instead of dragging a white card along with it. */
:root[data-theme="dark"] .line[style*="black"],
:root[data-theme="dark"] .linee[style*="black"] {
  padding: 0 4px;
  color: var(--ink) !important;
  background: transparent;
  border: 0;
}

