/* «Бортовой журнал Кометы» — /live/. Separate zone: rules in docs/live/bible.md. */

@font-face {
  font-family: "Russo One";
  src: url("fonts/russo-one.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Pangolin";
  src: url("fonts/pangolin.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #efe3c8;
  --paper-light: #f8f1df;
  --ink: #1c1a17;
  --orange: #d45a22;
  --teal: #1d5961;
  --teal-light: #cfe1dc;
  --chrome: #b8bfc0;
  --display: "Russo One", "Arial Black", system-ui, sans-serif;
  --hand: "Pangolin", "Comic Sans MS", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(28, 26, 23, 0.07) 1px, transparent 1.2px);
  background-size: 7px 7px;
  font: 17px/1.5 var(--hand);
}

a { color: var(--teal); text-underline-offset: 3px; }
a:hover { color: var(--orange); }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

/* Masthead */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 10px;
  border-bottom: 3px solid var(--ink);
}
.brand { display: flex; align-items: baseline; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-name { font: 28px/1 var(--display); }
.brand-tag { font-size: 16px; white-space: nowrap; }
.masthead-link { font: 16px/1.2 var(--display); color: var(--orange); text-decoration: none; }

.plaque {
  max-width: 1180px;
  margin: 12px auto 0;
  padding: 8px 16px;
  font-size: 16px;
  color: var(--paper-light);
  background: var(--teal);
}

/* Issue header */
.issue, .archive { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.issue-head, .archive-head { margin-bottom: 24px; }
.issue-no {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 12px;
  font: 18px/1.2 var(--display);
  color: var(--paper-light);
  background: var(--ink);
  transform: rotate(-2deg);
}
.issue-title, .archive-head h1 {
  margin: 0;
  font: clamp(40px, 8vw, 88px)/0.95 var(--display);
  color: var(--orange);
  text-shadow: 3px 3px 0 var(--ink);
  letter-spacing: 0.01em;
}
.issue-dates { margin: 12px 0 0; font-size: 18px; }

/* Panels */
/* Page = rows of panels. In a row all panels share one height: each panel's width
   is proportional to its shape ratio (--ratio), like a printed comic page. */
.panels {
  max-width: 1140px;
  margin-inline: auto;
}
.row {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
}
.row .panel {
  flex: var(--ratio) 1 0;
  min-width: 0;
}
.panel { margin: 0; box-shadow: 5px 5px 0 var(--ink); background: var(--paper-light); }
.panel-art img { aspect-ratio: var(--ratio); object-fit: cover; }
.panel-art {
  position: relative;
  container-type: inline-size;
  border: 3px solid var(--ink);
  background: var(--paper-light);
  overflow: hidden;
}
.panel-art img { display: block; width: 100%; height: auto; }

/* Narrator's box. Legacy issues: a strip above/below the art. Comic layout: a box
   inside the art, in the top or bottom left corner, like in print. */
.caption {
  margin: 0;
  padding: 10px 14px;
  font-size: 19px;
  line-height: 1.4;
  background: #f2c14e;
  border: 3px solid var(--ink);
}
.panel-strip .caption-top { border-bottom: 0; }
.panel-strip .caption-bottom { border-top: 0; }
.row-comic .caption {
  position: absolute;
  left: 0;
  max-width: min(64%, 34em);
  padding: 8px 12px;
  font-size: clamp(16px, 1.7cqw, 19px);
  line-height: 1.35;
  border-width: 2.5px;
  z-index: 1;
}
.row-comic .caption-top { top: 0; border-top: 0; border-left: 0; }
.row-comic .caption-bottom { bottom: 0; border-bottom: 0; border-left: 0; }
.row-comic .panel-square .caption,
.row-comic .panel-portrait .caption,
.row-comic .panel-tall .caption { max-width: 100%; right: 0; border-right: 0; }

.previously {
  max-width: 1140px;
  margin: 0 auto 28px;
  padding: 12px 16px;
  font-size: 18px;
  line-height: 1.4;
  background: var(--paper-light);
  border: 3px dashed var(--ink);
}
.previously-label {
  font: 16px/1 var(--display);
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 6px;
}

.balloon {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  margin: 0;
  padding: 0.55em 0.8em;
  font-size: clamp(16px, 1.9cqw, 21px);
  line-height: 1.25;
  text-align: center;
  background: #fffdf6;
  border: 2.5px solid var(--ink);
  border-radius: 999px / 48px; /* soft pill: long v2 lines stay inside */
}
.balloon .who {
  display: block;
  font: 0.75em/1.2 var(--display);
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.balloon::after {
  content: "";
  position: absolute;
  bottom: -16px;
  width: 0;
  height: 0;
  border-top: 18px solid var(--ink);
}
.balloon.tail-left::after { left: var(--tp, 22%); border-right: 14px solid transparent; }
.balloon.tail-right::after { right: var(--tp, 22%); border-left: 14px solid transparent; }
.balloon.tail-none::after { display: none; }
/* Tails that aim at a speaker above or beside the balloon. --tp is the offset along the edge.
   :where() keeps specificity low so the phone layout below can reset them. */
.balloon:where(.tail-up-left, .tail-up-right)::after {
  top: -16px; bottom: auto; border-top: 0; border-bottom: 18px solid var(--ink);
}
.balloon:where(.tail-up-left)::after { left: var(--tp, 22%); border-right: 14px solid transparent; }
.balloon:where(.tail-up-right)::after { right: var(--tp, 22%); border-left: 14px solid transparent; }
.balloon:where(.tail-side-left, .tail-side-right)::after {
  top: var(--tp, 40%); bottom: auto; border-top: 0; border-bottom: 14px solid transparent;
}
.balloon:where(.tail-side-left)::after { left: -16px; border-right: 18px solid var(--ink); }
.balloon:where(.tail-side-right)::after { right: -16px; border-left: 18px solid var(--ink); }

.balloon-radio {
  border-radius: 10px;
  border: 3px double var(--teal);
  background: var(--teal-light);
  box-shadow: 0 0 0 2px var(--ink);
}
.balloon-radio::after { border-top-color: var(--teal); }
.balloon-radio:where(.tail-up-left, .tail-up-right)::after { border-bottom-color: var(--teal); }
.balloon-radio:where(.tail-side-left)::after { border-right-color: var(--teal); }
.balloon-radio:where(.tail-side-right)::after { border-left-color: var(--teal); }

.balloon-sfx {
  padding: 0;
  font: max(26px, 5.5cqw)/1 var(--display);
  color: var(--orange);
  background: none;
  border: 0;
  text-shadow: 2px 2px 0 var(--ink), -1px -1px 0 var(--paper-light);
  transform: rotate(-8deg);
}
.balloon-sfx::after { display: none; }

/* Phones, and panels too narrow for lettering on the art: text moves out of the drawing.
   Captions come before the image in the markup, balloons after it. */
@media (max-width: 600px) {
  .issue-title, .archive-head h1 { text-shadow: 1px 1px 0 var(--ink); line-height: 1.05; }
  .balloon, .row-comic .caption {
    position: static;
    width: auto;
    max-width: none;
    font-size: 17px;
  }
  .row-comic .caption { border: 0; border-bottom: 2.5px solid var(--ink); }
  .balloon { position: relative; left: auto; top: auto; margin: 18px 12px 10px; border-radius: 22px; }
  .balloon::after { top: -16px; bottom: auto; border-top: 0; border-bottom: 18px solid var(--ink); }
  .balloon:where(.tail-up-left, .tail-up-right, .tail-side-left, .tail-side-right)::after {
    left: 22%; right: auto; top: -16px; border-left: 0; border-right: 14px solid transparent;
    border-bottom: 18px solid var(--ink);
  }
  /* Opt-in per-issue mobile attribution; old panels retain their tails. */
  .balloon.has-mobile-tail::after { left: var(--mobile-tp); right: auto; }
  .balloon-radio::after { border-bottom-color: var(--teal); }
  .balloon-radio:where(.tail-side-left, .tail-side-right)::after { border-right-color: transparent; border-left-color: transparent; border-bottom-color: var(--teal); }
  .balloon-sfx { margin: 12px 16px 18px; text-align: left; font-size: 30px; transform: rotate(-4deg); }
}
@container (max-width: 260px) {
  .balloon, .row-comic .caption {
    position: static;
    width: auto;
    max-width: none;
    font-size: 17px;
  }
  .row-comic .caption { border: 0; border-bottom: 2.5px solid var(--ink); }
  .balloon { position: relative; left: auto; top: auto; margin: 18px 12px 10px; border-radius: 22px; }
  .balloon::after { top: -16px; bottom: auto; border-top: 0; border-bottom: 18px solid var(--ink); }
  .balloon:where(.tail-up-left, .tail-up-right, .tail-side-left, .tail-side-right)::after {
    left: 22%; right: auto; top: -16px; border-left: 0; border-right: 14px solid transparent;
    border-bottom: 18px solid var(--ink);
  }
  /* Opt-in per-issue mobile attribution; old panels retain their tails. */
  .balloon.has-mobile-tail::after { left: var(--mobile-tp); right: auto; }
  .balloon-radio::after { border-bottom-color: var(--teal); }
  .balloon-radio:where(.tail-side-left, .tail-side-right)::after { border-right-color: transparent; border-left-color: transparent; border-bottom-color: var(--teal); }
  .balloon-sfx { margin: 12px 16px 18px; text-align: left; font-size: 30px; transform: rotate(-4deg); }
}

/* Facts */
.facts {
  margin-top: 40px;
  padding: 20px 22px;
  background: var(--paper-light);
  border: 3px solid var(--ink);
}
.facts h2 { margin: 0 0 10px; font: 24px/1.2 var(--display); color: var(--teal); }
.facts ul { margin: 0; padding-left: 20px; }
.facts li + li { margin-top: 6px; }

.issue-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 32px;
  font: 16px/1.3 var(--display);
}
.nav-next { text-align: right; }
.nav-next:is(span) { font: 16px/1.3 var(--hand); color: #5b574f; }

/* Archive */
.archive-lead { max-width: 720px; font-size: 20px; margin: 16px 0; }
.lead-link { font: 20px/1.3 var(--display); color: var(--orange); }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px;
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
}
.card a {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: var(--ink);
  text-decoration: none;
  background: var(--paper-light);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
}
.card a:hover { box-shadow: 6px 6px 0 var(--orange); }
.card img { display: block; width: 100%; height: auto; aspect-ratio: 2; object-fit: cover; border-bottom: 3px solid var(--ink); }
.card-no { margin: 12px 14px 0; font: 16px/1.2 var(--display); color: var(--teal); }
.card-title { margin: 2px 14px 0; font: 26px/1.1 var(--display); color: var(--orange); }
.card-dates { margin: 6px 14px 0; font-size: 16px; }
.card-teaser { margin: 8px 14px 14px; }

/* Footer and cookie notice */
.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 16px 90px;
  border-top: 3px solid var(--ink);
  font-size: 16px;
}
.footer p { margin: 4px 0; }

.cookie {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 10px 16px;
  font-size: 16px;
  color: var(--paper-light);
  background: var(--ink);
}
.cookie[hidden] { display: none; }
.cookie p { margin: 0; max-width: 760px; }
.cookie button {
  font: 16px/1 var(--display);
  padding: 9px 16px;
  color: var(--ink);
  background: #f2c14e;
  border: 0;
  cursor: pointer;
}

@media (max-width: 760px) {
  body { font-size: 16px; }
  .row { flex-direction: column; gap: 20px; margin-bottom: 20px; }
  .caption, .previously { font-size: 17px; }
  .issue-nav { grid-template-columns: 1fr; text-align: center; }
  .nav-next { text-align: center; }
  .brand-name { font-size: 24px; }
}

@media (prefers-reduced-motion: no-preference) {
  .card a { transition: box-shadow 0.15s; }
}

/* Archive-only readable links: keep the comic palette and issue pages intact. */
body:has(> .archive) .masthead-link,
.archive .lead-link { color: var(--teal); }
body:has(> .archive) .masthead-link:hover,
.archive .lead-link:hover { text-decoration: underline; }
body:has(> .archive) .masthead-link:focus-visible,
.archive .lead-link:focus-visible { outline-color: var(--teal); }

/* Opt-in adaptive lettering: existing issues keep their original layout. */
.issue-adaptive .panel-art img.adaptive-original { display:none; }
@media (max-width:600px) {
 .issue-adaptive .panel-art img.adaptive-padded { display:none; }
 .issue-adaptive .panel-art img.adaptive-original { display:block; }
}
@container (max-width:600px) {

  .issue-adaptive .balloon, .issue-adaptive .row-comic .caption {
    position: static;
    width: auto;
    max-width: none;
    font-size: 17px;
  }
  .issue-adaptive .row-comic .caption { border: 0; border-bottom: 2.5px solid var(--ink); }
  .issue-adaptive .balloon { position: relative; left: auto; top: auto; margin: 18px 12px 10px; border-radius: 22px; }
  .issue-adaptive .balloon::after { top: -16px; bottom: auto; border-top: 0; border-bottom: 18px solid var(--ink); }
  .issue-adaptive .balloon:where(.tail-up-left, .tail-up-right, .tail-side-left, .tail-side-right)::after {
    left: 22%; right: auto; top: -16px; border-left: 0; border-right: 14px solid transparent;
    border-bottom: 18px solid var(--ink);
  }
  /* Opt-in per-issue mobile attribution; old panels retain their tails. */
  .issue-adaptive .balloon.has-mobile-tail::after { left: var(--mobile-tp); right: auto; }
  .issue-adaptive .balloon-radio::after { border-bottom-color: var(--teal); }
  .issue-adaptive .balloon-radio:where(.tail-side-left, .tail-side-right)::after { border-right-color: transparent; border-left-color: transparent; border-bottom-color: var(--teal); }
  .issue-adaptive .balloon-sfx { margin: 12px 16px 18px; text-align: left; font-size: 30px; transform: rotate(-4deg); }

 .issue-adaptive .panel-art img.adaptive-padded { display:none; }
 .issue-adaptive .panel-art img.adaptive-original { display:block; }
}

/* Issue 14: speaker labels also meet the 16px floor. */
.issue-adaptive .balloon .who {font-size:16px;}
