:root {
  --paper: #f3efe6;
  --card: #fbf9f4;
  --ink: #1d1c1a;
  --ink-soft: #5b5850;
  --wash: #c9cfd4;
  --rule: #1d1c1a;
  --accent: #a9502b;
  --shadow: 0 1px 0 rgba(0,0,0,.08), 0 8px 24px -12px rgba(30,25,15,.35);
  --backdrop: rgba(24, 22, 18, .82);
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #171716;
    --card: #22211f;
    --ink: #ece7dc;
    --ink-soft: #a8a294;
    --wash: #3a3d40;
    --rule: #ece7dc;
    --accent: #e08a5f;
    --shadow: 0 1px 0 rgba(255,255,255,.04), 0 10px 28px -14px rgba(0,0,0,.8);
    --backdrop: rgba(5, 5, 5, .9);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #171716; --card: #22211f; --ink: #ece7dc; --ink-soft: #a8a294;
  --wash: #3a3d40; --rule: #ece7dc; --accent: #e08a5f;
  --shadow: 0 1px 0 rgba(255,255,255,.04), 0 10px 28px -14px rgba(0,0,0,.8);
  --backdrop: rgba(5, 5, 5, .9); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--body);
}
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }

/* Masthead: the brand box mimics the label on every panel */
.masthead {
  max-width: 1180px;
  margin: 0 auto;
  padding: 48px 16px 8px;
  text-align: center;
}
.brand {
  display: inline-block;
  text-decoration: none;
  transform: rotate(-1.6deg);
}
.brand span {
  display: inline-block;
  font: 400 clamp(40px, 8vw, 72px)/1 var(--hand);
  padding: 10px 22px 6px;
  background: var(--card);
  border: 3px solid var(--rule);
  box-shadow: 5px 5px 0 var(--rule);
}
.tagline {
  max-width: 34em;
  margin: 26px auto 4px;
  font-size: 1.1rem;
}
.byline {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--hand);
  font-size: 1.15rem;
}

/* Signup */
.signup {
  max-width: 640px;
  margin: 24px auto 8px;
  padding: 0 16px;
}
.signup form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.signup label {
  width: 100%;
  text-align: center;
  font-family: var(--hand);
  font-size: 1.25rem;
}
.signup input[type="email"] {
  flex: 1 1 220px;
  min-width: 0;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--rule);
  border-radius: 0;
}
.signup button {
  padding: 12px 20px;
  font: 700 1rem var(--body);
  color: var(--paper);
  background: var(--ink);
  border: 2px solid var(--rule);
  cursor: pointer;
}
.signup button:hover { background: var(--accent); border-color: var(--accent); }
.signup .small { width: 100%; text-align: center; margin: 2px 0 0; font-size: .85rem; color: var(--ink-soft); }

/* Grid */
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; }
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 32px 28px;
}
.card a {
  display: block;
  text-decoration: none;
  background: var(--card);
  border: 2px solid var(--rule);
  padding: 10px 10px 4px;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease;
}
.card:nth-child(3n+1) a { transform: rotate(-.6deg); }
.card:nth-child(3n+2) a { transform: rotate(.5deg); }
.card a:hover, .card a:focus-visible {
  transform: rotate(0) translateY(-4px);
  box-shadow: 6px 6px 0 var(--rule);
  outline: none;
}
.card img { aspect-ratio: 1; object-fit: cover; width: 100%; background: var(--wash); }
.card p {
  margin: 8px 2px 6px;
  font: 1.2rem/1.25 var(--hand);
}
.card .num { color: var(--accent); margin-right: 6px; }
.card .new {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font: 700 .7rem/1.6 var(--body);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--accent);
  vertical-align: 3px;
}

.foot {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  text-align: center;
  color: var(--ink-soft);
  font-size: .9rem;
  border-top: 2px solid var(--rule);
}

/* Viewer */
.viewer {
  width: min(100vw, 980px);
  max-width: 100vw;
  max-height: 100dvh;
  padding: 0;
  margin: auto;
  border: 0;
  background: transparent;
  color: #f3efe6;
  overflow: auto;
}
.viewer::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.viewer:not([open]) { display: none; }
.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}
.viewer-num { font: 1.3rem var(--hand); }
.viewer-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  font: 700 .85rem var(--body);
  color: #f3efe6;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.25);
  text-decoration: none;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.22); }
.icon-btn.close { font-size: 1.1rem; width: 36px; justify-content: center; padding: 0; }
.viewer-fig { position: relative; margin: 0; padding: 0 12px; }
.viewer-fig img {
  width: auto;
  max-width: 100%;
  max-height: calc(100dvh - 150px);
  margin: 0 auto;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,.7);
}
.viewer-fig figcaption { text-align: center; padding: 12px 8px 0; }
.v-caption { display: inline; margin: 0; font: 1.25rem/1.25 var(--hand); }
.v-caption::after { content: " · "; opacity: .5; }
.v-meta { display: inline; margin: 0; font-size: .85rem; opacity: .7; }
.nav {
  position: absolute;
  top: calc(50% - 60px);
  width: 46px;
  height: 64px;
  font: 2.4rem/1 var(--body);
  color: #fff;
  background: rgba(0,0,0,.45);
  border: 0;
  cursor: pointer;
}
.nav:hover { background: rgba(0,0,0,.7); }
.nav[disabled] { visibility: hidden; }
.nav.prev { left: 12px; }
.nav.next { right: 12px; }
.viewer .signup { margin: 18px auto 20px; }
.viewer .signup label, .viewer .signup .small { color: #f3efe6; }
.viewer .signup input[type="email"] { background: #fbf9f4; color: #1d1c1a; border-color: #fbf9f4; }
.viewer .signup button { background: #a9502b; border-color: #a9502b; color: #fff; }

/* Without JS (or before it loads) a cartoon page shows the viewer inline */
.viewer[open]:not(:modal) {
  position: static;
  background: #1d1c1a;
  margin: 24px auto;
}

@media (max-width: 600px) {
  .viewer-fig img { max-height: calc(100dvh - 130px); }
  .masthead { padding-top: 32px; }
  .nav { display: none; }
  .viewer-fig figcaption::after { content: "Swipe for more"; display: block; margin-top: 4px; font-size: .75rem; opacity: .55; }
  .icon-btn { padding: 0 9px; font-size: .78rem; }
  .viewer-fig { padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .card a { transition: none; }
}
