/* Where's Rocko? — Rocko Comic Reader.
   Loaded by /comic/ on TOP of the shared /styles.css design tokens — same
   pattern as /spot/spot.css and /reveal/reveal.css. Uses the warm "Creative
   Library" system (paper / surface / ink / brand #F04E37), NOT the festive hub
   palette. Category is COMICS, so accents use a toned-down comics hue that reads
   well on warm paper (the hub's brighter #A970FF is only for body.home). */
:root {
  --c-comics: #8A54D6;   /* comics accent, muted for paper backgrounds */
  --bubble-tail: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --c-comics: #B98CE8; }
}

body.comic main { max-width: 900px; margin: 0 auto; padding: 0 20px 64px; }

/* ============ library / story select ============ */
.comic-hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 30px; flex-wrap: wrap;
  margin: 26px 0 22px; padding: 34px 36px; border-radius: 26px;
  background: radial-gradient(120% 150% at 100% 0%,
    color-mix(in srgb, var(--c-comics) 20%, var(--surface)) 0%, var(--surface) 60%);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.comic-hero-art {
  flex: 0 0 auto; width: 116px; height: 116px;
  filter: drop-shadow(0 10px 20px rgba(30,22,14,.18));
}
.comic-hero-copy { flex: 1 1 300px; min-width: 0; }
.comic-eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: #fff; background: var(--c-comics); padding: 4px 11px; border-radius: 999px; margin: 0 0 12px;
}
.comic-hero h1 { font-size: clamp(1.9rem, 4.8vw, 3rem); margin: 0 0 .26em; }
.comic-hero h1 .accent { color: var(--brand); }
.comic-hero .lede { font-size: 1.06rem; font-weight: 700; color: var(--ink-soft); margin: 0; max-width: 54ch; }
.comic-hero .lede strong { color: var(--ink); }

/* reading-level filter */
.tier-filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.tier-btn {
  font: inherit; font-family: var(--font-display); font-weight: 600; font-size: .94rem;
  cursor: pointer; padding: 8px 16px; border-radius: 999px;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--ink);
  transition: border-color .12s ease, color .12s ease, background .12s ease, transform .08s ease;
}
.tier-btn:hover { border-color: var(--c-comics); color: var(--c-comics); transform: translateY(-1px); }
.tier-btn.is-on { background: var(--c-comics); border-color: var(--c-comics); color: #fff; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.story-card {
  display: flex; flex-direction: column; text-align: left; overflow: hidden; position: relative;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: inherit; cursor: pointer; font: inherit;
  transition: transform .12s ease, box-shadow .12s ease;
}
.story-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.story-card:focus-visible { outline: 3px solid var(--c-comics); outline-offset: 2px; }
.story-thumb {
  position: relative; display: grid; place-items: center;
  height: 150px; background: var(--surface-2); overflow: hidden;
}
.story-thumb .scene { width: 100%; height: 100%; display: block; }
.thumb-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 72%; z-index: 1; }
.story-thumb .thumb-fade {   /* soft comic-strip frame over the cover */
  position: absolute; inset: 0; pointer-events: none; z-index: 2;
  box-shadow: inset 0 0 0 4px color-mix(in srgb, var(--c-comics) 22%, transparent);
  border-radius: 0;
}
.tier-chip {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  font-family: var(--font-display); font-weight: 700; font-size: .72rem;
  color: #fff; background: color-mix(in srgb, var(--c-comics) 88%, #000 4%);
  padding: 3px 10px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.done-flag {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  font-weight: 800; font-size: .72rem; color: #fff; background: #35b06a;
  padding: 3px 9px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.story-meta { padding: 13px 16px 6px; display: flex; flex-direction: column; gap: 2px; }
.story-name { font-family: var(--font-display); font-weight: 700; font-size: 1.12rem; }
.story-tag { color: var(--ink-soft); font-size: .88rem; font-weight: 700; }
.story-cta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 16px 16px; margin-top: auto;
}
.story-go {
  display: inline-flex; align-items: center; gap: .4em;
  font-family: var(--font-display); font-weight: 600; font-size: .96rem;
  color: #fff; background: var(--brand); padding: 8px 16px; border-radius: 999px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--brand) 40%, transparent);
}
.story-card:hover .story-go { transform: translateY(-1px); }
.story-panels { font-size: .78rem; font-weight: 800; color: var(--ink-soft); }

.comic-fine { margin-top: 24px; }

/* ============ HUD ============ */
.hud { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 20px 0 12px; }
.hud-back {
  font: inherit; font-weight: 800; cursor: pointer; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 999px; padding: 8px 15px;
}
.hud-back:hover { border-color: var(--brand); color: var(--brand-ink); }
.hud-scene { font-family: var(--font-display); font-weight: 700; font-size: 1.16rem; }
.hud-count {
  display: inline-flex; align-items: baseline; gap: 4px; padding: 5px 13px; border-radius: 999px;
  background: color-mix(in srgb, var(--c-comics) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c-comics) 40%, var(--line));
  font-weight: 800; color: color-mix(in srgb, var(--c-comics) 70%, var(--ink));
}
.hud-count b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.hud-spacer { flex: 1 1 auto; }
.read-toggle {
  display: inline-flex; align-items: center; gap: 7px; font: inherit; font-weight: 800; cursor: pointer;
  color: var(--ink); background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 8px 15px; transition: border-color .12s, color .12s, background .12s;
}
.read-toggle .rt-ico { filter: grayscale(1) opacity(.6); }
.read-toggle:hover { border-color: var(--c-comics); color: var(--c-comics); }
.read-toggle[aria-pressed="true"] {
  background: var(--c-comics); border-color: var(--c-comics); color: #fff;
}
.read-toggle[aria-pressed="true"] .rt-ico { filter: none; }

/* ============ stage ============ */
.stage-wrap {
  position: relative; width: 100%; margin: 0 auto;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
}
.panel-stage {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 66vh;
  margin: 0 auto; overflow: hidden; border-radius: var(--radius);
  border: 3px solid var(--ink); background: var(--surface);
  box-shadow: var(--shadow-lift);
}
/* background layer: WebP if the pipeline drops one, else the hand-built SVG scene */
.panel-bg { position: absolute; inset: 0; }
.panel-bg-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.panel-bg .scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.panel-stage.turning .panel-bg { animation: panelIn .34s ease both; }
@keyframes panelIn { from { opacity: 0; transform: scale(1.03); } to { opacity: 1; transform: none; } }

/* ---- speech + caption bubbles (hand-built DOM, revealed one at a time) ---- */
.bubble-layer { position: absolute; inset: 0; }
.bubble {
  position: absolute; transform: translate(-50%, -50%) scale(.5);
  max-width: 62%; opacity: 0; pointer-events: none;
  font-family: var(--font-display); font-weight: 600; line-height: 1.18;
  transition: opacity .28s ease, transform .32s cubic-bezier(.3,1.5,.5,1);
}
.bubble.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* karaoke word highlight while "Read to me" speaks each word */
.bubble .cw { border-radius: 5px; box-decoration-break: clone; -webkit-box-decoration-break: clone;
  transition: background-color .1s ease, box-shadow .1s ease, color .1s ease; }
.bubble.speech .cw.reading { background: #FFD84D; box-shadow: 0 0 0 2px #FFD84D; }
.bubble.caption .cw.reading { background: #F0A227; color: #3a2408; box-shadow: 0 0 0 2px #F0A227; }

.bubble.speech {
  background: #fff; color: #17171c;
  border: 2.5px solid var(--ink); border-radius: 16px;
  padding: 10px 14px; font-size: clamp(.95rem, 2.6vw, 1.2rem);
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.bubble.speech .who {
  display: block; font-size: .62em; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; color: var(--c-comics); margin-bottom: 1px;
}
/* the pointer tail — direction set by a modifier class */
.bubble.speech::after {
  content: ""; position: absolute; width: 0; height: 0;
  border: var(--bubble-tail) solid transparent;
}
.bubble.tail-b::after { bottom: calc(var(--bubble-tail) * -2 + 3px); left: 26px; border-top-color: var(--ink); }
.bubble.tail-b::before {
  content: ""; position: absolute; bottom: calc(var(--bubble-tail) * -2 + 7px); left: 29px;
  width: 0; height: 0; border: calc(var(--bubble-tail) - 3px) solid transparent; border-top-color: #fff; z-index: 1;
}
.bubble.tail-br::after { bottom: calc(var(--bubble-tail) * -2 + 3px); right: 26px; border-top-color: var(--ink); }
.bubble.tail-br::before {
  content: ""; position: absolute; bottom: calc(var(--bubble-tail) * -2 + 7px); right: 29px;
  width: 0; height: 0; border: calc(var(--bubble-tail) - 3px) solid transparent; border-top-color: #fff; z-index: 1;
}
.bubble.tail-tl::after { top: calc(var(--bubble-tail) * -2 + 3px); left: 26px; border-bottom-color: var(--ink); }
.bubble.tail-tl::before {
  content: ""; position: absolute; top: calc(var(--bubble-tail) * -2 + 7px); left: 29px;
  width: 0; height: 0; border: calc(var(--bubble-tail) - 3px) solid transparent; border-bottom-color: #fff; z-index: 1;
}

/* narrator caption — a comic-strip yellow box pinned along the bottom */
.bubble.caption {
  left: 50%; bottom: 12px; top: auto; transform: translate(-50%, 12px) scale(.9);
  max-width: 86%; text-align: center;
  background: #FFF3C4; color: #4a3a10; border: 2.5px solid var(--ink);
  border-radius: 12px; padding: 8px 16px; font-family: var(--font-body); font-weight: 800;
  font-size: clamp(.9rem, 2.4vw, 1.08rem); box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.bubble.caption.show { transform: translate(-50%, 0) scale(1); }
@media (prefers-color-scheme: dark) {
  .bubble.caption { background: #F6E4A0; }   /* keep captions bright & readable */
}

/* tap-to-continue hint (fades once you've started) */
.tap-hint {
  position: absolute; bottom: 12px; right: 12px; z-index: 4;
  display: inline-flex; align-items: center; gap: 6px; font: inherit;
  font-family: var(--font-display); font-weight: 700; font-size: .84rem;
  color: #fff; background: color-mix(in srgb, var(--c-comics) 92%, #000);
  border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.28); animation: hintBob 1.6s ease-in-out infinite;
}
.tap-hint .arw { font-size: .8em; }
.tap-hint[hidden] { display: none; }
@keyframes hintBob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ============ reader bar ============ */
.reader-bar { display: flex; align-items: center; gap: 12px; margin: 14px auto 0; }
.rbtn {
  font: inherit; font-family: var(--font-display); font-weight: 600; font-size: 1rem; cursor: pointer;
  color: var(--ink); background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 10px 20px; display: inline-flex; align-items: center; gap: .4em;
  transition: border-color .12s, color .12s, transform .08s, box-shadow .12s;
}
.rbtn:hover:not(:disabled) { border-color: var(--c-comics); color: var(--c-comics); transform: translateY(-1px); }
.rbtn:disabled { opacity: .45; cursor: default; }
.rbtn.primary {
  color: #fff; background: var(--brand); border-color: var(--brand);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 40%, transparent);
}
.rbtn.primary:hover:not(:disabled) { color: #fff; transform: translateY(-2px); box-shadow: 0 8px 22px color-mix(in srgb, var(--brand) 46%, transparent); }
.pips { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; gap: 7px; flex-wrap: wrap; }
.pip { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: background .2s, transform .2s; }
.pip.done { background: color-mix(in srgb, var(--c-comics) 55%, var(--line)); }
.pip.on { background: var(--c-comics); transform: scale(1.35); }

/* ============ The End modal (reused .win pattern) ============ */
.win { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: rgba(10,12,20,.5); backdrop-filter: blur(3px); padding: 20px; }
.win[hidden] { display: none; }   /* class display must not beat the hidden attr */
.win-card {
  background: var(--surface); color: var(--ink); border-radius: 22px; padding: 30px 30px 26px;
  text-align: center; max-width: 400px; width: 100%; box-shadow: 0 24px 70px rgba(0,0,0,.4);
  animation: winPop .35s ease both;
}
@keyframes winPop { 0% { transform: scale(.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.win-rocko { width: 116px; height: 116px; animation: rockoWag 1s ease-in-out infinite alternate; }
@keyframes rockoWag { from { transform: rotate(-5deg); } to { transform: rotate(5deg); } }
.win-card h2 { font-size: 1.9rem; margin: 6px 0 4px; }
.win-time { font-size: 1.05rem; color: var(--ink-soft); font-weight: 700; margin: 0 0 2px; }
.win-time strong { color: var(--ink); }
.win-best { font-weight: 800; color: var(--brand-ink); margin: 4px 0 18px; min-height: 1.2em; }
.win-actions { display: flex; flex-direction: column; gap: 10px; }
.win-actions .btn { justify-content: center; border-radius: 14px; }

@media (max-width: 480px) {
  .comic-hero { padding: 26px 22px; }
  .reader-bar { gap: 8px; }
  .rbtn { padding: 10px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
