/* Wordblock Theater — STYLE.md tokens + touch-first phone UI */
:root {
  --stage-black: #1A1220;
  --curtain-red: #E63946;
  --candy-cyan: #00C2FF;
  --lemon: #FFE66D;
  --lime: #7CFC9A;
  --cream: #FFF6E8;
  --ink: #0D0A12;
  --outline: 3px;
  --radius: 16px;
  --tap: 52px;
  --font: "Fredoka", "Nunito", system-ui, sans-serif;
  --shadow: 0 4px 0 var(--ink);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  width: 100%;
  background: var(--stage-black);
  color: var(--cream);
  font-family: var(--font);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#app {
  width: 100%;
  max-width: 430px;
  height: 100%;
  max-height: 100dvh;
  margin: 0 auto;
  position: relative;
  background: var(--stage-black);
  overflow: hidden;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 12px;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.screen.active { display: flex; }
#screen-stage {
  touch-action: none;
  overflow: hidden;
  padding: 0;
  justify-content: flex-start;
}
#screen-stage.active { display: flex; }

.curtain-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 36px;
  background: linear-gradient(180deg, var(--curtain-red) 70%, #b02a34);
  border-bottom: 4px solid var(--ink);
  z-index: 1;
}

.title-art { width: 92%; max-width: 360px; margin-top: 44px; }
.title-banner {
  width: 100%;
  height: auto;
  display: block;
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  object-fit: cover;
  aspect-ratio: 16/9;
}

.game-title {
  font-size: clamp(1.5rem, 7vw, 2.1rem);
  font-weight: 700;
  color: var(--lemon);
  text-shadow: 3px 3px 0 var(--ink);
  margin: 14px 0 6px;
  text-align: center;
}
.tagline {
  color: var(--candy-cyan);
  font-size: 0.92rem;
  text-align: center;
  margin-bottom: 22px;
  max-width: 300px;
}
.credit-mini {
  margin-top: 18px;
  font-size: 0.68rem;
  opacity: 0.55;
  text-align: center;
}

.btn {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.1rem;
  min-height: var(--tap);
  padding: 14px 28px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-primary { background: var(--lemon); color: var(--ink); }
.btn-choice {
  background: var(--cream);
  color: var(--ink);
  width: 100%;
  text-align: left;
  border-radius: 16px;
  margin-top: 10px;
  font-size: 1rem;
  line-height: 1.35;
  min-height: 56px;
  padding: 14px 16px;
}

.if-panel {
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  width: 100%;
  max-width: 380px;
  max-height: 92%;
  overflow-y: auto;
  touch-action: pan-y;
}
.narrator-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.narrator-mic {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 12px;
  border: 3px solid var(--ink);
  background: var(--stage-black);
}
.narrator-badge {
  display: inline-block;
  background: var(--curtain-red);
  color: var(--cream);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 999px;
  border: 3px solid var(--ink);
}
.if-text {
  font-size: 1.02rem;
  line-height: 1.45;
  margin-bottom: 14px;
  white-space: pre-wrap;
}
.choices { display: flex; flex-direction: column; gap: 2px; }

.ending-panel { text-align: center; }
.ending-hero {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 20px;
  border: 3px solid var(--ink);
  margin-bottom: 8px;
  background: #FFF6E8;
}
.ending-panel h2 {
  color: var(--curtain-red);
  font-size: 1.4rem;
  margin-bottom: 10px;
}
.ending-stats {
  background: var(--stage-black);
  color: var(--cream);
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0 18px;
  font-size: 0.9rem;
  text-align: left;
  border: 3px solid var(--ink);
}
.ending-stats div { margin: 4px 0; }

/* HUD */
#hud {
  width: 100%;
  padding: 8px 10px 4px;
  background: linear-gradient(180deg, #2a1f35, var(--stage-black));
  border-bottom: 3px solid var(--ink);
  z-index: 5;
  flex-shrink: 0;
}
.hud-row { display: flex; gap: 8px; align-items: center; }
.stat { flex: 1; display: flex; align-items: center; gap: 6px; }
.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--lemon);
  min-width: 28px;
}
.bar {
  flex: 1;
  height: 14px;
  background: var(--ink);
  border: 2px solid var(--cream);
  border-radius: 8px;
  overflow: hidden;
}
.bar-fill { height: 100%; width: 100%; transition: width 0.15s ease; border-radius: 6px; }
.bar-fill.hp { background: var(--curtain-red); }
.bar-fill.ink { background: var(--candy-cyan); transition: width 0.08s linear; }
.bar-fill.ink.draining {
  background: linear-gradient(90deg, #00C2FF, #7CFC9A, #00C2FF);
  background-size: 200% 100%;
  animation: inkDrainPulse 0.7s linear infinite;
}
@keyframes inkDrainPulse {
  0% { background-position: 0% 0; filter: brightness(1); }
  50% { background-position: 100% 0; filter: brightness(1.25); }
  100% { background-position: 0% 0; filter: brightness(1); }
}
.hud-meta {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--cream);
  justify-content: space-between;
  opacity: 0.9;
}
.buff-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.buff-chip {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--lemon);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px 8px;
}

#game-canvas {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: block;
  background: var(--stage-black);
  touch-action: none;
}

.narrator-toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  max-width: 88%;
  z-index: 20;
  box-shadow: var(--shadow);
  pointer-events: none;
  text-align: center;
}
.narrator-toast.hidden { display: none; }

/* Summon chips — primary touch summon path */
.summon-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: #241833;
  border-top: 3px solid var(--ink);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: none;
}
.summon-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 72px;
  padding: 8px 14px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--candy-cyan);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  text-transform: uppercase;
}
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.chip.locked {
  background: #5a4a6a;
  color: #cbb;
  opacity: 0.7;
}
.chip.cooling {
  background: #7a90a0;
  opacity: 0.85;
}
.chip.noink { opacity: 0.45; }
.chip.active-toggle {
  background: var(--lemon);
  border-color: var(--candy-cyan);
  box-shadow: 0 0 0 3px var(--candy-cyan), 0 0 14px rgba(0, 194, 255, 0.85), 0 3px 0 var(--ink);
  animation: chipPulse 1.1s ease-in-out infinite;
}
@keyframes chipPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}

/* Touch controls — thumb corners */
#touch-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #1a1220;
  flex-shrink: 0;
  gap: 12px;
  border-top: 2px solid #2a1f35;
}
.pad-left, .pad-right { display: flex; gap: 10px; }
.tc {
  min-width: var(--tap);
  min-height: var(--tap);
  font-family: var(--font);
  font-weight: 800;
  font-size: 1.15rem;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.tc:active, .tc.held {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
  background: var(--lime);
}
.tc-jump {
  background: var(--candy-cyan);
  min-width: 78px;
  font-size: 0.95rem;
}
.tc-atk {
  background: var(--curtain-red);
  color: var(--cream);
  min-width: 70px;
  font-size: 0.95rem;
}

#app.shake { animation: shake 0.25s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

/* Language toggle — always visible, thumb-friendly */
#lang-bar {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 100;
  pointer-events: none;
}
.btn-lang {
  pointer-events: auto;
  font-family: var(--font);
  font-weight: 800;
  font-size: 1rem;
  min-width: 64px;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--lemon);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.btn-lang:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}
.ending-hero, .narrator-mic {
  background: transparent !important;
}
.title-banner {
  background: var(--stage-black);
}


/* Intermission reward showcase */
.reward-panel {
  margin: 12px 0 4px;
  padding: 12px;
  background: rgba(26, 18, 32, 0.85);
  border: 3px solid var(--lemon, #FFE66D);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink, #1A1220);
}
.reward-head {
  font-family: var(--font-display, Nunito, sans-serif);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--lemon, #FFE66D);
  margin-bottom: 10px;
  text-align: center;
}
.reward-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.reward-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 64px;
  padding: 8px 10px;
  background: var(--cream, #FFF6E8);
  border: 2.5px solid var(--ink, #1A1220);
  border-radius: 12px;
  box-shadow: 0 2px 0 var(--ink, #1A1220);
  animation: rewardPop 0.45s ease backwards;
}
.reward-chip:nth-child(1) { animation-delay: 0.05s; }
.reward-chip:nth-child(2) { animation-delay: 0.1s; }
.reward-chip:nth-child(3) { animation-delay: 0.15s; }
.reward-chip:nth-child(4) { animation-delay: 0.2s; }
.reward-chip:nth-child(5) { animation-delay: 0.25s; }
.reward-icon { font-size: 22px; line-height: 1; }
.reward-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink, #1A1220);
  text-align: center;
}
@keyframes rewardPop {
  from { transform: scale(0.6) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* Capture helper: highlight newly unlocked summon chips */
.chip.capture-glow {
  outline: 2px solid #FFE66D;
  outline-offset: 2px;
  box-shadow: 0 0 10px rgba(255, 230, 109, 0.85);
  position: relative;
  z-index: 2;
}


/* —— Reward route perception (next-act cues) —— */
.route-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  min-height: 0;
}
.route-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  color: var(--ink);
  letter-spacing: 0.02em;
  box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
.route-badge[data-route="swarm"] { background: #FF8FAB; }
.route-badge[data-route="loot"] { background: #FFE66D; }
.route-badge[data-route="tease"] { background: #C4B5FD; }
.route-badge[data-route="brave"] { background: #FFB347; }
.route-badge[data-route="crafty"] { background: #7CFC9A; }
.route-badge[data-route="chaos"] { background: #00C2FF; }

.crafty-kit {
  position: absolute;
  right: 10px;
  top: 8px;
  display: flex;
  gap: 4px;
  z-index: 6;
  pointer-events: none;
}
.crafty-kit.hidden { display: none; }
.crafty-icon {
  font-size: 18px;
  line-height: 1;
  filter: drop-shadow(0 1px 0 #1A1220);
  animation: craftyBob 1.4s ease-in-out infinite;
}
.crafty-icon:nth-child(2) { animation-delay: 0.35s; }
@keyframes craftyBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

#hud { position: relative; }

.route-banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 25;
  pointer-events: none;
  width: min(340px, 92%);
  text-align: center;
  background: linear-gradient(180deg, #FFF6E8 0%, #FFE66D 100%);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 16px;
  padding: 12px 14px 14px;
  box-shadow: 0 8px 0 rgba(26,18,32,0.55), 0 0 24px rgba(255,230,109,0.45);
  animation: routeBannerIn 0.45s cubic-bezier(.2,1.4,.4,1) both;
}
.route-banner.hidden { display: none; }
.route-banner.route-swarm { background: linear-gradient(180deg, #FFE0EA, #FF8FAB); }
.route-banner.route-loot { background: linear-gradient(180deg, #FFF6E8, #FFE66D); }
.route-banner.route-tease { background: linear-gradient(180deg, #F3E8FF, #C4B5FD); }
.route-banner.route-brave { background: linear-gradient(180deg, #FFF0D6, #FFB347); }
.route-banner.route-crafty { background: linear-gradient(180deg, #E8FFE8, #7CFC9A); }
.route-banner.route-chaos { background: linear-gradient(180deg, #E0F9FF, #00C2FF); }
.route-banner-sub {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 4px;
}
.route-banner-main {
  font-family: var(--font-display, 'Nunito', sans-serif);
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1.25;
}
.route-banner-alt {
  margin-top: 4px;
  font-size: 0.92rem;
  font-weight: 700;
  opacity: 0.92;
}
.route-banner-hint {
  margin-top: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.75;
}
@keyframes routeBannerIn {
  from { transform: translateX(-50%) translateY(-18px) scale(0.88); opacity: 0; }
  to { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

.tease-popup {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translateX(-50%);
  z-index: 22;
  pointer-events: none;
  width: min(300px, 88%);
  background: rgba(26,18,32,0.9);
  color: #FFF6E8;
  border: 3px solid #C4B5FD;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.35;
  box-shadow: 0 6px 0 rgba(0,0,0,0.35);
  animation: teasePop 0.4s ease both;
}
.tease-popup.hidden { display: none; }
@keyframes teasePop {
  from { transform: translateX(-50%) scale(0.9); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

.stage-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  mix-blend-mode: soft-light;
}
.stage-fx::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#screen-stage.route-swarm .stage-fx::before {
  opacity: 1;
  background: radial-gradient(ellipse at 50% 30%, rgba(255,100,140,0.35), transparent 65%),
              linear-gradient(180deg, rgba(255,80,120,0.18), transparent 50%);
}
#screen-stage.route-brave .stage-fx::before {
  opacity: 1;
  background: radial-gradient(ellipse at 50% 20%, rgba(255,180,40,0.32), transparent 60%),
              linear-gradient(180deg, rgba(255,140,0,0.16), transparent 55%);
}
#screen-stage.route-chaos .stage-fx::before {
  opacity: 1;
  background: radial-gradient(ellipse at 70% 25%, rgba(0,194,255,0.28), transparent 55%),
              radial-gradient(ellipse at 25% 40%, rgba(196,181,253,0.22), transparent 50%);
}
#screen-stage.route-swarm.route-brave .stage-fx::before,
#screen-stage.route-swarm.route-chaos .stage-fx::before,
#screen-stage.route-brave.route-chaos .stage-fx::before {
  opacity: 1;
}

/* Loot-route summon chips sparkle */
.chip.route-loot-spark {
  outline: 2px solid #FFE66D;
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(255, 230, 109, 0.9), 0 0 2px #FFF6E8;
  position: relative;
  z-index: 2;
  animation: lootSparkPulse 1.1s ease-in-out infinite;
}
.chip.route-loot-spark::after {
  content: '✨';
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 12px;
  animation: lootSparkSpin 1.6s linear infinite;
}
@keyframes lootSparkPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}
@keyframes lootSparkSpin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(12deg) scale(1.15); }
  100% { transform: rotate(0deg) scale(1); }
}

/* Extra spawn VFX dots (DOM particles over canvas corners) */
.stage-spawn-vfx {
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}
.stage-spawn-vfx span {
  position: absolute;
  font-size: 16px;
  animation: spawnFloat 2.2s ease-in-out infinite;
  opacity: 0.85;
}
@keyframes spawnFloat {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.55; }
  50% { transform: translateY(-10px) scale(1.15); opacity: 1; }
}
