/* Comicwell: black ground, cover-led, square panels and one orange accent. Earlier plan and critique: ../DESIGN.md */

:root {
  --orange: #e4572e;      /* the accent: black text on it is 5.7:1 */
  --orange-ink: #ff8a63;  /* accent text and links on black (9.1:1), panels and raised panels (6.2:1) */
  --ink: #000;            /* the ground */
  --panel: #1c1c1c;
  --caption: #2a2a2a;     /* raised: the reader's narration box, chips, the search box */
  --line-ink: #3d3d3d;    /* rules and outlines */
  --muted-ink: #b5b5b5;   /* body muted, at least 7:1 on every ground here */

  --display: "Avenir Next Condensed", "Bahnschrift", "DIN Condensed", "Roboto Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --text: "Iowan Old Style", "Charter", "Sitka Text", Cambria, Georgia, serif;

  /* perfect fourth: 14 / 16 / 19 / 25 / 33 / 44 */
  --s-1: 0.875rem;
  --s0: 1rem;
  --s1: 1.1875rem;
  --s2: 1.5625rem;
  --s3: 2.0625rem;
  --s4: 2.75rem;

  --gutter: clamp(10px, 1.2vw, 16px);  /* between panels */
  --side: clamp(16px, 4vw, 48px);
  --max: 1240px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: #e9e9e9;
  font: 400 var(--s1)/1.6 var(--text);
  font-kerning: normal;
}
img { display: block; max-width: 100%; height: auto; }
/* `hidden` wins over any display rule (Share stays hidden without site.js). */
[hidden] { display: none !important; }
h1, h2, h3 {
  font-family: var(--display);
  font-stretch: condensed;
  font-weight: 700;
  line-height: 1.05;
  margin: 0;
  text-wrap: balance;
}
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
a { color: inherit; text-decoration-thickness: 0.08em; text-underline-offset: 0.18em; }
:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.wrap { width: 100%; max-width: var(--max); margin-inline: auto; padding-inline: var(--side); }
.vh {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: 12px; top: -100px; z-index: 10;
  background: var(--orange); color: var(--ink); padding: 10px 14px; font-family: var(--display); font-weight: 700;
}
.skip:focus { top: 12px; }

/* ---------- Masthead (all pages): wordmark, browse links, search, the reader's links ---------- */

.masthead { background: var(--ink); color: #fff; border-bottom: 1px solid var(--caption); }
.masthead-row { display: flex; align-items: center; gap: 4px 24px; min-height: 72px; flex-wrap: wrap; padding-block: 8px; }
.brand {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px;
  text-decoration: none; font: 700 1.75rem/1 var(--display); font-stretch: condensed; letter-spacing: -0.01em;
}
.brand img { width: 40px; height: 40px; margin-left: -6px; }
.masthead nav { flex: 1 1 0; min-width: min(100%, 20rem); }
.masthead nav ul { display: flex; align-items: center; gap: 4px 22px; list-style: none; flex-wrap: wrap; }
.masthead nav a, .masthead nav button {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0;
  font: 700 var(--s1)/1 var(--display); font-stretch: condensed; letter-spacing: 0.01em;
  text-decoration: none; color: #fff; background: none; border: 0; cursor: pointer;
}
.masthead nav a:hover, .masthead nav button:hover, .masthead nav a[aria-current="page"] { color: var(--orange-ink); }
.nav-search { flex: 1 1 200px; min-width: 0; }
/* Under 480px the row is full: Genres goes (it is on the home and /browse), Legends stays. */
@media (max-width: 479px) { .nav-genres { display: none; } }
.nav-search label { display: block; }
.nav-search input {
  width: 100%; height: 44px; padding: 0 14px; border: 0; border-radius: 0; background: var(--caption); color: #fff;
  font: 500 var(--s0)/1 var(--display); font-stretch: condensed; -webkit-appearance: none; appearance: none;
}
.nav-search input::placeholder { color: var(--muted-ink); opacity: 1; }
.nav-search input:focus-visible { outline-offset: 0; }

/* ---------- Shared blocks ---------- */

/* A row of covers: a grid on desktop, a sideways scroll under 900px. .row-grid stays a grid at every width. */
.row-covers { list-style: none; display: grid; gap: 22px 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.cover-card { display: block; color: #fff; text-decoration: none; }
.cover-card img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--panel); }
.cover-card.book img { aspect-ratio: 720 / 1140; }
.cover-card .t { display: block; margin-top: 8px; font: 700 var(--s1)/1.2 var(--display); font-stretch: condensed; }
.cover-card .m { display: block; margin-top: 2px; font-size: var(--s-1); line-height: 1.35; color: var(--muted-ink); }
.cover-card:hover .t { color: var(--orange-ink); }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; background: var(--caption); color: #fff;
  font: 700 var(--s0)/1.1 var(--display); font-stretch: condensed; text-decoration: none;
}
.chip:hover, .chip[aria-current="true"] { background: var(--orange); color: var(--ink); }

.panel-box { background: var(--panel); padding: 20px; margin-bottom: 16px; }
.panel-box h2 { font-size: var(--s2); margin-bottom: 10px; }

/* A numbered list of series: the place is the content, so the number is real. */
.ranked { list-style: none; display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); counter-reset: ranked; }
.ranked li { counter-increment: ranked; }
.ranked a {
  display: flex; align-items: center; gap: 14px; min-height: 84px; padding: 10px; background: var(--panel); color: #fff; text-decoration: none;
}
.ranked a::before {
  content: counter(ranked); flex: none; width: 1.2em; text-align: center; color: var(--orange-ink);
  font: 700 var(--s3)/1 var(--display); font-stretch: condensed;
}
.ranked a:hover { background: var(--caption); }
.ranked img { width: 48px; height: 64px; flex: none; object-fit: cover; background: var(--caption); }
.ranked .t { display: block; font: 700 var(--s1)/1.2 var(--display); font-stretch: condensed; }
.ranked .m { display: block; font-size: var(--s-1); line-height: 1.35; color: var(--muted-ink); }

/* ---------- Home: the site sentence, then the featured hero ---------- */

.home { color: #fff; }
.home-intro { padding-block: clamp(28px, 4vw, 56px) clamp(24px, 3vw, 40px); }
.home-h1 { font-size: clamp(2.5rem, 5.6vw, 4.75rem); line-height: 0.95; letter-spacing: -0.02em; max-width: 16ch; color: #fff; }
.home-intro .lede { margin-top: 18px; }
.home-intro .store { margin-top: 24px; }
.store-note a, .app-lede a { color: var(--orange-ink); }

/* The hero: a scroll-snap row of slides, all in the HTML. Without JavaScript it scrolls sideways; the thumbnails are
   links to each slide. Fixed aspect ratio, so nothing shifts while the banner loads. */
.hero { overflow: hidden; }
.hero-slides {
  list-style: none; display: grid; grid-auto-flow: column; grid-auto-columns: 100%;
  overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none;
}
.hero-slides::-webkit-scrollbar { display: none; }
.hero-slide { position: relative; scroll-snap-align: start; background: var(--panel); }
.hero-slide img { width: 100%; height: clamp(360px, 42vw, 520px); object-fit: cover; }
.hero-cap {
  position: absolute; left: 32px; bottom: 32px; width: 440px; max-width: calc(100% - 64px);
  background: var(--ink); color: #fff; padding: 24px; box-shadow: 6px 6px 0 0 var(--orange);
}
.hero-genre { color: var(--orange-ink); font: 700 var(--s0)/1.2 var(--display); font-stretch: condensed; }
.hero-cap h2 { margin: 4px 0 8px; font-size: clamp(var(--s3), 3.6vw, var(--s4)); line-height: 1; }
.hero-cap p:not(.hero-genre):not(.actions) { font-size: var(--s0); line-height: 1.45; }
.hero-cap .actions { margin-top: 16px; gap: 10px; }
.hero-thumbs { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.hero-thumbs a { display: block; height: 84px; overflow: hidden; background: var(--panel); outline: 3px solid transparent; outline-offset: -3px; }
.hero-thumbs img { width: 100%; height: 100%; object-fit: cover; opacity: 0.6; }
.hero-thumbs a:hover img, .hero-thumbs a[aria-current="true"] img { opacity: 1; }
.hero-thumbs a[aria-current="true"] { outline-color: var(--orange); }
.hero-thumbs a:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

/* ---------- Home: cover rows ---------- */

.home-row { padding-top: clamp(40px, 5vw, 56px); }
.home-row h2 { font-size: clamp(var(--s3), 3.6vw, 2.75rem); letter-spacing: -0.015em; color: #fff; }
.home-row > h2, .row-top { margin-bottom: 16px; }
.row-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; }
.row-top a { color: var(--orange-ink); font: 700 var(--s1)/1.2 var(--display); font-stretch: condensed; min-height: 44px; display: inline-flex; align-items: center; }
.home-split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 32px; }
.home-split h2 { margin-bottom: 16px; }
.home-split .genre-row { margin-top: 0; }
.home-split .genre-row h2 { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.home-split .genre-row ul { margin: 0 0 10px; }
.home-split .genre-row a { background: var(--orange); color: var(--ink); box-shadow: none; min-height: 44px; display: inline-flex; align-items: center; }
.app-lede { color: var(--muted-ink); max-width: 30em; }
.home-split .actions { margin-top: 14px; }

/* ---------- The static fallback home (web/index.html, WEB_READER off): the strip hero and comic-page grid ---------- */

.hero-grid {
  display: grid; gap: 40px var(--gutter);
  grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
  align-items: stretch;
  padding-top: clamp(24px, 5vw, 72px);
}
.hero-copy { padding-bottom: clamp(48px, 7vw, 96px); }

.cut {
  font-size: clamp(3.25rem, 7.2vw, 7rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
  max-width: 11ch;
}

.lede { font-size: var(--s1); max-width: 34em; margin-top: 28px; line-height: 1.55; }
.store {
  display: inline-flex; align-items: center; gap: 12px;
  margin-top: 32px; padding: 14px 22px 14px 18px;
  background: var(--orange); color: var(--ink);
  font: 700 var(--s1)/1.1 var(--display); font-stretch: condensed; letter-spacing: 0.01em;
  text-decoration: none;
}
.store svg { width: 26px; height: 26px; fill: currentColor; flex: none; }
a.store:hover { background: #fff; }
.store-note { margin-top: 18px; font-size: var(--s-1); }

/* A strip of real panels; it fills the hero's height and the last panel runs off the bottom edge. */
.strip { position: relative; overflow: hidden; min-height: 360px; }
.strip-inner { position: absolute; inset: 0 0 auto 0; display: flex; flex-direction: column; gap: var(--gutter); }
.strip img { width: 100%; flex: none; }

/* ---------- Home: the series (the fallback's comic-page grid below) ---------- */

.series { padding-block: clamp(48px, 7vw, 96px) 0; }
.series h2, .reading h2 { font-size: clamp(var(--s3), 4.4vw, 3.75rem); letter-spacing: -0.015em; }
.page {
  list-style: none;
  margin-top: clamp(28px, 4vw, 48px);
  display: grid; gap: var(--gutter);
  grid-template-columns: 2fr 1fr 1fr;
  grid-template-rows: auto auto;
}
.panel { position: relative; background: var(--ink); }
.panel img { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 3 / 4; }
.panel-lead { grid-row: span 2; }
.panel-wide { grid-column: 1 / -1; }
.panel-wide img { aspect-ratio: 16 / 7; object-position: center 25%; }
.caption {
  position: absolute; top: 12px; left: -6px;
  max-width: min(78%, 21em);
  background: var(--ink); color: #fff;
  padding: 10px 12px 11px;
  font-size: var(--s0); line-height: 1.4;
  box-shadow: 4px 4px 0 0 var(--orange);
}
.panel-lead .caption { top: 20px; left: -8px; max-width: min(62%, 22em); font-size: var(--s1); padding: 14px 16px 15px; }
.genre {
  margin-top: 6px; color: var(--muted-ink);
  font: 600 var(--s-1)/1.2 var(--display); font-stretch: condensed; letter-spacing: 0.02em;
}

/* ---------- Home: the novels row ---------- */

.shelf-lede { font-size: var(--s1); line-height: 1.4; margin: -4px 0 18px; max-width: 34em; color: var(--muted-ink); }
.series-more a { color: var(--orange-ink); }

/* ---------- Home: interactive stories ---------- */

.story { padding-block: clamp(40px, 6vw, 80px); }
.story h2 { font-size: clamp(var(--s3), 4.4vw, 3.75rem); letter-spacing: -0.015em; }
.story-lede { font-size: var(--s2); line-height: 1.3; margin-top: 16px; max-width: 26em; }
.story p { max-width: 36em; margin-top: 12px; }

/* ---------- Home: how reading works ---------- */

.reading { color: #fff; padding-block: clamp(56px, 8vw, 112px); }
.reading-lede { font-size: var(--s2); line-height: 1.3; margin-top: 16px; max-width: 26em; }
.ruler { margin-top: clamp(32px, 4vw, 48px); }
.ticks {
  list-style: none;
  display: grid; grid-template-columns: repeat(26, minmax(0, 1fr)); gap: 4px;
  font: 600 0.75rem/1 var(--display); font-stretch: condensed;
}
.ticks li {
  aspect-ratio: 3 / 4; display: flex; align-items: flex-end; justify-content: flex-start;
  padding: 4px; background: var(--orange); color: var(--ink);
}
.ticks .paid { background: transparent; color: #fff; box-shadow: inset 0 0 0 2px var(--orange); }
.ticks .paid:last-child { mask-image: linear-gradient(to right, #000 20%, transparent); -webkit-mask-image: linear-gradient(to right, #000 20%, transparent); }
.ruler-key {
  display: grid; grid-template-columns: 20fr 6fr; gap: 4px; margin-top: 10px;
  font: 600 var(--s0)/1.2 var(--display); font-stretch: condensed;
}
.ruler-key span { border-top: 2px solid var(--orange); padding-top: 8px; }
.options {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px clamp(24px, 4vw, 56px);
  margin-top: clamp(40px, 5vw, 64px);
}
.options h3 { font-size: var(--s2); color: var(--orange-ink); }
.options p { margin-top: 10px; max-width: 26em; color: #e6e6e6; }
.promise {
  margin-top: clamp(40px, 5vw, 64px); padding-top: 24px; border-top: 1px solid var(--line-ink);
  font: 700 var(--s2)/1.2 var(--display); font-stretch: condensed;
}

/* ---------- Footer (all pages) ---------- */

.site-footer { background: var(--ink); color: #fff; border-top: 1px solid var(--caption); }
.footer-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px 32px;
  padding-block: 28px 36px;
  font: 600 var(--s0)/1.3 var(--display); font-stretch: condensed;
}
.footer-brand { display: inline-flex; align-items: center; gap: 12px; color: var(--muted-ink); }
.footer-brand img { width: 32px; height: 32px; }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 22px; }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- Documents: privacy, terms, support, delete account ---------- */

.doc { max-width: calc(70ch + 2 * var(--side)); padding-block: clamp(40px, 6vw, 80px) clamp(64px, 8vw, 112px); }
.doc-head { padding-bottom: 28px; margin-bottom: 8px; border-bottom: 4px solid var(--orange); }
.doc h1 { font-size: clamp(var(--s4), 7vw, 4.5rem); line-height: 0.95; letter-spacing: -0.02em; color: #fff; }
.doc .meta { margin-top: 14px; color: var(--muted-ink); font-size: var(--s0); }
.doc .intro { margin-top: 18px; font-size: var(--s1); }
.doc section { margin-top: 40px; }
.doc h2 { font-size: var(--s2); letter-spacing: -0.005em; display: flex; gap: 0.4em; align-items: baseline; color: #fff; }
.doc h2 .n { color: var(--orange-ink); min-width: 1.4em; }
.doc p, .doc ul, .doc ol, .doc dl { margin-top: 12px; }
.doc ul, .doc ol { padding-left: 1.3em; }
.doc li + li { margin-top: 8px; }
.doc li::marker { color: var(--orange-ink); }
.doc a { color: var(--orange-ink); overflow-wrap: anywhere; }
.doc a:hover { color: #fff; }
.doc strong { font-weight: 700; }
.doc h3 { margin-top: 24px; font-size: var(--s1); }
/* Comparison tables in the legends guides: scroll sideways on a phone instead of squeezing. */
.doc table {
  display: block; max-width: 100%; overflow-x: auto; margin-top: 16px;
  border-collapse: collapse; font-size: var(--s0); line-height: 1.45;
}
.doc caption { padding-bottom: 8px; text-align: left; font-weight: 700; }
.doc th, .doc td { min-width: 9em; padding: 10px 12px; border: 1px solid var(--line-ink); text-align: left; vertical-align: top; }
.doc thead th { border-bottom: 3px solid var(--orange); }
.doc tbody th { font-weight: 700; }
.series-more { margin-top: 28px; font-size: var(--s1); }
.series-more a { color: inherit; }
.faq dt {
  margin-top: 28px; font: 700 var(--s1)/1.25 var(--display); font-stretch: condensed;
}
.faq dt:first-child { margin-top: 8px; }
.faq dd { margin: 6px 0 0; }
.callout {
  margin-top: 28px; padding: 16px 20px; background: var(--panel); color: #fff;
}
.callout a { color: #fff; }
.callout > :first-child { margin-top: 0; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .hero-cap { left: 16px; bottom: 16px; max-width: calc(100% - 38px); padding: 16px; }
  .hero-thumbs a { height: 56px; }
  .home-split { grid-template-columns: minmax(0, 1fr); }
  .row-covers:not(.row-grid) {
    grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 42%;
    overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 8px;
  }
  .row-covers:not(.row-grid) > li { scroll-snap-align: start; }
  .ranked { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .page { grid-template-columns: 1fr 1fr; }
  .panel-lead { grid-column: 1 / -1; grid-row: auto; }
  .panel-lead img { aspect-ratio: 3 / 4; }
  .panel-wide img { aspect-ratio: 3 / 2; }
  .options { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .hero-copy { padding-bottom: 40px; }
  .strip { height: clamp(420px, 128vw, 640px); min-height: 0; max-width: 520px; }
}
@media (max-width: 600px) {
  .masthead-row { min-height: 60px; }
  .masthead nav { flex-basis: 100%; }
  .masthead nav ul { gap: 4px 16px; }
  .nav-search { order: 9; flex-basis: 100%; }
  .row-covers.row-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page { grid-template-columns: minmax(0, 1fr); }
  .caption, .panel-lead .caption { max-width: 80%; font-size: var(--s0); padding: 10px 12px 11px; top: 14px; left: -6px; }
  .ticks { grid-template-columns: repeat(13, minmax(0, 1fr)); }
  .ruler-key { grid-template-columns: 1fr; }
  .ruler-key span { border-top: 0; padding-top: 0; display: flex; align-items: center; gap: 8px; }
  .ruler-key span::before { content: ""; width: 14px; height: 14px; background: var(--orange); flex: none; }
  .ruler-key .key-paid::before { background: transparent; box-shadow: inset 0 0 0 2px var(--orange); }
}
@media (max-width: 360px) {
  .brand { font-size: 1.5rem; }
  .masthead nav a { font-size: 0.9375rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* The welcome gift (core/welcome-gift.ts): the signed-out offer under the masthead, and the one-time card. */
.gift-offer { margin: 0; padding: 10px var(--side); background: var(--panel); border-bottom: 1px solid var(--line-ink); font: 600 var(--s-1)/1.4 var(--display); color: #fff; text-align: center; }
.gift-offer a { color: var(--orange-ink); }
.gift-card { position: fixed; inset: auto 0 24px; z-index: 20; width: min(420px, calc(100% - 32px)); box-sizing: border-box; margin: 0 auto; padding: 24px 24px 20px; background: var(--panel); color: #fff; border: 2px dashed var(--orange); border-radius: 14px; text-align: center; }
.gift-card h2 { margin: 0 0 8px; font: 800 var(--s3)/1.05 var(--display); }
.gift-card p { margin: 0 0 16px; color: var(--muted-ink); font-size: var(--s0); }
.gift-card .gift-coins { margin: 0; font: 800 4.5rem/1 var(--display); color: var(--orange-ink); }

/* Invite landing page (/r/:code, rendered by the API) */
.invite .invite-code {
  display: inline-block; margin: 8px 0 24px; padding: 12px 20px; border: 2px solid var(--orange); background: var(--panel);
  font: 800 clamp(2rem, 10vw, 3rem)/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.15em; color: #fff;
  user-select: all; -webkit-user-select: all;
}
.doc .invite-store {
  display: inline-block; padding: 12px 22px; background: var(--orange); color: #000;
  font-weight: 700; text-decoration: none;
}
.doc .invite-store:hover { color: #000; background: var(--orange-ink); }
