/* === Battle Layout === */
.battle-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  gap: 8px;
}

.battle-field {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 0;
  position: relative;
}

.battle-opponent,
.battle-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  max-width: 200px;
}

.battle-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.battle-name {
  font-family: var(--font-display);
  font-size: 1rem;
}

.battle-level {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.hp-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

.monster-slot {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.monster-slot .monster {
  transform: scale(1.33);
}

.opponent-slot {
  transition: all 0.3s ease;
}

.boss-slot {
  width: 140px !important;
  height: 140px !important;
}

.boss-monster {
  transform: scale(2.13);
  transform-origin: center bottom;
  filter: drop-shadow(0 0 12px rgba(255, 50, 50, 0.4));
}

.battle-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 1.2rem;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  z-index: 10;
}

.battle-message.visible {
  opacity: 1;
}

/* === World Themes === */
.battle-field--earth {
  background: linear-gradient(180deg, #1a3a12 0%, #2d4a22 40%, #3b2a15 100%);
  border-radius: 12px;
  overflow: hidden;
}

.battle-field--water {
  background: linear-gradient(180deg, #012a4a 0%, #013a6b 40%, #01497c 100%);
  border-radius: 12px;
  overflow: hidden;
}

.battle-field--cloud {
  background: linear-gradient(180deg, #2a2a6e 0%, #3a3d98 40%, #5c5fb8 100%);
  border-radius: 12px;
  overflow: hidden;
}

.battle-field--sand {
  background: linear-gradient(180deg, #3d2b10 0%, #5c3d1a 40%, #7a5a30 100%);
  border-radius: 12px;
  overflow: hidden;
}

.battle-field--fire {
  background: linear-gradient(180deg, #1a0505 0%, #4a0e0e 40%, #6b1010 100%);
  border-radius: 12px;
  overflow: hidden;
}

/* Decoration container */
.world-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.battle-player, .battle-opponent {
  z-index: 1;
}

/* --- Earth: Trees --- */
.world-decor--earth::before,
.world-decor--earth::after {
  content: '';
  position: absolute;
  bottom: 0;
}

.world-decor--earth::before {
  left: 5px;
  width: 18px;
  height: 60px;
  background: linear-gradient(180deg, #2d5a1e 0%, #3b7a28 30%, #5a3420 30%, #5a3420 100%);
  border-radius: 8px 8px 2px 2px;
}

.world-decor--earth::after {
  right: 8px;
  width: 14px;
  height: 50px;
  background: linear-gradient(180deg, #3a7a2e 0%, #4a8a38 35%, #5a3420 35%, #5a3420 100%);
  border-radius: 6px 6px 2px 2px;
}

/* Extra trees via box-shadow */
.world-decor--earth {
  /* Ground line */
  border-bottom: 4px solid #2a1a08;
}

/* --- Water: Bubbles --- */
.world-decor--water::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(100, 200, 255, 0.2);
  border: 1px solid rgba(100, 200, 255, 0.3);
  bottom: 20px;
  left: 15%;
  animation: bubble-rise 4s ease-in infinite;
}

.world-decor--water::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(100, 200, 255, 0.15);
  border: 1px solid rgba(100, 200, 255, 0.25);
  bottom: 10px;
  right: 20%;
  animation: bubble-rise 5s ease-in 1.5s infinite;
}

.world-decor--water {
  box-shadow:
    inset 25px -30px 0 -26px rgba(100, 200, 255, 0.15),
    inset -30px -50px 0 -26px rgba(100, 200, 255, 0.1),
    inset 60px -15px 0 -26px rgba(100, 200, 255, 0.12);
}

@keyframes bubble-rise {
  0% { transform: translateY(0) scale(1); opacity: 0.6; }
  50% { opacity: 0.8; }
  100% { transform: translateY(-120px) scale(0.4); opacity: 0; }
}

/* --- Cloud: Floating clouds --- */
.world-decor--cloud::before {
  content: '';
  position: absolute;
  width: 60px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  top: 15px;
  left: -20px;
  animation: cloud-drift 8s linear infinite;
}

.world-decor--cloud::after {
  content: '';
  position: absolute;
  width: 45px;
  height: 15px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 15px;
  top: 55px;
  left: -15px;
  animation: cloud-drift 12s linear 3s infinite;
}

@keyframes cloud-drift {
  0% { transform: translateX(-80px); }
  100% { transform: translateX(500px); }
}

/* --- Sand: Cactus & sand --- */
.world-decor--sand::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10px;
  width: 8px;
  height: 40px;
  background: #3a6b30;
  border-radius: 4px 4px 0 0;
  box-shadow:
    -10px 0 0 -3px #3a6b30,
    10px -12px 0 -3px #3a6b30;
}

.world-decor--sand::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 12px;
  width: 6px;
  height: 30px;
  background: #4a8040;
  border-radius: 3px 3px 0 0;
  box-shadow:
    8px -8px 0 -2px #4a8040;
}

.world-decor--sand {
  border-bottom: 4px solid #c4943a;
  background: linear-gradient(0deg, rgba(196, 148, 58, 0.15) 0%, transparent 30%);
}

/* Drifting sand particles */
@keyframes sand-drift {
  0% { transform: translateX(0) translateY(0); opacity: 0; }
  20% { opacity: 0.4; }
  100% { transform: translateX(80px) translateY(-20px); opacity: 0; }
}

/* --- Fire: Smoke & embers --- */
.world-decor--fire::before {
  content: '';
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(100, 100, 100, 0.2);
  bottom: 30px;
  left: 10%;
  animation: smoke-rise 5s ease-out infinite;
  filter: blur(6px);
}

.world-decor--fire::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(80, 80, 80, 0.15);
  bottom: 20px;
  right: 12%;
  animation: smoke-rise 7s ease-out 2s infinite;
  filter: blur(5px);
}

.world-decor--fire {
  box-shadow:
    inset 0 -8px 20px -8px rgba(255, 100, 0, 0.3),
    inset 0 -2px 8px -2px rgba(255, 50, 0, 0.2);
}

@keyframes smoke-rise {
  0% { transform: translateY(0) scale(1); opacity: 0.4; }
  50% { opacity: 0.2; }
  100% { transform: translateY(-100px) scale(2); opacity: 0; }
}

/* --- Primeval: Jungle --- */
.battle-field--primeval {
  background: linear-gradient(180deg, #0a1a08 0%, #152e10 30%, #1e3b16 60%, #2a1a08 100%);
  border-radius: 12px;
  overflow: hidden;
}

.world-decor--primeval {
  /* Misty jungle floor */
  border-bottom: 5px solid #1a1206;
  background:
    /* Ground fog */
    linear-gradient(0deg, rgba(100, 180, 80, 0.08) 0%, transparent 20%),
    /* Canopy shadow from top */
    linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0%, transparent 25%);
}

/* Left jungle tree — tall trunk with bushy canopy */
.world-decor--primeval::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 4px;
  width: 14px;
  height: 100%;
  background:
    /* Canopy leaves (top blob) */
    radial-gradient(ellipse 32px 40px at 7px 12px, #1a5c10 0%, #1a5c10 55%, transparent 56%),
    radial-gradient(ellipse 24px 28px at 20px 22px, #237a16 0%, #237a16 55%, transparent 56%),
    radial-gradient(ellipse 28px 32px at -4px 26px, #1e6e12 0%, #1e6e12 55%, transparent 56%),
    /* Hanging vines */
    linear-gradient(180deg, transparent 10%, #2a8a1e 10%, #2a8a1e 11%, transparent 11%,
      transparent 24%, #1e7a14 24%, #1e7a14 25%, transparent 25%),
    /* Trunk */
    linear-gradient(90deg, #3a2410 0%, #5a3820 40%, #4a2e18 100%);
  border-radius: 4px 4px 0 0;
}

/* Right jungle tree — different shape */
.world-decor--primeval::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 6px;
  width: 12px;
  height: 90%;
  background:
    /* Canopy */
    radial-gradient(ellipse 26px 34px at 6px 8px, #1e6e12 0%, #1e6e12 55%, transparent 56%),
    radial-gradient(ellipse 22px 26px at 16px 16px, #2a8a1e 0%, #2a8a1e 55%, transparent 56%),
    /* Ferns hanging */
    linear-gradient(180deg, transparent 14%, #237a16 14%, #237a16 15%, transparent 15%,
      transparent 30%, #2a8a1e 30%, #2a8a1e 31%, transparent 31%),
    /* Trunk */
    linear-gradient(90deg, #4a2e18 0%, #5a3820 50%, #3a2410 100%);
  border-radius: 4px 4px 0 0;
}

/* Fireflies / spores floating in the jungle */
@keyframes jungle-firefly {
  0% { transform: translate(0, 0); opacity: 0; }
  20% { opacity: 0.8; }
  50% { opacity: 0.4; }
  80% { opacity: 0.7; }
  100% { transform: translate(30px, -40px); opacity: 0; }
}

@keyframes jungle-firefly2 {
  0% { transform: translate(0, 0); opacity: 0; }
  30% { opacity: 0.6; }
  60% { opacity: 0.9; }
  100% { transform: translate(-20px, -50px); opacity: 0; }
}

/* Fireflies via box-shadows on the field */
.battle-field--primeval {
  position: relative;
}

.battle-field--primeval::before {
  content: '';
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #a0ff60;
  box-shadow: 0 0 6px 2px rgba(160, 255, 96, 0.6);
  bottom: 30%;
  left: 25%;
  animation: jungle-firefly 5s ease-in-out infinite;
  z-index: 0;
}

.battle-field--primeval::after {
  content: '';
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #c0ff80;
  box-shadow: 0 0 5px 2px rgba(192, 255, 128, 0.5);
  bottom: 50%;
  right: 30%;
  animation: jungle-firefly2 6.5s ease-in-out 2s infinite;
  z-index: 0;
}

/* --- Dragon's Peak: misty mountain summit --- */
.battle-field--dragon {
  position: relative;
  background: linear-gradient(180deg, #1a2540 0%, #2a3a5c 25%, #3a5078 50%, #1a3520 80%, #0a2010 100%);
  border-radius: 12px;
  overflow: hidden;
}

.world-decor--dragon {
  border-bottom: 5px solid #0a1a10;
  background:
    /* Ground mist */
    linear-gradient(0deg, rgba(200, 220, 255, 0.12) 0%, transparent 25%),
    /* Sky haze */
    linear-gradient(180deg, rgba(220, 230, 255, 0.15) 0%, transparent 22%);
}

/* Left jagged peak */
.world-decor--dragon::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 38%;
  height: 100%;
  background:
    linear-gradient(135deg, transparent 0%, transparent 55%, #3a5068 55%, #2a3a4e 72%, #1a2638 100%);
  clip-path: polygon(0 100%, 0 45%, 12% 28%, 28% 38%, 42% 20%, 58% 34%, 72% 22%, 100% 40%, 100% 100%);
}

/* Right jagged peak — taller, with gold glint */
.world-decor--dragon::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 42%;
  height: 100%;
  background:
    radial-gradient(circle 4px at 70% 42%, #ffd166 0%, #ffd166 45%, transparent 46%),
    radial-gradient(circle 3px at 55% 56%, #ffd166 0%, #ffd166 45%, transparent 46%),
    linear-gradient(225deg, transparent 0%, transparent 55%, #3a5068 55%, #2a3a4e 72%, #1a2638 100%);
  clip-path: polygon(100% 100%, 100% 35%, 85% 18%, 68% 30%, 52% 14%, 36% 28%, 22% 16%, 0 38%, 0 100%);
}

/* Floating embers / dragon sparks */
@keyframes dragon-ember {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  20% { opacity: 0.9; }
  60% { opacity: 0.7; }
  100% { transform: translate(-20px, -90px) scale(0.4); opacity: 0; }
}

@keyframes dragon-ember2 {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  30% { opacity: 0.8; }
  70% { opacity: 0.5; }
  100% { transform: translate(25px, -70px) scale(0.5); opacity: 0; }
}

.battle-field--dragon::before {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffb347;
  box-shadow: 0 0 8px 3px rgba(255, 150, 50, 0.7);
  bottom: 20%;
  left: 30%;
  animation: dragon-ember 4.5s ease-in-out infinite;
  z-index: 0;
}

.battle-field--dragon::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffd166;
  box-shadow: 0 0 7px 2px rgba(255, 200, 80, 0.6);
  bottom: 40%;
  right: 28%;
  animation: dragon-ember2 5.5s ease-in-out 1.5s infinite;
  z-index: 0;
}

/* === Quiz Panel === */
.battle-actions {
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-panel {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 16px;
}

.quiz-question {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 12px;
  text-align: center;
}

.quiz-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quiz-answer {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px;
  border: 2px solid var(--bg-card);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  text-align: center;
}

.quiz-answer:hover {
  border-color: var(--accent);
}

.quiz-answer.correct {
  border-color: #4caf50;
  background: rgba(76, 175, 80, 0.2);
}

.quiz-answer.wrong {
  border-color: #f44336;
  background: rgba(244, 67, 54, 0.2);
}

.quiz-answer:disabled {
  cursor: default;
}

/* === Battle Items === */
.battle-items {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ==========================================================================
   ADVENTURE BATTLE (#screen-battle only)
   Pokemon-style field: enemy top-right with its nameplate top-left,
   your monster bottom-left with its nameplate bottom-right.
   PvP/team screens reuse the generic classes above, so everything here is scoped.
   ========================================================================== */
#screen-battle {
  justify-content: flex-start;
  padding: 10px 12px 12px;
}

#screen-battle .battle-container {
  max-width: 760px;
  margin: 0 auto;
  gap: 8px;
  min-height: 0;
}

#screen-battle .battle-stage {
  flex: none;
  min-height: 40px;
  display: flex;
  align-items: center;
  padding-right: 104px; /* room for the fixed ? and music buttons */
  font-family: var(--font-display);
  font-size: .9rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#screen-battle .battle-field {
  flex: 1 1 auto;
  display: block;
  min-height: 210px;
  padding: 0;
  border-radius: 20px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .08);
  box-shadow: inset 0 -40px 60px -30px rgba(0, 0, 0, .45);
  background-color: #1f2d44;
}

/* Soft rolling ground the two monsters stand on. */
#screen-battle .battle-ground {
  position: absolute;
  left: -15%;
  right: -15%;
  bottom: -32%;
  height: 70%;
  border-radius: 50% 50% 0 0;
  background: var(--ground, rgba(255, 255, 255, .06));
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}
#screen-battle .battle-field--earth { --ground: linear-gradient(180deg, #4d7a33, #2f4a1f); }
#screen-battle .battle-field--water { --ground: linear-gradient(180deg, #1f7fae, #0d4466); }
#screen-battle .battle-field--cloud { --ground: linear-gradient(180deg, #d6dcff, #8e95d9); }
#screen-battle .battle-field--sand { --ground: linear-gradient(180deg, #d9a55a, #8a5f2a); }
#screen-battle .battle-field--fire { --ground: linear-gradient(180deg, #8a2a14, #3d0c06); }
#screen-battle .battle-field--primeval { --ground: linear-gradient(180deg, #3f6b25, #1e3812); }
#screen-battle .battle-field--dragon { --ground: linear-gradient(180deg, #3d6b4f, #173524); }
#screen-battle .battle-field--crystal {
  --ground: linear-gradient(180deg, #5ad1e6, #1d4f6e);
  background: radial-gradient(circle at 20% 20%, rgba(90, 209, 230, .25), transparent 40%), linear-gradient(180deg, #16324f 0%, #10243c 60%, #0a1a2e 100%);
}

#screen-battle .battle-opponent,
#screen-battle .battle-player {
  position: absolute;
  left: 0;
  right: 0;
  display: block;
  max-width: none;
  height: 50%;
  z-index: 2;
}
#screen-battle .battle-opponent { top: 0; }
#screen-battle .battle-player { bottom: 0; }

#screen-battle .battle-nameplate {
  position: absolute;
  width: min(52%, 240px);
  padding: 8px 12px 6px;
  border-radius: 14px;
  background: rgba(10, 16, 28, .82);
  border: 2px solid rgba(255, 255, 255, .14);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .3);
  z-index: 3;
}
#screen-battle .battle-opponent .battle-nameplate { top: 10px; left: 10px; }
#screen-battle .battle-player .battle-nameplate { right: 10px; bottom: 10px; border-color: rgba(202, 238, 147, .55); }
#screen-battle .battle-opponent.is-boss .battle-nameplate { border-color: #ffd166; }

#screen-battle .battle-info {
  justify-content: space-between;
  gap: 6px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}
#screen-battle .battle-name {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#screen-battle .battle-level {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  color: #e7eef4;
  font-weight: 800;
  font-size: .72rem;
}
#screen-battle .is-boss .battle-level { background: #ffd166; color: #3a2500; }
#screen-battle .hp-bar {
  height: 10px;
  margin: 5px 0 2px;
  background: rgba(0, 0, 0, .5);
  border: 1px solid rgba(255, 255, 255, .12);
}
#screen-battle .hp-text {
  display: block;
  text-align: right;
  font-weight: 800;
  font-size: .72rem;
  color: #d5deea;
}

/* Sprites */
#screen-battle .monster-slot {
  position: absolute;
  width: 60px;
  height: 60px;
  transition: none;
}
#screen-battle .opponent-slot { right: 16%; bottom: 6%; }
#screen-battle .player-slot { left: 20%; bottom: 26%; }
#screen-battle .boss-slot { width: 60px !important; height: 60px !important; }
#screen-battle .monster-slot .monster {
  transform-origin: 50% 100%;
  scale: 1.8;
}
#screen-battle .player-slot .monster { scale: 2.2; }
#screen-battle .opponent-slot .boss-monster { scale: 2.3; }
/* Shadow "platforms" under each monster */
#screen-battle .monster-slot::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 150px;
  height: 30px;
  margin-left: -75px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, .45), rgba(0, 0, 0, .15) 60%, transparent 72%);
  z-index: -1;
}
#screen-battle .player-slot::before { width: 170px; margin-left: -85px; }

#screen-battle .damage-number,
#screen-battle .miss-text {
  margin-left: -1.2rem;
  top: -30px !important;
  font-size: 2rem;
  -webkit-text-stroke: 1px rgba(0, 0, 0, .5);
  text-shadow: 0 3px 0 rgba(0, 0, 0, .45);
  white-space: nowrap;
  color: #ffe066;
}
#screen-battle .damage-number.heal { color: #7dff9c; }
#screen-battle .miss-text { color: #e0e6ee; font-size: 1.5rem; }

.hit-burst {
  position: absolute;
  left: 50%;
  top: 40%;
  z-index: 15;
  font-size: 2.6rem;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: hit-burst .45s ease-out forwards;
}
@keyframes hit-burst {
  from { opacity: 1; transform: translate(-50%, -50%) scale(.3); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
}
.field-shake { animation: field-shake .35s ease; }
@keyframes field-shake {
  25% { translate: -5px 2px; }
  50% { translate: 5px -2px; }
  75% { translate: -3px 1px; }
}

/* Center-of-field announcer ("Enemy missed!", "Wrong answer...") */
#screen-battle .battle-message {
  top: 50%;
  width: max-content;
  max-width: 88%;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(10, 16, 28, .9);
  border: 3px solid rgba(255, 255, 255, .25);
  font-size: 1.15rem;
  line-height: 1.25;
  color: #fff;
  transform: translate(-50%, -50%) scale(.8);
  transition: opacity .2s ease, transform .2s cubic-bezier(.2, 1.4, .4, 1);
}
#screen-battle .battle-message.visible { transform: translate(-50%, -50%) scale(1); }
#screen-battle .battle-message[data-tone="good"] { border-color: var(--good); }
#screen-battle .battle-message[data-tone="bad"] { border-color: var(--bad); }
#screen-battle .battle-message[data-tone="info"] { border-color: var(--brand); }

/* Turn banner */
.battle-turn {
  flex: none;
  padding: 10px 14px;
  border-radius: 14px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.1rem;
  line-height: 1.25;
  color: #fff;
  background: var(--surface-2);
  border: 2px solid var(--border);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .3);
  transition: background .2s ease, color .2s ease;
}
.battle-turn[data-mode="you"] { background: var(--brand); border-color: #e6ffc0; color: var(--brand-ink); animation: turn-pulse 1.6s ease-in-out infinite; }
.battle-turn[data-mode="good"] { background: #1f7a55; border-color: var(--good); }
.battle-turn[data-mode="bad"] { background: #7a2632; border-color: var(--bad); }
.battle-turn[data-mode="enemy"] { background: #3a2a44; border-color: #a86ad8; color: #f3dcff; }
@keyframes turn-pulse { 50% { box-shadow: 0 4px 0 rgba(0, 0, 0, .3), 0 0 0 5px rgba(202, 238, 147, .25); } }

/* Question + answers */
#screen-battle .battle-actions {
  flex: none;
  min-height: 0;
  gap: 8px;
}
#screen-battle .quiz-panel {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  transition: opacity .2s ease;
}
#screen-battle .quiz-question {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 12px;
  color: #fff;
  overflow-wrap: anywhere;
}
#screen-battle .quiz-answers { gap: 10px; }
#screen-battle .dragon-skills { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; margin-bottom: 10px; }
#screen-battle .dragon-skills p { flex-basis: 100%; margin: 0; font-size: .8rem; font-weight: 700; color: #bfefff; }
#screen-battle .dragon-skills .btn { flex: 1 1 auto; min-width: 0; margin: 0; padding: 7px 10px; font-size: .82rem; background: #22335a; color: #fff; box-shadow: 0 3px 0 rgba(0, 0, 0, .35); }
#screen-battle .dragon-skills .btn[aria-pressed="true"] { background: #1c86b3; }
#screen-battle .player-slot .monster-rexstorm,
#screen-battle .player-slot .monster-demon-dragon,
#screen-battle .player-slot .monster-viridrax { scale: 1.5; }

/* Rule reminder + potion */
#screen-battle .battle-items {
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.battle-rule {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-secondary);
}
.battle-turn-row { flex: none; display: flex; gap: 8px; align-items: stretch; }
.battle-turn-row .battle-turn { flex: 1; min-width: 0; }
#screen-battle #btn-use-potion {
  flex: none;
  min-width: 0;
  background: linear-gradient(135deg, #b565f0, #7b3fd1);
  font-size: 1rem;
  padding: 8px 14px;
  white-space: nowrap;
}
#screen-battle #btn-use-potion:disabled { background: var(--surface-2); color: var(--text-secondary); }
#screen-battle #btn-use-potion.potion-urgent { animation: potion-pulse 1s ease-in-out infinite; }
@keyframes potion-pulse { 50% { box-shadow: 0 5px 0 rgba(0, 0, 0, .35), 0 0 0 6px rgba(181, 101, 240, .45); } }

@media (min-width: 900px) {
  #screen-battle .battle-field { min-height: 300px; }
  #screen-battle .monster-slot .monster { scale: 2; }
  #screen-battle .player-slot .monster { scale: 2.4; }
  #screen-battle .opponent-slot .boss-monster { scale: 2.7; }
  #screen-battle .quiz-question { font-size: 1.5rem; }
}
@media (max-width: 480px) {
  .battle-turn { font-size: 1rem; padding: 10px 8px; }
  #screen-battle #btn-use-potion { font-size: .9rem; padding: 8px 10px; }
}
@media (max-height: 700px) {
  #screen-battle .battle-stage { min-height: 32px; }
  #screen-battle .quiz-question { font-size: 1.15rem; margin-bottom: 8px; }
}

/* ==========================================================================
   ADVENTURE WORLD MAP (#screen-battle-select)
   ========================================================================== */
#screen-battle-select { justify-content: flex-start; padding: 10px 14px 14px; }
#screen-battle-select .battle-select-container { max-width: 640px; margin: 0 auto; gap: 8px; }
.adv-header { width: 100%; text-align: center; position: relative; }
.adv-header h2 { font-size: 1.7rem; margin: 4px 96px 0; min-height: 40px; display: flex; align-items: center; justify-content: center; }
.adv-subtitle { color: var(--text-secondary); font-weight: 700; font-size: .92rem; }
.adv-header .adv-home { position: absolute; left: 0; top: 2px; margin: 0; padding: 8px 4px; font-weight: 800; }
.adv-header .adv-home:hover, .adv-back:hover { color: var(--brand); }
#screen-battle-select .battle-select-content { padding: 4px 2px 20px; gap: 12px; }

.adv-back { align-self: flex-start; margin: 0; padding: 4px 2px; font-weight: 800; }
.adv-eyebrow { font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); }
.adv-section-label { font-size: 1.05rem; margin: 6px 2px -2px; color: #e7eef4; }
.adv-section-label small { font-family: var(--font-body); font-size: .75rem; color: var(--text-secondary); margin-left: 6px; }

/* Partner card */
.adv-partner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, #2c4a3c, #213244);
  border: 2px solid rgba(202, 238, 147, .45);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .3);
}
.adv-partner-sprite { flex: none; width: 76px; height: 76px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle at 50% 70%, rgba(202, 238, 147, .25), transparent 70%); }
.adv-partner-sprite .monster { scale: 1.05; }
.adv-partner-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.adv-partner-name { font-family: var(--font-display); font-size: 1.2rem; font-weight: 400; }
.adv-partner-name small { font-family: var(--font-body); font-weight: 800; font-size: .8rem; color: var(--text-secondary); }
.adv-partner-stats { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .82rem; font-weight: 800; color: #dfe7ef; }
.adv-xp { display: block; height: 7px; border-radius: 99px; background: rgba(0, 0, 0, .35); overflow: hidden; }
.adv-xp span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.adv-link {
  flex: none;
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 12px;
  border: 2px solid rgba(202, 238, 147, .6);
  background: transparent;
  color: var(--brand);
  font: 800 .85rem var(--font-body);
  cursor: pointer;
}
.adv-link:hover { background: rgba(202, 238, 147, .12); }

/* Empty state */
.adv-empty {
  margin-top: 24px;
  padding: 28px 22px;
  border-radius: 22px;
  background: var(--surface);
  border: 2px dashed var(--border);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.adv-empty-egg { font-size: 4rem; animation: adv-wobble 2.4s ease-in-out infinite; }
.adv-empty h3 { font-size: 1.5rem; }
.adv-empty p { color: var(--text-secondary); line-height: 1.5; max-width: 320px; }
.adv-empty-btn { margin-top: 6px; font-size: 1.1rem; min-width: 220px; }
@keyframes adv-wobble { 0%, 60%, 100% { rotate: 0deg; } 70% { rotate: -10deg; } 80% { rotate: 10deg; } 90% { rotate: -5deg; } }

/* World path */
.adv-path { position: relative; display: flex; flex-direction: column; gap: 12px; }
.adv-path:not(.adv-path-events)::before {
  content: '';
  position: absolute;
  left: 40px;
  top: 30px;
  bottom: 30px;
  border-left: 4px dotted rgba(255, 255, 255, .18);
  z-index: 0;
}
.adv-world {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 18px;
  border: 2px solid color-mix(in srgb, var(--world) 70%, transparent);
  background: var(--world-bg);
  color: #fff;
  text-align: left;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .35);
  transition: transform .12s ease, box-shadow .12s ease;
}
.adv-world:not(.locked):hover { transform: translateY(-2px); box-shadow: 0 7px 0 rgba(0, 0, 0, .35); }
.adv-world:not(.locked):active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.adv-world.current { border-color: var(--brand); box-shadow: 0 5px 0 rgba(0, 0, 0, .35), 0 0 0 4px rgba(202, 238, 147, .25); }
.adv-world.locked { background: var(--surface); border-color: var(--border); border-style: dashed; cursor: not-allowed; box-shadow: none; }
.adv-world-icon {
  flex: none;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  font-size: 1.9rem;
  border-radius: 16px;
  background: rgba(0, 0, 0, .28);
  border: 2px solid color-mix(in srgb, var(--world) 60%, transparent);
}
.adv-world.locked .adv-world-icon { font-size: 1.4rem; border-color: var(--border); background: var(--surface-2); }
.adv-world-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.adv-world-name { font-family: var(--font-display); font-size: 1.15rem; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.adv-world.locked .adv-world-name { color: var(--text-secondary); }
.adv-world-next, .adv-world-done, .adv-world-lock { font-size: .82rem; font-weight: 700; color: #e7eef4; }
.adv-world-done { color: var(--good); }
.adv-world-lock { color: var(--text-secondary); line-height: 1.35; }
.adv-world-go {
  flex: none;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .3);
  font-family: var(--font-display);
  font-size: .95rem;
}
.adv-world.current .adv-world-go { background: var(--brand); color: var(--brand-ink); animation: adv-bounce 1.4s ease-in-out infinite; }
@keyframes adv-bounce { 50% { transform: translateY(-3px); } }
.adv-stars { display: flex; gap: 2px; font-size: .95rem; line-height: 1; }
.adv-star { color: rgba(255, 255, 255, .22); }
.adv-star.on { color: #ffd166; text-shadow: 0 0 6px rgba(255, 209, 102, .6); }
.adv-world.locked .adv-stars { display: none; }

/* Level list */
.adv-world-banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 20px;
  border: 2px solid var(--world);
  overflow: hidden;
}
.adv-world-banner > span:last-child { display: flex; flex-direction: column; gap: 4px; position: relative; z-index: 1; }
.adv-world-banner strong { font-family: var(--font-display); font-weight: 400; font-size: 1.4rem; color: #fff; }
.adv-world-banner small { font-size: .85rem; color: #e1e8f0; line-height: 1.4; }
.adv-banner-icon { font-size: 2.6rem; position: relative; z-index: 1; }
.adv-levels { list-style: none; display: flex; flex-direction: column; gap: 10px; position: relative; }
.adv-levels::before { content: ''; position: absolute; left: 33px; top: 24px; bottom: 24px; border-left: 4px dotted rgba(255, 255, 255, .15); }
.adv-level {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .3);
  transition: transform .12s ease;
}
.adv-level:not(.locked):hover { transform: translateY(-2px); }
.adv-level:not(.locked):active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.adv-level.current { border-color: var(--brand); background: linear-gradient(135deg, #2c4a3c, var(--surface)); }
.adv-level.cleared { background: var(--surface-2); }
.adv-level.locked { cursor: not-allowed; box-shadow: none; border-style: dashed; }
.adv-level.boss { border-color: #ffd166; background: linear-gradient(135deg, #4a3a18, var(--surface)); }
.adv-level.boss.locked { border-color: rgba(255, 209, 102, .4); }
.adv-level-num {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--world);
  color: #10202a;
  font-family: var(--font-display);
  font-size: 1.2rem;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25);
}
.adv-level.locked .adv-level-num { background: var(--surface-2); color: var(--text-secondary); }
.adv-level.boss .adv-level-num { background: #ffd166; font-size: 1.3rem; }
.adv-level-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.adv-level-name { font-family: var(--font-display); font-size: 1.05rem; }
.adv-level-sub { display: flex; flex-wrap: wrap; gap: 4px; font-size: .78rem; font-weight: 700; color: var(--text-secondary); }
.adv-chip { padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, .08); color: #e7eef4; }
.adv-chip-foe { background: rgba(255, 93, 108, .18); color: #ffc2c8; }
.adv-level-action { flex: none; font-family: var(--font-display); font-size: .95rem; padding: 8px 12px; border-radius: 12px; }
.adv-level-action.go { background: var(--brand); color: var(--brand-ink); box-shadow: 0 3px 0 rgba(0, 0, 0, .3); }
.adv-level.boss .adv-level-action.go { background: #ffd166; color: #3a2500; }
.adv-level-action.done { background: rgba(54, 211, 153, .18); color: var(--good); font-size: 1.1rem; }

/* Topic picker */
.adv-topic-head { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.adv-topic-head h3 { font-size: 1.5rem; }
.adv-topic-head p { color: var(--text-secondary); font-weight: 700; }
.adv-topic-rule { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; }
.adv-topic-rule span { padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: #e7eef4; font-size: .82rem; }
.adv-topics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.adv-topic {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 150px;
  justify-content: center;
  padding: 18px 12px;
  border-radius: 20px;
  border: 3px solid var(--topic);
  background: linear-gradient(160deg, color-mix(in srgb, var(--topic) 30%, var(--surface)), var(--surface));
  color: #fff;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35);
  transition: transform .12s ease, box-shadow .12s ease;
}
.adv-topic:hover { transform: translateY(-3px); box-shadow: 0 9px 0 rgba(0, 0, 0, .35); }
.adv-topic:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.adv-topic-icon { font-size: 3rem; }
.adv-topic-name { font-family: var(--font-display); font-size: 1.4rem; color: var(--topic); text-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.adv-topic-blurb { font-size: .82rem; font-weight: 700; color: #dfe7ef; text-align: center; }
.adv-topic-last { position: absolute; top: 8px; right: 8px; padding: 2px 8px; border-radius: 99px; background: var(--brand); color: var(--brand-ink); font-size: .7rem; font-weight: 800; }
@media (max-width: 519px) {
  .adv-topics { grid-template-columns: 1fr; }
  .adv-topic { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 16px; min-height: 0; padding: 16px 18px; text-align: left; }
  .adv-topic-icon { grid-row: span 2; font-size: 2.8rem; }
  .adv-topic-name, .adv-topic-blurb { text-align: left; }
  .adv-topic-name { align-self: end; }
  .adv-topic-blurb { align-self: start; }
}

/* ==========================================================================
   BATTLE RESULT (#screen-result)
   ========================================================================== */
#screen-result { overflow-y: auto; justify-content: flex-start; padding: 24px 16px; }
#screen-result .result-container {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: auto;
  gap: 12px;
  padding: 26px 18px 20px;
  border-radius: 26px;
  background: linear-gradient(170deg, #26394f, #1a2638);
  border: 3px solid var(--border);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .3), 0 24px 60px rgba(0, 0, 0, .4);
  overflow: hidden;
  animation: result-pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
#screen-result .result--win { border-color: #ffd166; background: linear-gradient(170deg, #3a3a1f, #1f3a33 55%, #1a2638); }
#screen-result .result--lose { border-color: #5a6b86; background: linear-gradient(170deg, #2a3350, #1a2638); }
#screen-result .result-container > * { position: relative; z-index: 1; }
#screen-result .result-container > .result-burst {
  position: absolute;
  z-index: 0;
  top: -130px;
  left: 50%;
  width: 440px;
  height: 440px;
  margin-left: -220px;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 209, 102, .16) 0deg 10deg, transparent 10deg 24deg);
  mask-image: radial-gradient(circle, #000 25%, transparent 68%);
  -webkit-mask-image: radial-gradient(circle, #000 25%, transparent 68%);
  animation: result-spin 18s linear infinite;
  display: none;
}
#screen-result .result--win > .result-burst { display: block; }
.result-kicker { font-weight: 800; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: #ffd166; }
.result--lose .result-kicker { color: #a9b8d0; }
#screen-result .result-container h2 {
  font-size: 2.6rem;
  line-height: 1.05;
  color: #ffe08a;
  text-shadow: 0 4px 0 #8a5a00, 0 8px 18px rgba(0, 0, 0, .4);
}
#screen-result .result--lose h2 { color: #c9d5e6; text-shadow: 0 4px 0 #34425c; }
#screen-result .result--boss h2 { font-size: 2.1rem; }
.result-sub { color: #e1e8f0; font-weight: 700; line-height: 1.4; }
.result-hero { width: 120px; height: 110px; display: grid; place-items: end center; padding-bottom: 8px; }
.result-hero .monster { scale: 1.7; transform-origin: 50% 100%; }
.result--win .result-hero .monster { animation: result-hop .9s ease-in-out infinite; }
.result--lose .result-hero .monster { filter: saturate(.5) brightness(.85); animation: none; }
#screen-result .result-details { width: 100%; min-width: 0; padding: 0; gap: 10px; background: none; }
.result-chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.result-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 10px 6px;
  border-radius: 16px;
  background: rgba(0, 0, 0, .28);
  border: 2px solid rgba(255, 255, 255, .12);
  animation: result-pop .4s cubic-bezier(.2, 1.4, .4, 1) both;
}
.result-chip:nth-child(2) { animation-delay: .1s; }
.result-chip:nth-child(3) { animation-delay: .2s; }
.result-chip > span { font-size: 1.5rem; }
.result-chip strong { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; color: #fff; }
.result-chip small { font-size: .72rem; font-weight: 800; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.result-chip.result-gems { border-color: rgba(90, 209, 230, .5); }
.result-chip.result-gems strong { color: #8ae8f7; }
.result-xpbar { display: flex; flex-direction: column; gap: 5px; text-align: left; }
.result-xpbar-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .85rem; }
.result-xpbar-label small { color: var(--text-secondary); font-weight: 700; }
.result-xpbar-track { display: block; height: 10px; border-radius: 99px; background: rgba(0, 0, 0, .35); overflow: hidden; }
.result-xpbar-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #9be15d, var(--brand)); transition: width .8s ease; }
#screen-result .result-levelup { color: inherit; font-family: var(--font-body); }
#result-levelup-text { display: flex; flex-direction: column; gap: 6px; }
.result-callout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(202, 238, 147, .12);
  border: 2px solid rgba(202, 238, 147, .5);
  font-weight: 800;
  text-align: left;
  color: #f1ffd9;
  animation: result-pop .4s .3s cubic-bezier(.2, 1.4, .4, 1) both;
}
.result-callout > span { font-size: 1.3rem; }
.result-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 4px; }
.result-actions .btn { width: 100%; min-width: 0; font-size: 1.1rem; }
.result-actions .result-main { font-family: var(--font-display); font-size: 1.25rem; font-weight: 400; }
.result-actions .result-worlds:not(.room-primary) { background: var(--surface-2); border: 2px solid var(--border); }
.result-actions .result-worlds.room-primary { font-family: var(--font-display); font-weight: 400; }
.result-actions .result-home { margin: 0; padding: 8px; text-align: center; font-weight: 800; }
.result-actions .result-home:hover { color: var(--brand); }
@keyframes result-pop { from { opacity: 0; transform: scale(.85) translateY(12px); } }
@keyframes result-spin { to { rotate: 360deg; } }
@keyframes result-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-14px); } 60% { transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  .battle-turn[data-mode="you"], #screen-battle #btn-use-potion.potion-urgent, .field-shake, .hit-burst,
  .adv-empty-egg, .adv-world.current .adv-world-go,
  #screen-result .result-container, #screen-result .result-container > .result-burst, .result-chip, .result-callout,
  .result--win .result-hero .monster { animation: none !important; }
  .hit-burst { opacity: 0; }
  #screen-battle .battle-message { transition: opacity .2s ease; }
}

/* Lucky hit: floats above the damage number. */
#screen-battle .lucky-text {
  position: absolute;
  margin-left: -2.6rem;
  top: -64px !important;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: #7dff9c;
  -webkit-text-stroke: 1px rgba(0, 0, 0, .5);
  text-shadow: 0 3px 0 rgba(0, 0, 0, .45);
  white-space: nowrap;
  pointer-events: none;
  animation: damage-float 1s ease-out forwards;
  z-index: 21;
}
