/* Styles for The Chase (.chase-) and Kraken Attack (.kraken-). Colors come from tokens only. */

/* ---------- Shared overlay pieces ---------- */

.chase-overlay,
.kraken-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 5;
  cursor: pointer;
}
.chase-overlay::before,
.kraken-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0.78;
}
.chase-overlay[hidden],
.kraken-overlay[hidden] { display: none; }
.chase-card,
.kraken-card {
  position: relative;
  max-width: 30rem;
  text-align: center;
}
.chase-card h2,
.kraken-card h2 { margin-bottom: 0.3em; }
.chase-press,
.kraken-press {
  display: inline-block;
  padding: 4px 16px;
  border: 2px solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-primary);
  color: var(--sb-primary-ink);
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: 0;
  animation: ttk-pulse 1.6s ease-in-out infinite;
}
@keyframes ttk-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ---------- The Chase ---------- */

.chase {
  position: relative;
  display: grid;
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
}
.chase-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}
.chase-title { display: grid; flex: 1 1 14rem; min-width: 0; }
.chase-title strong { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; line-height: 1.2; }
/* free play: the HUD stats are sticker chips */
.chase-stats { flex: 0 1 auto; flex-wrap: nowrap; gap: 10px; }
.chase:not(.is-story) .chase-stats .stat,
.kraken:not(.is-story) .kraken-hud .stat {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-height: 40px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  box-shadow: 0 3px 0 var(--sb-outline);
}
.chase:not(.is-story) .chase-stats .stat-label,
.kraken:not(.is-story) .kraken-hud .stat-label { color: var(--sb-card-muted); }
.chase:not(.is-story) .chase-stats .stat-value,
.kraken:not(.is-story) .kraken-hud .stat-value { font-size: 1.2rem; line-height: 1.2; }
.chase:not(.is-story) .chase-forfeit,
.kraken:not(.is-story) .kraken-pause { background: var(--sb-chip); border-color: var(--sb-outline); box-shadow: 0 3px 0 var(--sb-outline); color: var(--sb-chip-ink); }
.chase-forfeit { margin-left: auto; }

.chase-track {
  position: relative;
  height: 124px;
  overflow: hidden;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  box-shadow: var(--sb-pop);
}
.chase-bgwrap { position: absolute; inset: 0; }
.chase-bg { display: block; width: 100%; height: 100%; }
.chase-start {
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  border-left: 3px dashed var(--sb-outline);
  opacity: 0.5;
}
.chase-finish {
  position: absolute;
  right: 8px;
  top: 0;
  bottom: 0;
  width: 12px;
  background: repeating-conic-gradient(var(--ink) 0 25%, var(--surface) 0 50%) 0 0 / 12px 12px;
  border-left: 1px solid var(--ink);
  border-right: 1px solid var(--ink);
}
.chase-lane {
  position: absolute;
  left: 0;
  right: 0;
  height: 52px;
}
.chase-lane-opp { top: 6px; }
.chase-lane-player { top: 64px; }
.chase-lane-inner {
  position: absolute;
  left: 12px;
  right: 30px;
  top: 0;
  bottom: 0;
}
.chase-mover {
  position: absolute;
  left: 0;
  bottom: 3px;
  width: 54px;
  will-change: transform;
  filter: drop-shadow(0 2px 1px var(--border));
}
.chase-mover-player { z-index: 2; }
.chase-icon { display: block; width: 100%; height: auto; overflow: visible; }

.chase-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  font-size: 0.9rem;
}
.chase-key { display: inline-flex; align-items: center; gap: 6px; }
.chase-swatch { display: inline-block; width: 30px; }

.chase-passage {
  --chase-lh: 1.9rem;
  position: relative;
  height: calc(var(--chase-lh) * 5 + 28px);
  padding: 14px 16px;
  overflow: hidden;
  background: var(--sb-card);
  color: var(--sb-card-ink);
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius);
  box-shadow: inset 0 -5px 0 var(--sb-card-2), var(--sb-pop);
  font-family: var(--font-mono);
  font-size: 1.12rem;
  line-height: var(--chase-lh);
  white-space: pre-wrap;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}
.chase-ch { border-radius: 3px; }
.chase-ch.is-pending { color: var(--pending); }
.chase-ch.is-correct { color: var(--sb-card-ink); }
.chase-ch.is-wrong {
  color: var(--bad);
  background: var(--surface-2);
  text-decoration: underline;
  text-decoration-color: var(--bad);
}
.chase-ch.is-current {
  background: var(--sb-primary);
  color: var(--sb-primary-ink);
}
.chase-status {
  min-height: 1.5em;
  font-size: 0.95rem;
}

.chase-overlay.is-count { pointer-events: none; }
.chase-overlay.is-count::before { opacity: 0.35; }
.chase-count {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(4rem, 18vw, 8rem);
  line-height: 1;
  color: var(--sb-sun);
  animation: chase-pop 0.9s ease-out;
}
.chase:not(.is-story) .chase-count,
.chase:not(.is-story) .chase-banner {
  font-weight: 700;
  paint-order: stroke fill;
  -webkit-text-stroke: 14px var(--sb-outline);
  text-shadow: 0 6px 0 var(--sb-outline);
}
.chase-count.is-go { color: var(--sb-kelp); }
.chase-banner {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 4.5rem);
  line-height: 1;
  animation: chase-pop 0.7s ease-out;
}
.chase-banner.is-won { color: var(--sb-kelp); }
.chase-banner.is-lost { color: var(--sb-pink); }
@keyframes chase-pop {
  0% { transform: scale(1.5); opacity: 0; }
  35% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.94); opacity: 0.85; }
}

@media (max-width: 640px) {
  .chase-passage { font-size: 1.02rem; --chase-lh: 1.75rem; padding: 12px; }
  .chase-stats .stat { min-width: 78px; }
  .chase-mover { width: 46px; }
  .chase-title { flex-basis: 100%; }
  .chase-forfeit { margin-left: 0; }
}

/* ---------- Kraken Attack ---------- */

.kraken {
  display: grid;
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
}
.kraken-hud {
  align-items: center;
  gap: 10px;
}
.kraken-pause { align-self: center; margin-left: auto; }

.kraken-hull { display: inline-flex; gap: 6px; align-items: center; min-height: 1.95rem; }
.kraken-rivet {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--sb-gold);
  border: 3px solid var(--sb-outline);
  box-shadow: inset 0 -3px 0 var(--sb-gold-lo);
  transition: background-color 0.2s, border-color 0.2s;
}
.kraken-rivet.is-lost {
  background: transparent;
  border-color: var(--sb-danger);
  border-style: dashed;
  box-shadow: none;
}

.kraken-stage {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  overflow: hidden;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius-lg);
  background: var(--sb-deep);
  box-shadow: var(--sb-pop);
  touch-action: manipulation;
}
.kraken-canvas {
  display: block;
  max-width: 100%;
  margin: 0 auto;
}
.kraken-hint { margin: 0; font-size: 0.95rem; font-weight: 600; text-align: center; }

@media (max-width: 640px) {
  .kraken:not(.is-story) .kraken-hud .stat { padding: 4px 10px; gap: 5px; }
  .kraken:not(.is-story) .kraken-hud .stat-label { font-size: 0.85rem; }
  .kraken-rivet { width: 14px; height: 14px; }
}

/* ---------- Story mode: Kraken Attack (the shark and the poulps) wears the cartoon look ----------
   Free play never gets .is-story, so none of this touches it. The canvas itself is painted with the
   art kit and js/games/story-art.js (toon.js); the HUD uses the story chip language (.sb-chip). */

.kraken.is-story { gap: 14px; }
.kraken-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.kraken-chips .kraken-chip { flex: none; padding: 6px 16px 6px 12px; }
.kraken-chips .kraken-chip .sb-icon { width: 1.35em; height: 1.35em; }
.kraken-chips .kraken-chip:nth-child(2) .sb-icon { color: var(--sb-danger); }
.kraken-chips .kraken-chip:nth-child(3) .sb-icon { color: var(--good); }
.kraken-chip-label {
  font: 600 0.9rem/1 var(--font-body);
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}
.kraken-chip-value {
  min-width: 3ch;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.2;
  text-align: right;
}
.kraken.is-story .kraken-pause { align-self: center; margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.kraken.is-story .kraken-hull { min-height: 0; gap: 7px; }
/* three round lives: sunny when safe, an empty dashed ring when lost */
.kraken.is-story .kraken-rivet {
  width: 16px;
  height: 16px;
  background: var(--sb-sun);
  border: 2.5px solid var(--sb-outline);
  box-shadow: inset 2px 2px 0 rgb(255 255 255 / 0.65);
}
.kraken.is-story .kraken-rivet.is-lost {
  background: transparent;
  border-color: var(--sb-danger);
  border-style: dashed;
  box-shadow: none;
}

/* the stage: a sticker frame with an ink outline */
.kraken.is-story .kraken-stage {
  border: 6px solid var(--sb-sun);
  border-radius: var(--radius-lg);
  background: var(--sb-deep);
  box-shadow: 0 0 0 var(--sb-outline-w) var(--sb-outline), inset 0 0 0 var(--sb-outline-w) var(--sb-outline), 0 6px 0 var(--sb-outline);
  background-clip: padding-box;
}
.kraken.is-story .kraken-hint { color: var(--ink-muted); }

/* the rules card: a white sticker over a tinted sea */
.kraken.is-story .kraken-overlay::before { background: var(--sb-deep); opacity: 0.5; }
.kraken.is-story .kraken-card {
  color: var(--sb-card-ink);
  background: var(--sb-card);
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius);
  box-shadow: var(--sb-pop), var(--sb-shadow-lg);
  animation: sb-pop 0.45s var(--ease-spring, ease) both;
}
.kraken.is-story .kraken-card h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; }
.kraken.is-story .kraken-press {
  display: inline-block;
  padding: 3px 14px 4px;
  border-radius: 999px;
  background: var(--sb-sun);
  color: var(--sb-primary-ink);
  border: 2px solid var(--sb-outline);
  font-family: var(--font-display);
  font-weight: 600;
}

@media (max-width: 640px) {
  .kraken-chips { display: grid; grid-template-columns: repeat(3, auto) 1fr; gap: 6px; }
  .kraken-chips .kraken-chip { min-width: 0; justify-content: center; gap: 5px; padding: 6px 9px; }
  .kraken.is-story .kraken-pause { justify-self: end; padding-inline: 12px; }
  .kraken.is-story .kraken-hull { gap: 4px; }
  .kraken.is-story .kraken-rivet { width: 13px; height: 13px; }
  .kraken-chips .kraken-chip-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .kraken-chip-value { min-width: 0; font-size: 1.05rem; }
  .kraken.is-story .kraken-stage { border-width: 4px; }
  .kraken.is-story .kraken-card h2 { font-size: 1.4rem; }
}

/* ---------- Story mode: The Hunt (the frigate and the creature) wears the cartoon look ----------
   Only .chase.is-story, which free play never gets. The canvas is painted with the art kit. */

.chase.is-story { gap: 14px; }
.chase.is-story .chase-hud { align-items: center; }
.chase.is-story .chase-title .eyebrow { color: var(--ink-muted); }
.chase.is-story .chase-title strong { font-family: var(--font-display); font-weight: 600; }
.chase-chips { display: flex; flex: 0 1 auto; align-items: center; gap: 10px; }
.chase-chips .chase-chip { flex: none; padding: 6px 16px 6px 12px; }
.chase-chips .chase-chip .sb-icon { width: 1.35em; height: 1.35em; }
.chase-chips .chase-chip:nth-child(2) .sb-icon { color: var(--sb-orange); }
.chase-chip-label {
  font: 600 0.9rem/1 var(--font-body);
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}
.chase-chip-value {
  min-width: 3ch;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.2;
  text-align: right;
}
.chase.is-story .chase-chip:nth-child(2) .chase-chip-value { min-width: 4ch; }

/* the sea: a sticker frame, the canvas filling it */
.chase.is-story .chase-track {
  height: clamp(190px, 31vw, 320px);
  border: 6px solid var(--sb-sun);
  border-radius: var(--radius-lg);
  background: var(--sb-deep);
  box-shadow: 0 0 0 var(--sb-outline-w) var(--sb-outline), inset 0 0 0 var(--sb-outline-w) var(--sb-outline), 0 6px 0 var(--sb-outline);
  background-clip: padding-box;
}
.chase-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

/* the passage: a white card with an ink outline, like the typing box in the other story steps */
.chase.is-story .chase-passage {
  color: var(--sb-card-ink);
  background: var(--sb-card);
  border: var(--sb-outline-w) solid var(--sb-outline);
  box-shadow: var(--sb-pop), var(--sb-shadow-lg);
}
.chase.is-story .chase-ch.is-pending { color: var(--sb-card-muted); }
.chase.is-story .chase-ch.is-correct { color: var(--sb-card-ink); }
.chase.is-story .chase-ch.is-wrong {
  color: color-mix(in srgb, var(--sb-danger) 62%, var(--sb-card-ink));
  background: color-mix(in srgb, var(--sb-danger) 14%, transparent);
  text-decoration-color: var(--sb-danger);
}
.chase.is-story .chase-ch.is-current { background: var(--sb-glow-color); color: var(--sb-primary-ink); border-radius: 4px; }

/* the rules card, the count and the banner: stickers over a tinted sea */
.chase.is-story .chase-overlay::before { background: var(--sb-deep); opacity: 0.5; border-radius: var(--radius-lg); }
.chase.is-story .chase-overlay.is-count::before { opacity: 0.16; }
.chase.is-story .chase-card {
  color: var(--sb-card-ink);
  background: var(--sb-card);
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius);
  box-shadow: var(--sb-pop), var(--sb-shadow-lg);
  animation: sb-pop 0.45s var(--ease-spring, ease) both;
}
.chase.is-story .chase-card h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; }
.chase.is-story .chase-press {
  display: inline-block;
  padding: 3px 14px 4px;
  border-radius: 999px;
  background: var(--sb-sun);
  color: var(--sb-primary-ink);
  border: 2px solid var(--sb-outline);
  font-family: var(--font-display);
  font-weight: 600;
}
.chase.is-story .chase-count,
.chase.is-story .chase-banner {
  color: var(--sb-card-ink);
  background: var(--sb-card);
  border: var(--sb-outline-w) solid var(--sb-outline);
  box-shadow: var(--sb-pop);
  -webkit-text-stroke: 0;
  text-shadow: none;
  paint-order: normal;
}
.chase.is-story .chase-count {
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  font-size: clamp(2.6rem, 11vw, 4.6rem);
  border-radius: 50%;
  background: var(--sb-sun);
  color: var(--sb-primary-ink);
}
.chase.is-story .chase-count.is-go { background: var(--sb-kelp); color: var(--sb-primary-ink); }
.chase.is-story .chase-banner {
  padding: 0.12em 0.6em 0.2em;
  border-radius: var(--radius);
  font-size: clamp(2rem, 7vw, 3.6rem);
  transform: rotate(-2deg);
}
.chase.is-story .chase-banner.is-won { background: var(--sb-kelp); color: var(--sb-primary-ink); }
.chase.is-story .chase-banner.is-lost { background: var(--sb-pink); color: var(--sb-primary-ink); }

@media (max-width: 640px) {
  .chase-chips { gap: 6px; }
  .chase-chips .chase-chip { gap: 5px; padding: 6px 10px 6px 8px; }
  .chase-chips .chase-chip-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .chase-chip-value { min-width: 0; font-size: 1.05rem; }
  .chase.is-story .chase-track { border-width: 4px; height: clamp(190px, 56vw, 250px); }
  .chase.is-story .chase-card h2 { font-size: 1.4rem; }
}

html.reduced-motion .kraken.is-story .kraken-card,
html.reduced-motion .chase.is-story .chase-card { animation: none; }
