*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-sky: linear-gradient(180deg, #bae6fd 0%, #fef08a 55%, #86efac 100%);
  --heracles-color: #f59e0b;
  --iolaus-color: #f97316;
  --hydra-green: #4ade80;
  --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro", "NanumSquareRound", "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-stack);
  background-color: #7dd3fc;
  color: #1e293b;
  touch-action: manipulation;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Outer Game Screen (Mobile viewport frame on desktop) */
.game-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  max-height: 890px;
  background: var(--bg-sky);
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 45px rgba(14, 116, 144, 0.35);
  border-radius: 28px;
  overflow: hidden;
  border: 4px solid #ffffff;
}

/* =========================================
   TOP HUD BAR
========================================= */
.hud-bar {
  height: 64px;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  z-index: 30;
}

.hud-left, .hud-right {
  display: flex;
  gap: 8px;
}

.hud-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #bae6fd;
  color: #0369a1;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.08);
  transition: transform 0.1s, background-color 0.2s;
}

.hud-btn:active {
  transform: scale(0.9);
  background: #f0f9ff;
}

.hud-center {
  text-align: center;
}

.badge-title {
  font-size: 0.78rem;
  color: #0284c7;
  letter-spacing: 0.5px;
  font-weight: 800;
}

.head-counter-box {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-top: 1px;
}

.head-counter-box .label {
  font-size: 0.92rem;
  font-weight: 700;
  color: #334155;
}

.head-counter-box .count-num {
  font-size: 1.65rem;
  font-weight: 900;
  color: #15803d;
  transition: transform 0.2s, color 0.2s;
}

.head-counter-box .count-num.danger {
  color: #ea580c;
  animation: pulseBounce 0.5s infinite alternate;
}

.head-counter-box .count-max {
  font-size: 0.85rem;
  font-weight: 700;
  color: #64748b;
}

@keyframes pulseBounce {
  from { transform: scale(1); }
  to { transform: scale(1.22); }
}

/* Friendly Warning Bar */
.danger-bar {
  background: #f97316;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  padding: 6px 10px;
  z-index: 25;
  box-shadow: 0 2px 6px rgba(249, 115, 22, 0.3);
}

.danger-bar.hidden {
  display: none;
}

/* =========================================
   BATTLE STAGE
========================================= */
.battle-stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

/* Gentle screen shake */
.battle-stage.shake {
  animation: softShake 0.22s ease-out;
}

@keyframes softShake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-4px, 3px); }
  50% { transform: translate(4px, -3px); }
  75% { transform: translate(-2px, 2px); }
}

/* Fairytale Background Elements */
.stage-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* Smiling Happy Sun */
.sun {
  position: absolute;
  top: 14px;
  right: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle, #fde047 0%, #f59e0b 100%);
  box-shadow: 0 0 25px rgba(253, 224, 71, 0.7);
  animation: sunGlow 3s infinite alternate ease-in-out;
}

@keyframes sunGlow {
  0% { transform: scale(0.96) rotate(0deg); }
  100% { transform: scale(1.05) rotate(10deg); }
}

/* Fluffy Floating Clouds */
.cloud {
  position: absolute;
  background: #ffffff;
  border-radius: 50px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  opacity: 0.85;
}

.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: #ffffff;
  border-radius: 50%;
}

.cloud-1 {
  top: 30px;
  left: 20px;
  width: 80px;
  height: 28px;
  animation: floatCloud 7s infinite alternate ease-in-out;
}
.cloud-1::before { width: 34px; height: 34px; top: -14px; left: 14px; }
.cloud-1::after { width: 28px; height: 28px; top: -10px; left: 40px; }

.cloud-2 {
  top: 75px;
  right: 60px;
  width: 65px;
  height: 22px;
  animation: floatCloud 6s infinite alternate-reverse ease-in-out;
}
.cloud-2::before { width: 28px; height: 28px; top: -12px; left: 10px; }
.cloud-2::after { width: 22px; height: 22px; top: -8px; left: 32px; }

@keyframes floatCloud {
  from { transform: translateX(0); }
  to { transform: translateX(18px); }
}

/* Greek Pillars (Pastel Cute) */
.pillar {
  position: absolute;
  bottom: 120px;
  width: 26px;
  height: 160px;
  background: linear-gradient(90deg, #f8fafc 0%, #e2e8f0 50%, #cbd5e1 100%);
  border-radius: 6px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
  opacity: 0.8;
}

.pillar::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -5px;
  width: 36px;
  height: 10px;
  background: #e2e8f0;
  border-radius: 4px;
}

.pillar-left { left: 14px; }
.pillar-right { right: 14px; height: 130px; }

/* Flower Field at the bottom */
.flower-field {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(180deg, rgba(134, 239, 172, 0.7) 0%, #4ade80 100%);
  border-top: 3px solid rgba(255, 255, 255, 0.6);
}

.flower {
  position: absolute;
  font-size: 1.4rem;
  bottom: 12px;
  animation: swayFlower 2.5s infinite alternate ease-in-out;
}
.f1 { left: 15%; animation-delay: 0s; }
.f2 { left: 38%; animation-delay: 0.8s; }
.f3 { left: 65%; animation-delay: 0.4s; }
.f4 { left: 85%; animation-delay: 1.2s; }

@keyframes swayFlower {
  from { transform: rotate(-8deg); }
  to { transform: rotate(8deg); }
}

/* =========================================
   HYDRA SECTION & HEADS
========================================= */
.hydra-section {
  position: relative;
  z-index: 10;
  width: 100%;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.hydra-heads-container {
  position: relative;
  width: 100%;
  height: 190px;
}

/* Head Unit */
.hydra-head-unit {
  position: absolute;
  bottom: 15px;
  width: 70px;
  height: 150px;
  transform-origin: bottom center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 12;
}

.head-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
}

.neck-path {
  fill: none;
  stroke: #4ade80;
  stroke-width: 17;
  stroke-linecap: round;
}

.neck-spots {
  fill: none;
  stroke: #22c55e;
  stroke-width: 5;
  stroke-dasharray: 4 10;
}

/* Head Idle Cute Bobbing */
.head-idle {
  animation: headBob 2.8s infinite ease-in-out alternate;
}

@keyframes headBob {
  0% { transform: rotate(-5deg) translateY(0); }
  50% { transform: rotate(4deg) translateY(-6px); }
  100% { transform: rotate(-3deg) translateY(2px); }
}

/* Head Bonked / Flying off cutely like a soap bubble */
.head-severed {
  animation: popFlyHead 0.75s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards !important;
  pointer-events: none;
}

@keyframes popFlyHead {
  0% { transform: scale(1.2) rotate(0); opacity: 1; }
  35% { transform: translate(-25px, -65px) rotate(-30deg) scale(1.1); }
  100% { transform: translate(-50px, -140px) rotate(-120deg) scale(0); opacity: 0; }
}

/* New Head Sprout Animation */
.head-sprout {
  animation: sproutCuteHead 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes sproutCuteHead {
  0% { transform: scale(0) translateY(40px); opacity: 0; }
  70% { transform: scale(1.25) translateY(-8px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* Cute Sleeping Seal (Heart Bandage & Zzz) */
.cauterized-stump {
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle, #fef08a 0%, #fde047 80%);
  border: 2px solid #ffffff;
  box-shadow: 0 0 15px rgba(254, 240, 138, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  animation: stampSleep 1s ease-out forwards;
}

@keyframes stampSleep {
  0% { transform: scale(0.4) rotate(-30deg); opacity: 1; }
  50% { transform: scale(1.3) rotate(15deg); }
  100% { transform: scale(1) rotate(0); opacity: 0.9; }
}

/* Hydra Body */
.hydra-body-wrapper {
  position: relative;
  width: 200px;
  height: 125px;
  z-index: 11;
  filter: drop-shadow(0 8px 15px rgba(0, 0, 0, 0.12));
}

.hydra-body-svg {
  width: 100%;
  height: 100%;
}

/* Friendly Torch Timer Prompt */
.cauterize-prompt {
  position: absolute;
  top: 15px;
  background: #ffffff;
  border: 3px solid #f97316;
  box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35);
  border-radius: 24px;
  padding: 8px 18px;
  text-align: center;
  z-index: 25;
  animation: promptPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cauterize-prompt.hidden {
  display: none;
}

@keyframes promptPop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.prompt-text {
  font-size: 0.95rem;
  font-weight: 800;
  color: #ea580c;
  letter-spacing: -0.2px;
}

.timer-track {
  width: 100%;
  height: 8px;
  background: #fed7aa;
  border-radius: 6px;
  margin-top: 6px;
  overflow: hidden;
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #fde047 0%, #f97316 100%);
  border-radius: 6px;
  transition: width 0.05s linear;
}

/* =========================================
   HEROES SECTION (Chibi Heracles & Iolaus)
========================================= */
.heroes-section {
  position: relative;
  z-index: 15;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 6px;
}

/* Speech Bubble */
.speech-bubble {
  position: relative;
  background: #ffffff;
  color: #0f172a;
  border-radius: 18px;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 800;
  margin-bottom: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  border: 2px solid #bae6fd;
  max-width: 90%;
  text-align: center;
  transition: transform 0.2s;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 7px 7px 0;
  border-style: solid;
  border-color: #ffffff transparent;
}

.heroes-container {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
}

.hero-character {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.character-name-tag {
  font-size: 0.82rem;
  font-weight: 800;
  background: #ffffff;
  border: 2px solid #fed7aa;
  border-radius: 12px;
  padding: 2px 10px;
  margin-bottom: 4px;
  color: #9a3412;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.hero-avatar {
  width: 110px;
  height: 125px;
  transition: transform 0.15s ease;
}

.hero-svg {
  width: 100%;
  height: 100%;
}

/* Heracles Squeaky Hammer Swing */
.weapon-club {
  transform-origin: 84px 83px;
  transition: transform 0.1s ease-out;
}

.heracles-swing .weapon-club {
  animation: hammerBonk 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.heracles-swing {
  animation: heroHop 0.32s ease-out;
}

@keyframes hammerBonk {
  0% { transform: rotate(-30deg); }
  50% { transform: rotate(50deg) scale(1.15); }
  100% { transform: rotate(0); }
}

@keyframes heroHop {
  0% { transform: translateY(0); }
  45% { transform: translateY(-10px) scale(1.05); }
  100% { transform: translateY(0) scale(1); }
}

/* Iolaus Warm Torch Shining */
.weapon-torch {
  transform-origin: 22px 100px;
  transition: transform 0.1s ease-out;
}

.flame-group {
  animation: cuteFlicker 0.4s infinite alternate ease-in-out;
}

@keyframes cuteFlicker {
  0% { transform: scale(0.95) rotate(-3deg); }
  100% { transform: scale(1.06) rotate(3deg); }
}

.iolaus-thrust .weapon-torch {
  animation: torchWave 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.iolaus-thrust {
  animation: heroHop 0.35s ease-out;
}

@keyframes torchWave {
  0% { transform: rotate(10deg); }
  50% { transform: translateY(-20px) translateX(-15px) rotate(-30deg) scale(1.2); }
  100% { transform: rotate(0) scale(1); }
}

/* =========================================
   VFX & PARTICLES
========================================= */
.vfx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 28;
  overflow: hidden;
}

.vfx-particle {
  position: absolute;
  font-size: 2rem;
  pointer-events: none;
  animation: floatCuteParticle 0.75s ease-out forwards;
}

@keyframes floatCuteParticle {
  0% { transform: scale(0.4) translateY(0); opacity: 1; }
  50% { transform: scale(1.3) translateY(-30px); opacity: 1; }
  100% { transform: scale(0.9) translateY(-65px); opacity: 0; }
}

/* =========================================
   CONTROLS FOOTER (Child-friendly Buttons)
========================================= */
.controls-footer {
  height: 98px;
  padding: 10px 14px 18px;
  background: #ffffff;
  border-top: 3px solid #e2e8f0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  z-index: 30;
  box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
}

.action-btn {
  border: none;
  border-radius: 22px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  color: #ffffff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15), 0 8px 16px rgba(0, 0, 0, 0.08);
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.08s ease;
}

.action-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 3px 6px rgba(0, 0, 0, 0.08);
  filter: brightness(1.15);
}

.btn-icon {
  font-size: 2.1rem;
}

.btn-labels {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.main-label {
  font-size: 1.08rem;
  font-weight: 900;
  letter-spacing: -0.2px;
}

.sub-label {
  font-size: 0.74rem;
  font-weight: 700;
  opacity: 0.95;
}

/* Button Themes */
.btn-heracles {
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
  border: 3px solid #fde047;
  color: #78350f;
}

.btn-iolaus {
  background: linear-gradient(180deg, #fb923c 0%, #ea580c 100%);
  border: 3px solid #fdba74;
  color: #ffffff;
}

.btn-iolaus.combo-active {
  animation: pulseTorchBtn 0.45s infinite alternate;
  border-color: #fef08a;
  box-shadow: 0 0 20px rgba(234, 88, 12, 0.8), 0 5px 0 rgba(0, 0, 0, 0.15);
}

@keyframes pulseTorchBtn {
  from { filter: brightness(1); transform: scale(1); }
  to { filter: brightness(1.25); transform: scale(1.04); }
}

/* =========================================
   MODALS (Victory, Party, Story)
========================================= */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: #ffffff;
  border: 4px solid #fde047;
  border-radius: 28px;
  padding: 26px 20px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  animation: popCard 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popCard {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-icon {
  font-size: 3.8rem;
  margin-bottom: 6px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: #0284c7;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.95rem;
  line-height: 1.55;
  color: #475569;
  margin-bottom: 16px;
  font-weight: 600;
}

.modal-stats {
  font-size: 0.88rem;
  color: #334155;
  margin-bottom: 18px;
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  padding: 10px;
  border-radius: 14px;
  line-height: 1.6;
}

.modal-restart-btn, .modal-close-btn {
  width: 100%;
  padding: 13px;
  border-radius: 16px;
  border: none;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
  transition: transform 0.1s, filter 0.15s;
}

.modal-restart-btn:active, .modal-close-btn:active {
  transform: scale(0.97);
  filter: brightness(1.15);
}

/* Rules for kids */
.rules-list {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #334155;
}

.r-badge {
  background: #fde047;
  color: #854d0e;
  font-weight: 900;
  font-size: 0.82rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.rule-item.highlight {
  background: #fff7ed;
  padding: 7px 10px;
  border-radius: 10px;
  border-left: 3px solid #f97316;
}

.rule-item.warning {
  background: #f0fdf4;
  padding: 7px 10px;
  border-radius: 10px;
  border-left: 3px solid #22c55e;
}

.rule-item.warning .r-badge {
  background: #86efac;
  color: #14532d;
}

/* Mobile full-screen */
@media (max-width: 480px) {
  body {
    background: #bae6fd;
  }

  .game-wrapper {
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    box-shadow: none;
    border-radius: 0;
    border: none;
  }

  .controls-footer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    height: calc(98px + env(safe-area-inset-bottom, 0px));
  }
}
