/* Shared comic/manga page styles for / and /app. The page is printed paper: it stays light in dark mode. */

.manga-root {
  --comic-ink: #111111;
  --comic-paper: #fbf8f1;
  --lettering: "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Marker Felt", system-ui, sans-serif;
  --sfx-font: Impact, "Arial Black", "Helvetica Neue", sans-serif;
}

/* ---------------- manga ---------------- */

.manga-root { display: flex; flex-direction: column; gap: 10px; }
.manga-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 10px; }
.manga-title { margin: 0; font-family: var(--sfx-font); font-weight: 400; letter-spacing: 0.02em; font-size: clamp(1.4rem, 3vw, 2.1rem); text-transform: uppercase; line-height: 1.05; }
.manga-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; font-family: var(--mono); }
.manga-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.manga-root .segmented { display: inline-flex; border: 2px solid var(--ink); }
.manga-root .segmented button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; font-weight: 700; font-family: var(--mono); }
.manga-root .segmented button + button { border-left: 2px solid var(--ink); }
.manga-root .segmented button.is-on { background: var(--ink); color: var(--paper); }

.manga-page {
  background: var(--comic-paper);
  color: var(--comic-ink);
  border: 3px solid var(--comic-ink);
  padding: 14px;
  box-shadow: 8px 8px 0 var(--comic-ink);
  background-image: radial-gradient(rgba(17, 17, 17, 0.06) 1px, transparent 1.2px);
  background-size: 6px 6px;
}

.manga-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: minmax(210px, auto);
  gap: 12px;
}

.span-c1 { grid-column: span 1; }
.span-c2 { grid-column: span 2; }
.span-c3 { grid-column: span 3; }
.span-c4 { grid-column: span 4; }
.span-c5 { grid-column: span 5; }
.span-c6 { grid-column: span 6; }
.span-r1 { grid-row: span 1; }
.span-r2 { grid-row: span 2; }
.span-r3 { grid-row: span 3; }

.manga-panel {
  position: relative;
  margin: 0;
  border: 3px solid var(--comic-ink);
  background: var(--comic-paper);
  overflow: hidden;
  min-height: 210px;
  animation: panel-in 0.4s ease both;
}
.manga-panel:nth-child(2) { animation-delay: 0.06s; }
.manga-panel:nth-child(3) { animation-delay: 0.12s; }
.manga-panel:nth-child(4) { animation-delay: 0.18s; }
.manga-panel:nth-child(5) { animation-delay: 0.24s; }
.manga-panel:nth-child(6) { animation-delay: 0.3s; }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.panel-art-wrap { position: absolute; inset: 0; }
.panel-art-wrap svg { width: 100%; height: 100%; display: block; }

.panel-overlay {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  height: 100%;
  font-family: var(--lettering);
  color: var(--comic-ink);
}

.caption {
  margin: 0;
  align-self: flex-start;
  max-width: 82%;
  background: #fffbe6;
  border: 2px solid var(--comic-ink);
  padding: 4px 9px;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.3;
  box-shadow: 3px 3px 0 var(--comic-ink);
}
.is-rtl .caption { align-self: flex-end; }

.bubbles { display: flex; flex-direction: column; gap: 10px; max-height: 68%; }
.bubbles-top .bubbles { flex-direction: row; justify-content: space-between; align-items: flex-start; }
.bubbles-right .bubbles { align-items: flex-end; }
.bubbles-right .bubble { max-width: 42%; }

.bubble {
  position: relative;
  margin: 0 0 12px;
  max-width: 64%;
  background: #ffffff;
  border: 2.5px solid var(--comic-ink);
  border-radius: 1.4em;
  padding: 6px 14px 7px;
  font-size: 0.84rem;
  line-height: 1.28;
  text-align: center;
  display: flex;
  flex-direction: column;
}
.bubble.side-left { align-self: flex-start; }
.bubble.side-right { align-self: flex-end; }

.bubble::after,
.bubble::before {
  content: "";
  position: absolute;
  bottom: -14px;
  width: 0;
  height: 0;
  border-style: solid;
}
.bubble.side-left::before { left: 26px; border-width: 15px 4px 0 14px; border-color: var(--comic-ink) transparent transparent transparent; }
.bubble.side-left::after { left: 29px; bottom: -9px; border-width: 10px 2px 0 9px; border-color: #ffffff transparent transparent transparent; }
.bubble.side-right::before { right: 26px; border-width: 15px 14px 0 4px; border-color: var(--comic-ink) transparent transparent transparent; }
.bubble.side-right::after { right: 29px; bottom: -9px; border-width: 10px 9px 0 2px; border-color: #ffffff transparent transparent transparent; }

.bubble-shout { border-width: 3.5px; border-radius: 6px; font-weight: 800; letter-spacing: 0.01em; transform: rotate(-1.2deg); box-shadow: 3px 3px 0 var(--comic-ink); }
.bubble-whisper { border-style: dashed; font-style: italic; }
.bubble-thought { border-style: dotted; border-width: 3px; border-radius: 50%; padding: 10px 18px; }
.bubble-thought::before, .bubble-thought::after { border: 2.5px solid var(--comic-ink); border-radius: 50%; background: #fff; }
.bubble-thought.side-left::before, .bubble-thought.side-right::before { width: 12px; height: 12px; bottom: -16px; border-color: var(--comic-ink); }
.bubble-thought.side-left::after, .bubble-thought.side-right::after { width: 7px; height: 7px; bottom: -26px; border-color: var(--comic-ink); }
.bubble-thought.side-left::after { left: 18px; }
.bubble-thought.side-right::after { right: 18px; }

.speaker { font-family: var(--sans); font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: #6b6458; font-weight: 700; }

.sfx {
  position: absolute;
  z-index: 2;
  font-family: var(--sfx-font);
  font-size: clamp(1.5rem, 3.2vw, 2.7rem);
  line-height: 1;
  color: #e4362b;
  -webkit-text-stroke: 1.5px var(--comic-ink);
  text-shadow: 3px 3px 0 var(--comic-ink);
  letter-spacing: 0.02em;
  white-space: nowrap;
  transform: rotate(-10deg);
  pointer-events: none;
  animation: sfx-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both 0.3s;
}
.sfx-bottom-left .sfx { left: 12px; bottom: 18px; }
.sfx-bottom-middle .sfx { left: 50%; bottom: 14px; transform: translateX(-50%) rotate(-8deg); }
.sfx-middle .sfx { left: 50%; top: 46%; transform: translate(-50%, -50%) rotate(-10deg); }
.sfx-top-left .sfx { left: 12px; top: 40%; }
.scene-cliffhanger .sfx, .scene-code-terminal .sfx { color: #ffffff; text-shadow: 3px 3px 0 #e4362b; }

@keyframes sfx-pop {
  from { opacity: 0; scale: 0.4; }
  to { opacity: 1; scale: 1; }
}

.panel-no {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 2;
  background: var(--comic-ink);
  color: #fff;
  font-family: var(--sans);
  font-weight: 800;
  font-size: 0.7rem;
  min-width: 20px;
  text-align: center;
  padding: 1px 5px;
}

.tone-noir .manga-page { filter: grayscale(1) contrast(1.15); }
.tone-shojo .manga-panel { border-radius: 10px; }
.tone-seinen .sfx { color: var(--comic-ink); -webkit-text-stroke: 0; text-shadow: 2px 2px 0 #fff; }

.comic-script summary { cursor: pointer; font-weight: 700; }


@media (max-width: 700px) {
  .manga-grid { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(240px, auto); }
  .span-c1, .span-c2, .span-c3, .span-c4, .span-c5, .span-c6 { grid-column: span 1; }
  .span-r2, .span-r3 { grid-row: span 1; }
  .scene-hero-splash { min-height: 300px; }
  .scene-diagram-action { min-height: 380px; }
  .bubble { max-width: 80%; }
  .bubbles-right .bubble { max-width: 60%; }
  .manga-page { padding: 8px; box-shadow: 4px 4px 0 var(--comic-ink); }
}

@media (prefers-reduced-motion: reduce) {
  .manga-panel, .sfx { animation: none; }
}

@media (prefers-color-scheme: dark) {
  .manga-root .segmented button.is-on { color: #1c1a17; }
  .manga-page { box-shadow: 8px 8px 0 #000, 0 0 0 1px #4a443a; }
}
