:root {
  --bg-primary: #0f0c1b;
  --bg-secondary: #1a162b;
  --bg-panel: rgba(26, 22, 43, 0.85);
  
  /* Character specific colors */
  --color-luffy: #ff2e51;
  --color-luffy-glow: rgba(255, 46, 81, 0.4);
  --color-pikachu: #ffd600;
  --color-pikachu-glow: rgba(255, 214, 0, 0.4);
  --color-kirby: #ff7ebb;
  --color-kirby-glow: rgba(255, 126, 187, 0.4);
  
  /* Text and borders */
  --text-main: #f3efff;
  --text-muted: #a59fb8;
  --border-light: rgba(165, 159, 184, 0.2);
  --border-glow: #8e54ff;
  
  /* Fonts */
  --font-display: 'Jua', 'Outfit', sans-serif;
  --font-body: 'Outfit', 'Jua', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-body);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

#game-container {
  position: relative;
  width: 1024px;
  height: 768px;
  max-width: 100vw;
  max-height: 100vh;
  background-color: var(--bg-secondary);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 40px rgba(142, 84, 255, 0.2);
  overflow: hidden;
  border: 4px solid #33265c;
  display: flex;
  flex-direction: column;
}

/* Sound Button */
.icon-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--bg-panel);
  border: 2px solid var(--border-light);
  color: white;
  padding: 10px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  font-size: 1.2rem;
  transition: all 0.2s ease;
}
.icon-btn:hover {
  transform: scale(1.1);
  border-color: var(--border-glow);
  box-shadow: 0 0 10px var(--border-glow);
}
.home-btn {
  left: 20px;
  right: auto;
}

/* Base Screen Layout */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
  transform: scale(0.95);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
  z-index: 2;
}

/* BUTTONS */
.btn {
  font-family: var(--font-display);
  font-size: 1.5rem;
  padding: 12px 30px;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  margin: 10px;
}
.btn-primary {
  background: linear-gradient(135deg, #8e54ff, #4b1fff);
  color: white;
  border: 2px solid #b388ff;
}
.btn-primary:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 25px rgba(142, 84, 255, 0.5), 0 0 15px rgba(142, 84, 255, 0.3);
}
.btn-secondary {
  background: #2a224a;
  color: #c9bfff;
  border: 2px solid var(--border-light);
}
.btn-secondary:hover {
  background: #362c61;
  transform: translateY(-2px);
  border-color: #8e54ff;
}
.btn-large {
  font-size: 2rem;
  padding: 20px 60px;
}

/* START SCREEN */
#start-screen {
  background: radial-gradient(circle at center, #1b133b 0%, #0a0618 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}

.logo-area {
  text-align: center;
}
.game-title {
  font-family: var(--font-display);
  font-size: 4.5rem;
  font-weight: 800;
  background: linear-gradient(to bottom, #fff, #ffd600, #ff5e00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6)) drop-shadow(0 0 20px rgba(255, 94, 0, 0.3));
  letter-spacing: 2px;
  margin-bottom: 10px;
  animation: logo-shimmer 2s ease-in-out infinite alternate;
}
.subtitle {
  font-size: 1.4rem;
  color: #b5acff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.intro-visual {
  display: flex;
  gap: 40px;
  font-size: 4rem;
  margin: 30px 0;
}

.character-preview {
  width: 120px;
  height: 120px;
  background: rgba(255, 255, 255, 0.05);
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 20px rgba(0,0,0,0.4);
}

/* Previews special effects */
.kirby-spin {
  animation: kirby-float 3s ease-in-out infinite;
  background: radial-gradient(circle, rgba(255, 126, 187, 0.3) 0%, transparent 70%);
  border-color: var(--color-kirby);
}
.luffy-bounce {
  animation: luffy-bounce 1s ease-in-out infinite alternate;
  background: radial-gradient(circle, rgba(255, 46, 81, 0.3) 0%, transparent 70%);
  border-color: var(--color-luffy);
}
.pika-flash {
  animation: pika-glow 1.5s ease-in-out infinite alternate;
  background: radial-gradient(circle, rgba(255, 214, 0, 0.3) 0%, transparent 70%);
  border-color: var(--color-pikachu);
}

/* CHARACTER SELECT SCREEN */
#select-screen {
  background: #0f0a24;
}
.section-title {
  font-family: var(--font-display);
  font-size: 2.5rem;
  margin-bottom: 40px;
  color: #ffd600;
  text-shadow: 0 0 15px rgba(255, 214, 0, 0.4);
}
.character-grid {
  display: flex;
  gap: 30px;
  width: 100%;
  max-width: 900px;
  justify-content: center;
}
.char-card {
  flex: 1;
  background: var(--bg-panel);
  border: 3px solid var(--border-light);
  border-radius: 15px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
}
.char-card:hover {
  transform: translateY(-15px) scale(1.03);
}
.char-card[data-id="luffy"]:hover {
  border-color: var(--color-luffy);
  box-shadow: 0 15px 40px var(--color-luffy-glow);
}
.char-card[data-id="pikachu"]:hover {
  border-color: var(--color-pikachu);
  box-shadow: 0 15px 40px var(--color-pikachu-glow);
}
.char-card[data-id="kirby"]:hover {
  border-color: var(--color-kirby);
  box-shadow: 0 15px 40px var(--color-kirby-glow);
}

.char-img-wrapper {
  width: 100%;
  height: 220px;
  background: #231c3d;
  overflow: hidden;
  border-bottom: 3px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.char-select-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}
.char-card:hover .char-select-img {
  transform: scale(1.1);
}

.char-info {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-grow: 1;
  justify-content: space-between;
}
.char-name {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: white;
}
.char-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 5px;
  font-weight: 600;
}
.char-tag.rubber { background: var(--color-luffy); color: white; }
.char-tag.electric { background: var(--color-pikachu); color: #000; }
.char-tag.inhale { background: var(--color-kirby); color: white; }

.char-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.4;
  min-height: 55px;
}
.char-skill {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: #a580ff;
  border-top: 1px dashed var(--border-light);
  padding-top: 10px;
  margin-top: auto;
}

/* BATTLE ARENA SCREEN */
#battle-screen {
  padding: 20px;
  background: linear-gradient(180deg, rgba(15, 12, 27, 0.4) 0%, rgba(15, 12, 27, 0.9) 100%), 
              url('images/arena_bg.jpg');
  background-size: cover;
  background-position: center;
  justify-content: space-between;
}

/* HUD System */
.battle-hud {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  padding: 15px 25px;
  border-radius: 15px;
  border: 2px solid var(--border-light);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
}
.hud-character {
  width: 40%;
}
.hud-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}
.hud-name {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: white;
}
.hud-level {
  font-size: 0.85rem;
  color: #00ffaa;
  font-weight: 600;
}
.hp-bar-container {
  position: relative;
  width: 100%;
  height: 24px;
  background: #141026;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.1);
}
.hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #00ff87, #60efff);
  border-radius: 10px;
  transition: width 0.4s ease-out;
}
.hp-bar-fill.enemy-hp {
  background: linear-gradient(90deg, #ff007f, #ff7ebb);
}
.hp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.8rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.vs-timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 18%;
}

.vs-badge {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  font-style: italic;
  color: #ff0055;
  background: #ffe3ec;
  padding: 3px 12px;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(255, 0, 85, 0.3);
}

.battle-timer-bar-container {
  width: 90px;
  height: 6px;
  background: #141026;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}

.battle-timer-bar-fill {
  height: 100%;
  width: 100%;
  background: #00ff87;
  border-radius: 3px;
  transition: width 1s linear, background-color 0.5s ease;
}

.battle-timer {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: #ffd600;
  text-shadow: 0 0 5px rgba(255, 214, 0, 0.5);
  font-weight: bold;
}
.battle-timer.danger {
  color: #ff2e51;
  text-shadow: 0 0 10px rgba(255, 46, 81, 0.8);
  animation: timer-blink 0.5s infinite alternate;
}

@keyframes timer-blink {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

/* Battlefield layout */
.battlefield {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  height: 260px;
  padding: 0 100px;
  position: relative;
  margin: 10px 0;
}
.fighter {
  position: relative;
  width: 180px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fighter-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 15px rgba(0,0,0,0.5));
}

/* Effect Layer and Damage Popups */
.effect-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}
.damage-popup {
  position: absolute;
  top: -30px;
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: #ff3c00;
  text-shadow: 0 2px 4px black, 0 0 10px rgba(255, 60, 0, 0.8);
  font-weight: 800;
  opacity: 0;
  transform: translateY(0) scale(0.5);
  pointer-events: none;
  z-index: 6;
}

/* Battle Log */
.battle-log {
  width: 100%;
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 8px 20px;
  font-size: 1.1rem;
  text-align: center;
  color: #ffd600;
  margin-bottom: 10px;
}

/* Math Interaction Panel */
.math-panel {
  display: flex;
  width: 100%;
  height: 280px;
  gap: 20px;
}

/* Question Area */
.question-container {
  flex: 4;
  background: var(--bg-panel);
  border-radius: 15px;
  border: 2px solid var(--border-light);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(10px);
}
.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.round-badge {
  background: #8e54ff;
  padding: 3px 12px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 0.9rem;
}
.question-type-badge {
  background: rgba(255, 214, 0, 0.2);
  color: #ffd600;
  border: 1px solid rgba(255, 214, 0, 0.4);
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 0.9rem;
  font-weight: bold;
}
.question-body {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
#question-text {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: white;
  line-height: 1.4;
}

#visual-helper-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 5px;
}
#helper-canvas {
  max-width: 140px;
  max-height: 140px;
}

/* Answer Choices Area */
.answers-container {
  flex: 3;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}
.choice-btn {
  background: linear-gradient(135deg, #2b2352, #181335);
  border: 3px solid var(--border-light);
  border-radius: 12px;
  color: white;
  font-family: var(--font-display);
  font-size: 1.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.choice-btn:hover {
  transform: scale(1.03);
  border-color: #8e54ff;
  box-shadow: 0 0 15px rgba(142, 84, 255, 0.3);
  background: linear-gradient(135deg, #382e6b, #1d1840);
}
.choice-btn:active {
  transform: scale(0.97);
}

/* Fraction Rendering Style (in choices/questions) */
.fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1;
  padding: 0 4px;
}
.numerator {
  border-bottom: 2px solid white;
  padding-bottom: 2px;
  margin-bottom: 2px;
}
.denominator {
  padding-top: 1px;
}

/* MODAL - OVERLAY */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 3, 13, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: radial-gradient(circle at top, #261f4d, #14102c);
  border: 4px solid #8e54ff;
  border-radius: 20px;
  padding: 40px;
  width: 90%;
  max-width: 500px;
  text-align: center;
  box-shadow: 0 0 50px rgba(142, 84, 255, 0.5);
  transform: scale(0.8);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-content h2 {
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: #ffd600;
  margin-bottom: 20px;
  text-shadow: 0 0 15px rgba(255, 214, 0, 0.3);
}

.winner-ill {
  font-size: 5rem;
  margin-bottom: 20px;
  animation: kirby-float 2s ease-in-out infinite;
}

#modal-summary {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.score-box {
  background: rgba(0,0,0,0.3);
  padding: 15px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  margin-bottom: 30px;
  font-size: 1.3rem;
}
.score-box strong {
  font-family: var(--font-display);
  font-size: 2rem;
  color: #00ffaa;
  margin: 0 5px;
}

/* ANIMATION KEYFRAMES */
@keyframes logo-shimmer {
  from { filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6)) drop-shadow(0 0 20px rgba(255, 94, 0, 0.3)); }
  to { filter: drop-shadow(0 4px 12px rgba(0,0,0,0.8)) drop-shadow(0 0 35px rgba(255, 94, 0, 0.6)); }
}

@keyframes kirby-float {
  0% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

@keyframes luffy-bounce {
  from { transform: translateY(0) scaleY(1); }
  to { transform: translateY(-15px) scaleY(0.95); }
}

@keyframes pika-glow {
  from { box-shadow: 0 0 15px rgba(255, 214, 0, 0.2); }
  to { box-shadow: 0 0 30px rgba(255, 214, 0, 0.6); }
}

/* Fighter Attack Animations */
.attack-forward-left {
  animation: attack-fw-l 0.5s ease-out;
}
@keyframes attack-fw-l {
  0% { transform: translateX(0); }
  50% { transform: translateX(100px) scale(1.1); }
  100% { transform: translateX(0); }
}

.attack-forward-right {
  animation: attack-fw-r 0.5s ease-out;
}
@keyframes attack-fw-r {
  0% { transform: translateX(0); }
  50% { transform: translateX(-100px) scale(1.1); }
  100% { transform: translateX(0); }
}

.hurt {
  animation: hurt-shake 0.4s ease-in-out;
}
@keyframes hurt-shake {
  0% { transform: translateX(0) rotate(0); filter: brightness(1); }
  15% { transform: translateX(-10px) rotate(-5deg); filter: brightness(1.5) sepia(1) saturate(5) hue-rotate(-50deg); }
  30% { transform: translateX(10px) rotate(5deg); }
  45% { transform: translateX(-8px) rotate(-3deg); }
  60% { transform: translateX(8px) rotate(3deg); }
  75% { transform: translateX(-4px) rotate(-1deg); }
  100% { transform: translateX(0) rotate(0); filter: brightness(1); }
}

/* Damage Text Popups Animation */
.pop-damage {
  animation: popup-dmg-anim 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes popup-dmg-anim {
  0% { opacity: 0; transform: translateY(0) scale(0.5); }
  30% { opacity: 1; transform: translateY(-40px) scale(1.2); }
  70% { opacity: 1; transform: translateY(-50px) scale(1); }
  100% { opacity: 0; transform: translateY(-70px) scale(0.8); }
}

/* special impact effect overlays */
.electric-strike {
  animation: lightning-flash 0.3s ease-out;
  background: radial-gradient(circle, rgba(255, 214, 0, 0.7) 10%, transparent 60%);
}
@keyframes lightning-flash {
  0% { opacity: 0; }
  25% { opacity: 1; }
  50% { opacity: 0; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

.punch-strike {
  animation: punch-flash 0.3s ease-out;
  background: radial-gradient(circle, rgba(255, 46, 81, 0.8) 10%, transparent 60%);
}
@keyframes punch-flash {
  0% { opacity: 0; transform: scale(0.5); }
  50% { opacity: 1; transform: scale(1.3); }
  100% { opacity: 0; transform: scale(1); }
}

.inhale-effect {
  animation: inhale-flash 0.5s ease-out;
  background: radial-gradient(circle, rgba(255, 126, 187, 0.6) 10%, transparent 70%);
}
@keyframes inhale-flash {
  0% { opacity: 0; transform: scale(0.2); }
  50% { opacity: 1; transform: scale(1.5); }
  100% { opacity: 0; transform: scale(1); }
}
