/* ================================================================== v5 — polish layer (loaded last) */

/* ---------- words never break mid-word anywhere: wrap only between words ---------- */
.plate, .v2-ore figcaption, .v2-slot b, .dcard .nm, .v2-tag, .v4-toast, .v2-hint {
  word-break: normal; overflow-wrap: normal; hyphens: none; -webkit-hyphens: none;
}

/* ---------- home 05 forge: equal vertical cards, icon over label ---------- */
.ch-forge .v2-ores { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 10px; align-items: stretch; }
.ch-forge .v2-ore {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 8px; padding: 12px 8px 10px; min-width: 0; height: 100%; box-sizing: border-box;
  text-align: center; border-radius: 0;
  box-shadow: inset 0 0 0 1px rgba(238, 230, 208, .1), 0 3px 0 rgba(0, 0, 0, .55);
}
.ch-forge .v2-ore img { width: 56px; height: 56px; flex: none; image-rendering: pixelated; }
.ch-forge .v2-ore figcaption {
  display: flex; align-items: center; justify-content: center;
  min-height: 2.1em; width: 100%; min-width: 0;
  font: clamp(15px, 1.25vw, 19px) / 1.05 var(--term); letter-spacing: .02em;
  white-space: normal; overflow: visible; text-overflow: clip; text-wrap: balance;
  word-break: normal; overflow-wrap: normal; hyphens: none;
}
.ch-forge .v2-ore.out figcaption { color: #f6dc7a; }
@media (max-width: 1200px) {
  .ch-forge .v2-ore { padding: 10px 6px 8px; gap: 6px; }
  .ch-forge .v2-ore img { width: 46px; height: 46px; }
  .ch-forge .v2-ore figcaption { font-size: 16px; }
}
/* phones: labels come back, small, under the icon */
@media (max-width: 700px) {
  .ch-forge .v2-ores { gap: 6px; }
  .ch-forge .v2-ore { padding: 7px 3px 6px; gap: 4px; justify-content: flex-start; }
  .ch-forge .v2-ore img { width: 36px; height: 36px; }
  .ch-forge .v2-ore figcaption { display: flex; font-size: 13px; line-height: 1; min-height: 2em; letter-spacing: 0; }
}
@media (max-width: 380px) {
  .ch-forge .v2-ore figcaption { font-size: 12px; }
  .ch-forge .v2-ore img { width: 32px; height: 32px; }
}

/* ---------- chapter rail: the hidden labels no longer sit (invisibly) on top of chapter copy ---------- */
.v2-rail-nav a { position: relative; }
.v2-rail-nav a span { position: absolute; left: 100%; top: 50%; margin-top: -.6em; white-space: nowrap; pointer-events: none; }
/* tablets + phones: in-row, crucible, out-row stacked; four equal cards per row */
@media (max-width: 900px) {
  .ch-forge .v2-anvil { grid-template-columns: minmax(0, 1fr) !important; justify-items: stretch; gap: 10px; }
  .ch-forge .v2-ores { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .ch-forge .v2-crucible { justify-self: center; width: 46px; }
}

/* forge entrance: the out-row settles fully by mid-chapter (the late stagger read as a misaligned last card) */
.ch-forge .v2-ore { --k: clamp(0, calc(var(--p, 0) * 10 - var(--i) * .4), 1); opacity: var(--k); transform: translateY(calc((1 - var(--k)) * 14px)); }
.ch-forge .v2-ore.out { --k: clamp(0, calc((var(--p, 0) - .38) * 12 - var(--i) * .35), 1); }
@media (max-width: 700px) { .ch-forge .v2-ore, .ch-forge .v2-ore.out { --k: 1; } }
@media (prefers-reduced-motion: reduce) { .ch-forge .v2-ore, .ch-forge .v2-ore.out { --k: 1; } }

/* ---------- home hero: the smash hint sits above the dock instead of under it ---------- */
@media (min-width: 701px) { html[data-route='home'] .v2-hint { bottom: 112px; } }
/* marquee: soft yellow edges so words slide in and out instead of being sliced at the screen edge */
.v2-marquee::before, .v2-marquee::after { content: ''; position: absolute; z-index: 2; top: 0; bottom: 0; width: clamp(28px, 5vw, 72px); pointer-events: none; }
.v2-marquee::before { left: 0; background: linear-gradient(90deg, var(--yellow) 15%, rgba(232, 196, 72, 0)); }
.v2-marquee::after { right: 0; background: linear-gradient(270deg, var(--yellow) 15%, rgba(232, 196, 72, 0)); }

/* ---------------------------------------------------------------- v5: sealed jars, no backdrops
   art/v5/jar/*.gif are the original sealed-jar sprites with the scene background cut away
   (same pixels, transparent surround). Frames and glows that used to box the old square
   sprites become outline-following drop shadows so nothing draws a square around the jar. */
.v2-cell img { box-shadow: none; background: radial-gradient(ellipse 62% 58% at 50% 58%, rgba(110, 240, 150, .2), rgba(4, 10, 8, .92) 72%); filter: saturate(1.05) drop-shadow(0 calc(3 * var(--u)) 0 rgba(0, 0, 0, .55)); }
.v2-glass img { box-shadow: none; filter: drop-shadow(0 0 calc(3 * var(--u)) rgba(0, 0, 0, .8)) drop-shadow(0 0 calc(26 * var(--u)) rgba(255, 210, 63, .45)); }
.bn-jar img { border: 0; box-shadow: none; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .7)); }
.bn-ch { background: radial-gradient(ellipse 60% 60% at 50% 55%, rgba(110, 240, 150, .32), rgba(4, 18, 12, .95) 75%); }
.bn-ch img { object-fit: contain; padding: 6%; }
.v4-fj img { filter: drop-shadow(0 .4cqw 0 rgba(0, 0, 0, .65)); }
/* control-room tanks: the jar floats mid-liquid instead of resting on the floor */
.v4-mon { left: 17%; width: 66%; bottom: 17%; filter: drop-shadow(0 0 .8cqw rgba(var(--lq), .45)); }
.bn-item img { border: 0; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .6)); }

/* ---------------------------------------------------------------- v5: the lab dock stays out of the way
   - it steps aside while a drawer, dialog or jar takeover is open (those have their own close controls)
   - on phones it folds to the single "more" button; the sound and light toggles slide out when it opens */
.v4-dock { transition: opacity .2s ease, transform .2s ease; }
body:has(#layer > *) .v4-dock, body:has(.v2-take) .v4-dock { opacity: 0; transform: translateY(10px); pointer-events: none; visibility: hidden; transition: opacity .2s ease, transform .2s ease, visibility 0s .2s; }
/* folded at every width (it was covering pinned chapter copy at 768 and 1536); a mouse hover or keyboard focus also opens it */
.v4-dock:not(:has(.more[aria-expanded='true'])) .v4-d:not(.more) { display: none; }
.v4-dock:has(.more[aria-expanded='true']) .v4-d:not(.more) { animation: v5-dockin .18s ease-out both; }
@media (hover: hover) {
  .v4-dock:is(:hover, :focus-within) .v4-d:not(.more) { display: grid; animation: v5-dockin .18s ease-out both; }
}
@media (max-width: 700px) { .v4-dock .v4-panel { bottom: 52px; } }
@keyframes v5-dockin { from { opacity: 0; transform: translateX(10px); } }
@media (prefers-reduced-motion: reduce) { .v4-dock .v4-d:not(.more) { animation: none !important; } }

/* locked-recipe tiles: category plates fit their tile on phones ("Headwear" was clipped at 390) */
.v2-locked .plate { max-width: 100%; }
@media (max-width: 520px) { .v2-locked { gap: 8px; } }
/* sized to its own tile at every width (was clipped at 768 and 1024 too) */
.v2-locked .cubby { container-type: inline-size; }
.v2-locked .plate { font-size: clamp(9px, 13.5cqi, 16px); letter-spacing: 0; padding-inline: 3px; }

/* toasts rise out of the dock (bottom-right) instead of dropping over the top-right of the page,
   where they used to sit on the control-room LCD; they still never take clicks */
.v4-toast { top: auto; bottom: 66px; transform: translateY(10px) scale(.98); transform-origin: 100% 100%; }
.v4-toast.in { transform: none; }
html[data-route='home'] .v4-toast { bottom: 158px; }
@media (max-width: 700px) { .v4-toast { top: auto; bottom: 66px; right: 10px; max-width: calc(100vw - 20px); } html[data-route='home'] .v4-toast { bottom: 104px; } }
@media (prefers-reduced-motion: reduce) { .v4-toast { transform: none; } }
@media (max-width: 700px) { html[data-route='home'] .v2-hint { max-width: calc(100% - 84px); } }

/* ---------------------------------------------------------------- v5 extra: the shift clock (local time, punch to clock in) */
.v5-clock { position: relative; display: inline-flex; align-items: baseline; gap: .35em; margin: 0 0 0 .35em; padding: 2px 4px; font: inherit; letter-spacing: inherit; text-transform: inherit; color: var(--cream); text-shadow: none; background: none; border: 0; border-bottom: 2px dashed rgba(110, 240, 150, .35); cursor: pointer; transition: color .15s, border-color .15s; }
.v5-clock i { font-style: normal; color: rgba(110, 240, 150, .6); }
.v5-clock span { display: inline-block; font-variant-numeric: tabular-nums; }
.v5-clock:hover, .v5-clock:focus-visible { color: var(--yellow); border-bottom-color: var(--yellow); outline: none; }
.v5-clock:focus-visible { box-shadow: 0 0 0 2px var(--green); }
.v5-clock em { position: absolute; left: 100%; top: 50%; margin-left: 6px; padding: 2px 5px 1px; font: inherit; font-size: .7em; font-style: normal; line-height: 1; color: #1b1405; background: var(--yellow); border: 2px solid #000; opacity: 0; transform: translateY(-50%) rotate(-8deg) scale(1.6); pointer-events: none; }
.v5-clock.punch em { animation: v5-stamp 1.6s ease-out both; }
@keyframes v5-stamp { 0% { opacity: 0; transform: translateY(-50%) rotate(-8deg) scale(1.6); } 14% { opacity: 1; transform: translateY(-50%) rotate(-8deg) scale(1); } 75% { opacity: 1; transform: translateY(-50%) rotate(-8deg) scale(1); } 100% { opacity: 0; transform: translateY(-50%) rotate(-8deg) scale(1); } }
@media (prefers-reduced-motion: reduce) { @keyframes v5-stamp { 0%, 80% { opacity: 1; transform: translateY(-50%) rotate(-8deg); } 100% { opacity: 0; transform: translateY(-50%) rotate(-8deg); } } }
@media (max-width: 700px) { .v5-clock { margin-left: .2em; padding: 6px 4px; } }

/* ---------------------------------------------------------------- v5 extra: shelf jars wobble on their hooks when you hover them */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .v2-cell:hover img, .hero-cab .cubby:hover img { animation: v5-wobble .7s ease-in-out; transform-origin: 50% 12%; }
}
@keyframes v5-wobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-4deg); } 45% { transform: rotate(3deg); } 70% { transform: rotate(-1.5deg); } }

/* background-free jars in the remaining jar slots (empty states, reduced-motion mine anchor) */
@media (prefers-reduced-motion: reduce) { .ch-mine .v2-crt-slot .v2-anchor { background-image: url('../art/v5/jar/205.gif'); box-shadow: none; filter: drop-shadow(0 2px 0 #000); } }
html[data-route='lab'] { --empty-art: url('../art/v5/jar/639.gif'); }
html[data-route='breed'] { --empty-art: url('../art/v5/jar/205.gif'); }

/* ---------------------------------------------------------------- v5 polish: states, type, scrolling */
:focus-visible { border-radius: 0; }
button, a, [role='button'], summary { -webkit-tap-highlight-color: transparent; }
.btn { transition: transform .08s ease-out, filter .15s, background-color .15s, border-color .15s, box-shadow .15s; }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .55; cursor: not-allowed; filter: grayscale(.35); }
.btn:disabled:active, .btn[aria-disabled='true']:active { transform: none; }
::selection { background: rgba(110, 240, 150, .85); color: #04140a; }
h1, h2, h3, .v2-h2 { text-wrap: balance; }
.page p, .v2-ch p, .drawer p { text-wrap: pretty; }
[id] { scroll-margin-top: 84px; }
html { scrollbar-color: #3a4644 #070a09; }
.v4-panel { scrollbar-width: thin; }
.v4-d:focus-visible, .v4-tk:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
@media (max-width: 700px) { .v2-chip { min-height: 40px; display: inline-flex; align-items: center; } }

/* 06 legendaries: one row of eight on desktop so the stats never fall out of the pinned frame (1366x768, 1536x864) */
@media (min-width: 901px) {
  .v2-legs { flex-wrap: nowrap; }
  .v2-leg { flex: 0 1 auto; min-width: 0; width: min(clamp(84px, 9vw, 132px), calc((100% - 7 * clamp(8px, 1.4vw, 20px)) / 8)); }
}
@media (min-width: 901px) and (max-height: 900px) {
  .v2-leg { width: min(clamp(72px, 7vw, 112px), calc((100% - 7 * clamp(8px, 1.4vw, 20px)) / 8)); }
  .v2-leg figcaption { font-size: 15px; }
}
/* 02 break, reduced motion: copy sits in flow at the top of the still frame instead of centring above it */
@media (prefers-reduced-motion: reduce) and (min-width: 701px) {
  .v2-break-copy { position: relative; top: auto; transform: none; }
}
/* phones: the shift clock hangs off the right of the headline's first line instead of wrapping the eyebrow onto a second row */
@media (max-width: 560px) {
  #v2hero .v2-eyebrow { position: relative; }
  #v2hero .v5-clock { position: absolute; right: 0; top: calc(100% + 16px); margin: 0; padding: 6px 4px; z-index: 2; }
  #v2hero .v5-clock i { display: none; }
}
/* short laptop windows (a 1366x768 screen leaves ~650px of viewport): the hero copy used to rise under the header and lose its facts row */
@media (min-width: 701px) and (max-height: 800px) {
  .v2-hero-copy { top: calc(50% + 2px); }
  .v2-h1 { font-size: min(clamp(50px, 6.1vw, 116px), 10svh); margin-bottom: 16px; }
  .v2-hero .v2-lede { margin-bottom: 18px; }
  .v2-hero .v2-actions { margin-bottom: 20px; }
}
@media (min-width: 701px) and (max-width: 1180px) and (max-height: 680px) {
  .v2-hero .v2-facts { display: none; } /* the same four numbers run in the ticker right under it */
}
@media (min-width: 701px) and (max-width: 900px) and (max-height: 680px) {
  .v2-h1 { font-size: 8.4svh; }
  .v2-hero .v2-lede { font-size: 15px; margin-bottom: 14px; }
}

/* ---------------------------------------------------------------- v5b: claw-machine crane
   A yoke wider than any floor jar, one arm hung from each end. JS measures the jar's visible pixels every run and
   tilts both arms by the same angle so they close on opposite sides of it (arms are tagged .v5-al / .v5-ar in JS,
   so the carried jar being added to the claw can no longer knock :last-child off the right arm). */
.v4-claw { width: 7.6cqw; height: 5.2cqw; margin-left: -3.8cqw; }
.v4-claw::before { left: 0; right: 0; height: 1.1cqw; z-index: 2; box-sizing: border-box; background: linear-gradient(#8a9592, #5c6663); }
.v4-claw::after { content: ''; position: absolute; left: 50%; top: -.2cqw; width: 2cqw; height: 1.5cqw; margin-left: -1cqw; z-index: 3; background: #6f7a77; border: .25cqw solid #000; box-sizing: border-box; }
.v4-claw > i, .v4-claw.shut > i { --v5-rest: 4; top: .55cqw; width: .9cqw; height: 4.4cqw; z-index: 1; box-sizing: border-box; transform-origin: 50% 0; transition: none; }
.v4-claw > i.v5-al, .v4-claw.shut > i.v5-al { left: 0; right: auto; transform: rotate(calc(var(--v5-rest) * -1deg)); }
.v4-claw > i.v5-ar, .v4-claw.shut > i.v5-ar { left: auto; right: 0; transform: rotate(calc(var(--v5-rest) * 1deg)); }
.v4-claw > i::after { content: ''; position: absolute; bottom: -.25cqw; width: .75cqw; height: .8cqw; background: #9aa5a1; border: .25cqw solid #000; box-sizing: border-box; }
.v4-claw > i.v5-al::after { left: 50%; } .v4-claw > i.v5-ar::after { right: 50%; }
.v5-carry { position: absolute; z-index: 0; display: block; max-width: none; image-rendering: pixelated; pointer-events: none; filter: drop-shadow(0 .4cqw 0 rgba(0, 0, 0, .65)); }
.v4-scene > .v5-carry.free { z-index: 0; }

/* ---------------------------------------------------------------- v5b: breed row is symmetric
   Cat, spark, jar, spark, Bat. Both sparks are identical and send a small pulse toward the jar together; the jar's
   label reads "Baby?" until the hybrid shows, so all three labels sit on one line. Holds at every width. */
.v2-pair { gap: clamp(14px, 3vw, 48px); }
.v2-spark { position: relative; flex: none; }
.v2-spark::before, .v2-spark::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.v2-spark::before { box-shadow: 0 0 22px 4px var(--yellow); opacity: .35; animation: v5-glow 1.6s ease-in-out infinite; }
.v2-spark::after { inset: 28%; background: #fff6c8; opacity: 0; animation: v5-flow-a 1.6s cubic-bezier(.4, 0, .6, 1) infinite; }
.v2-spark.b::after { animation-name: v5-flow-b; }
@keyframes v5-glow { 0%, 100% { opacity: .25; } 45% { opacity: .9; } }
/* in the spark's rotated (45deg) frame, translate(k, -k) moves right and (-k, k) moves left: always toward the jar */
@keyframes v5-flow-a { 0% { transform: translate(-60%, 60%); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(110%, -110%); opacity: 0; } }
@keyframes v5-flow-b { 0% { transform: translate(60%, -60%); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(-110%, 110%); opacity: 0; } }
html.mx-hashing .v2-spark::before, html.mx-hashing .v2-spark::after { animation-play-state: paused !important; }
.v2-baby span { opacity: 1; position: relative; }
.v2-baby span b { display: block; font-weight: inherit; }
.v2-baby span .q { color: var(--cream); opacity: clamp(0, calc((.55 - var(--p, 0)) * 20), 1); }
.v2-baby span .n { position: absolute; left: 0; right: 0; top: 0; color: var(--green); opacity: clamp(0, calc((var(--p, 0) - .55) * 20), 1); }
@media (max-width: 700px) {
  .v2-pair { gap: 17px; } /* clears each tile's 11px frame ring so both sparks sit fully in the open */
  .v2-parent, .v2-baby { width: 22vw; }
  .v2-spark { display: block; z-index: 1; width: 12px; height: 12px; box-shadow: 0 0 14px var(--yellow); }
  .v2-spark::before { box-shadow: 0 0 12px 2px var(--yellow); }
}
@media (prefers-reduced-motion: reduce) { .v2-spark::before, .v2-spark::after { animation: none; } .v2-spark::before { opacity: .6; } }
/* the breed chapter is a centred composition: pad both sides where the chapter rail needs room, so the jar sits on the page centre */
@media (min-width: 901px) and (max-width: 1400px) { .ch-breed .wrap { padding-right: 100px; } }
/* duel arena strip: one control left (the crowd button is gone), so it sits centred; the name tag and readout hug the ends */
.v4-strip[data-r='duel'] { justify-content: center; min-height: 64px; }
.v4-strip[data-r='duel'] .v4-sk { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); }
.v4-strip[data-r='duel'] .v4-read { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); margin: 0; }
@media (max-width: 700px) {
  .v4-strip[data-r='duel'] { min-height: 0; }
  .v4-strip[data-r='duel'] .v4-read { position: static; transform: none; flex: 1 0 100%; justify-content: center; min-height: 0; }
  .v4-strip[data-r='duel'] .v4-read:empty { display: none; }
}
