/* ══════════════════════════════════════════════════════════
   PENGUIN ADVENTURER — Dark Fantasy Ice Cave Theme
   ══════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=Rajdhani:wght@300;400;600;700&display=swap');

/* ── CSS VARIABLES ── */
:root {
  --ice-dark:   #050d1a;
  --ice-deep:   #091428;
  --ice-mid:    #0d2040;
  --ice-blue:   #1a3a6b;
  --ice-light:  #2a5aab;
  --ice-glow:   #4488ff;
  --ice-frost:  #88ccff;
  --ice-crystal:#c8e8ff;
  --gold:       #f0c040;
  --gold-light: #ffe080;
  --red:        #e04040;
  --red-glow:   #ff6060;
  --green:      #40c070;
  --green-glow: #60ff90;
  --purple:     #9040c0;
  --epic-glow:  #cc66ff;
  --rare-glow:  #4499ff;
  --text-main:  #d0e8ff;
  --text-dim:   #6888aa;
  --text-gold:  #f0c040;
  --border:     rgba(68,136,255,0.25);
  --panel-bg:   rgba(9,20,40,0.92);
  --panel-border: rgba(68,136,255,0.3);
  --radius:     10px;
  --radius-sm:  6px;
  --glow-blue:  0 0 15px rgba(68,136,255,0.5);
  --glow-gold:  0 0 15px rgba(240,192,64,0.5);
  --glow-red:   0 0 15px rgba(224,64,64,0.5);
}

/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Rajdhani', sans-serif;
  background: var(--ice-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  font-size: 15px;
}

/* ══════════════════════════════════════════════════════════
   START SCREEN
   ══════════════════════════════════════════════════════════ */
.screen { display: none; }
.screen.active { display: block; }

#startScreen {
  position: relative;
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#startScreen.active {
  display: flex;
}

.start-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(68,136,255,0.25) 0%, transparent 70%),
    radial-gradient(ellipse at 20% 80%, rgba(40,80,200,0.2) 0%, transparent 50%),
    linear-gradient(180deg, #020810 0%, #050d1a 50%, #030810 100%);
}

.start-content {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 40px 20px;
  max-width: 440px;
  width: 100%;
}

.title-penguin {
  font-size: 80px;
  line-height: 1;
  animation: floatBob 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(100,180,255,0.6));
}

@keyframes floatBob {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-12px); }
}

.game-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  line-height: 1.1;
  color: var(--ice-crystal);
  text-shadow: 0 0 30px rgba(136,204,255,0.6), 0 0 60px rgba(68,136,255,0.4);
  letter-spacing: 3px;
  margin: 16px 0 4px;
}

.game-title span {
  color: var(--gold);
  text-shadow: 0 0 30px rgba(240,192,64,0.7);
}

.game-subtitle {
  color: var(--text-dim);
  letter-spacing: 4px;
  font-size: 0.8rem;
  text-transform: uppercase;
  margin-bottom: 40px;
}

.name-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.name-form input {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  color: var(--text-main);
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.1rem;
  padding: 14px 18px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.name-form input:focus {
  border-color: var(--ice-glow);
  box-shadow: var(--glow-blue);
}

.start-msg {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--red-glow);
  min-height: 20px;
}

/* Ice crystal decorations */
.ice-crystals {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 1;
}
.ice-crystals span {
  position: absolute;
  width: 2px;
  background: linear-gradient(180deg, transparent, rgba(136,204,255,0.6), transparent);
  animation: crystalFall linear infinite;
  opacity: 0.4;
}
.ice-crystals span:nth-child(1) { left:10%; height:100px; top:-20px; animation-duration:8s; animation-delay:0s; }
.ice-crystals span:nth-child(2) { left:30%; height:60px;  top:-10px; animation-duration:6s; animation-delay:2s; }
.ice-crystals span:nth-child(3) { left:55%; height:140px; top:-30px; animation-duration:10s; animation-delay:1s; }
.ice-crystals span:nth-child(4) { left:75%; height:80px;  top:-15px; animation-duration:7s; animation-delay:3s; }
.ice-crystals span:nth-child(5) { left:90%; height:120px; top:-25px; animation-duration:9s; animation-delay:0.5s; }

@keyframes crystalFall {
  0%   { transform: translateY(-100px); opacity: 0; }
  10%  { opacity: 0.5; }
  90%  { opacity: 0.3; }
  100% { transform: translateY(110vh); opacity: 0; }
}

/* ══════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════ */
.btn-primary {
  background: linear-gradient(135deg, #1a4aab, #2a6aff);
  border: 1px solid rgba(68,136,255,0.5);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 14px 28px;
  transition: all 0.2s;
  text-transform: uppercase;
}
.btn-primary:hover { background: linear-gradient(135deg, #2a5acd, #3a7aff); box-shadow: var(--glow-blue); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  color: var(--text-main);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 24px;
  transition: all 0.2s;
}
.btn-secondary:hover { background: rgba(68,136,255,0.12); border-color: var(--ice-glow); }

.btn-sm { padding: 8px 14px; font-size: 0.88rem; }
.w100 { width: 100%; margin-top: 10px; }

.btn-icon {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  cursor: pointer;
  font-size: 1rem;
  padding: 6px 10px;
  transition: all 0.2s;
}
.btn-icon:hover { background: rgba(68,136,255,0.15); }

.btn-attack {
  background: linear-gradient(135deg, #8b1a1a, #cc3333, #ff5555);
  border: 1px solid rgba(255,80,80,0.4);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 14px 24px;
  text-transform: uppercase;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 8px;
}
.btn-attack:hover { box-shadow: var(--glow-red); transform: scale(1.03); }
.btn-attack:active { transform: scale(0.97); }
.btn-attack.cooldown { opacity: 0.5; cursor: not-allowed; }

.btn-auto {
  background: rgba(40,120,60,0.3);
  border: 1px solid rgba(64,192,112,0.35);
  border-radius: var(--radius-sm);
  color: var(--green-glow);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 14px;
  transition: all 0.2s;
}
.btn-auto:hover { background: rgba(40,120,60,0.5); }
.btn-auto.active { background: rgba(40,192,80,0.25); border-color: var(--green-glow); box-shadow: 0 0 10px rgba(64,255,100,0.3); }
.btn-auto.btn-farm { color: var(--gold); border-color: rgba(240,192,64,0.35); background: rgba(120,80,0,0.3); }
.btn-auto.btn-farm.active { box-shadow: 0 0 10px rgba(240,192,64,0.4); background: rgba(200,140,0,0.25); }

.btn-nav {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 8px 14px;
  transition: all 0.2s;
}
.btn-nav:hover { background: rgba(68,136,255,0.1); color: var(--text-main); }

.btn-up {
  background: rgba(240,192,64,0.15);
  border: 1px solid rgba(240,192,64,0.3);
  border-radius: 4px;
  color: var(--gold);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 3px 7px;
  transition: all 0.15s;
}
.btn-up:hover { background: rgba(240,192,64,0.3); box-shadow: var(--glow-gold); }

/* ══════════════════════════════════════════════════════════
   TOP BAR
   ══════════════════════════════════════════════════════════ */
.top-bar {
  align-items: center;
  background: rgba(5,13,26,0.95);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 2px 20px rgba(68,136,255,0.2);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.player-nameplate {
  align-items: center;
  display: flex;
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  gap: 8px;
  color: var(--ice-crystal);
}
.hero-icon { font-size: 1.4rem; }

.map-display {
  background: rgba(68,136,255,0.1);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--ice-frost);
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 6px 16px;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

#goldDisplay {
  background: rgba(240,192,64,0.1);
  border: 1px solid rgba(240,192,64,0.3);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 12px;
}

/* ══════════════════════════════════════════════════════════
   GAME LAYOUT
   ══════════════════════════════════════════════════════════ */
.game-layout {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px;
  min-height: calc(100vh - 58px);
}

/* ── PANELS ── */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(8px);
}

.panel-left, .panel-right {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ice-blue) transparent;
}
.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar { width: 4px; }
.panel-left::-webkit-scrollbar-track,
.panel-right::-webkit-scrollbar-track { background: transparent; }
.panel-left::-webkit-scrollbar-thumb,
.panel-right::-webkit-scrollbar-thumb { background: var(--ice-blue); border-radius: 4px; }

/* ── SECTION TITLES ── */
.section-title {
  background: rgba(68,136,255,0.08);
  border-bottom: 1px solid var(--border);
  color: var(--ice-crystal);
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 10px 14px;
  text-transform: uppercase;
}

/* ── CHARACTER SECTION ── */
.char-section, .equip-section, .skill-section,
.rank-section, .log-section, .ad-section {
  border-bottom: 1px solid var(--border);
}

.char-portrait {
  align-items: center;
  display: flex;
  gap: 12px;
  padding: 12px 14px 8px;
}

.portrait-frame {
  background: linear-gradient(135deg, var(--ice-mid), var(--ice-deep));
  border: 2px solid var(--ice-glow);
  border-radius: 50%;
  box-shadow: var(--glow-blue);
  height: 56px;
  width: 56px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.portrait-sprite { font-size: 32px; }

.char-nameplate { display: flex; flex-direction: column; gap: 4px; }
.char-nameplate > span:first-child {
  color: var(--ice-crystal);
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
}

.level-badge {
  background: linear-gradient(135deg, #1a4aab, #2a6aff);
  border-radius: 4px;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  width: fit-content;
}

/* ── STAT BARS ── */
.stat-bar-wrap { padding: 4px 14px; }
.stat-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.stat-bar {
  background: rgba(255,255,255,0.06);
  border-radius: 20px;
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
}

.bar-fill {
  border-radius: 20px;
  height: 100%;
  transition: width 0.4s ease;
}

.hp-bar .bar-fill { background: linear-gradient(90deg, #cc2222, #ff4444, #ff6666); }
.exp-bar .bar-fill { background: linear-gradient(90deg, #1a6aab, #2a9aff); }
.enemy-hp .bar-fill { background: linear-gradient(90deg, #883300, #cc5500, #ff6600); }
.player-hp .bar-fill { background: linear-gradient(90deg, #cc2222, #ff4444); }

.bar-label {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 2px;
  display: block;
  text-align: center;
}

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 8px 12px 12px;
}

.stat-item {
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 6px;
  padding: 6px 8px;
}
.si-icon { font-size: 0.9rem; }
.si-label { color: var(--text-dim); font-size: 0.78rem; flex: 1; }
.si-val { color: var(--text-main); font-size: 0.9rem; font-weight: 700; }

/* ── EQUIPMENT ── */
.equip-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px 6px;
}

.equip-slot {
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  position: relative;
  transition: all 0.2s;
}
.equip-slot:hover { background: rgba(68,136,255,0.08); border-color: var(--ice-glow); }
.equip-slot.grade-rare { border-color: rgba(68,160,255,0.5); background: rgba(20,60,160,0.12); }
.equip-slot.grade-epic { border-color: rgba(160,80,255,0.6); background: rgba(80,20,120,0.15); animation: epicPulse 2s ease-in-out infinite; }

@keyframes epicPulse {
  0%,100% { box-shadow: 0 0 8px rgba(160,80,255,0.3); }
  50%      { box-shadow: 0 0 18px rgba(160,80,255,0.6); }
}

.slot-icon { font-size: 1.4rem; }
.slot-info { flex: 1; display: flex; flex-direction: column; }
.slot-name { color: var(--text-dim); font-size: 0.78rem; }
.slot-stat { color: var(--text-main); font-size: 0.88rem; font-weight: 700; }

.slot-grade {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ── SKILLS ── */
.skill-list { padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 6px; }

.skill-item {
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 10px;
  padding: 8px 10px;
}

.skill-icon { font-size: 1.2rem; }
.skill-info { flex: 1; display: flex; flex-direction: column; }
.skill-name { color: var(--text-main); font-size: 0.85rem; font-weight: 700; }
.skill-desc { color: var(--text-dim); font-size: 0.72rem; }
.skill-right { display: flex; align-items: center; gap: 6px; }
.skill-lv { color: var(--gold); font-size: 0.78rem; font-weight: 700; min-width: 28px; text-align: center; }

.sp-badge {
  background: rgba(240,192,64,0.15);
  border: 1px solid rgba(240,192,64,0.3);
  border-radius: 4px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: 6px;
  padding: 2px 6px;
}

/* ══════════════════════════════════════════════════════════
   BATTLE ARENA
   ══════════════════════════════════════════════════════════ */
.panel-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
}

.arena-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  width: 100%;
  height: 100%;
}

.status-effects {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 28px;
}

.status-badge {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  padding: 3px 8px;
  animation: fadeIn 0.3s ease;
}
.status-badge.debuff { border-color: rgba(255,80,80,0.4); color: var(--red-glow); }
.status-badge.buff { border-color: rgba(80,255,120,0.4); color: var(--green-glow); }

/* Battle Stage */
.battle-stage {
  background: linear-gradient(180deg, #030810 0%, #071220 50%, #040c18 100%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: inset 0 0 40px rgba(68,136,255,0.08), var(--glow-blue);
  display: flex;
  align-items: center;
  justify-content: space-around;
  min-height: 260px;
  overflow: hidden;
  padding: 20px 10px;
  position: relative;
}

.stage-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(68,136,255,0.08) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent 0px, transparent 30px, rgba(68,136,255,0.03) 30px, rgba(68,136,255,0.03) 31px);
  pointer-events: none;
}

.combatant {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1;
  flex: 1;
}

.enemy-side  { flex-direction: column; align-items: center; }
.player-side { flex-direction: column; align-items: center; }

.enemy-info, .player-battle-info {
  width: 100%;
  max-width: 180px;
  text-align: center;
}

.enemy-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 4px;
}

.enemy-name-row span:first-child {
  color: var(--ice-crystal);
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 700;
}

.enemy-map-badge {
  background: rgba(68,136,255,0.15);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.68rem;
  padding: 1px 6px;
}

.sprite-wrap { position: relative; }

.sprite {
  font-size: clamp(50px, 8vw, 70px);
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  transition: transform 0.1s;
  user-select: none;
}

.enemy-sprite { animation: enemyIdle 4s ease-in-out infinite; }
.player-sprite { animation: playerIdle 3s ease-in-out infinite; }

@keyframes enemyIdle {
  0%,100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-5px) scale(1.02); }
}
@keyframes playerIdle {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

@keyframes attackAnim {
  0%  { transform: translateX(0); }
  25% { transform: translateX(30px) scale(1.1); }
  50% { transform: translateX(0) scale(1); }
}
@keyframes enemyAttackAnim {
  0%  { transform: translateX(0); }
  25% { transform: translateX(-30px) scale(1.1); }
  50% { transform: translateX(0); }
}
@keyframes shakeAnim {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes critAnim {
  0%   { filter: drop-shadow(0 0 20px rgba(255,200,0,0.9)) brightness(2); transform: scale(1.25); }
  100% { filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6)); transform: scale(1); }
}

.sprite.attacking { animation: attackAnim 0.3s ease; }
.sprite.enemy-attacking { animation: enemyAttackAnim 0.3s ease; }
.sprite.hit { animation: shakeAnim 0.4s ease; }
.sprite.critical { animation: critAnim 0.5s ease; }

/* Damage popup layer */
.dmg-pop-layer {
  pointer-events: none;
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 100%;
}

.dmg-popup {
  animation: dmgFloat 1.2s ease-out forwards;
  color: #fff;
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 900;
  left: 50%;
  pointer-events: none;
  position: absolute;
  text-shadow: 0 2px 4px rgba(0,0,0,0.9), 0 0 10px currentColor;
  top: 10px;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 20;
}
.dmg-popup.player-dmg { color: #ff6666; }
.dmg-popup.enemy-dmg  { color: #fff; }
.dmg-popup.crit-dmg   { color: var(--gold); font-size: 1.4rem; }
.dmg-popup.heal-dmg   { color: var(--green-glow); }
.dmg-popup.miss-dmg   { color: var(--text-dim); font-size: 0.9rem; }

@keyframes dmgFloat {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  20%  { opacity: 1; transform: translateX(-50%) translateY(-20px) scale(1.2); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-60px) scale(0.8); }
}

.vs-divider {
  color: var(--text-dim);
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-shadow: 0 0 20px rgba(68,136,255,0.4);
  z-index: 1;
}

/* ── BATTLE CONTROLS ── */
.battle-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 0 4px;
}

.auto-controls {
  display: flex;
  gap: 8px;
}

.map-nav {
  display: flex;
  gap: 8px;
}

/* ── ELITE ALERT ── */
.elite-alert {
  background: linear-gradient(135deg, rgba(160,80,0,0.3), rgba(255,140,0,0.15));
  border: 1px solid rgba(255,140,0,0.5);
  border-radius: var(--radius);
  color: var(--gold-light);
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 12px;
  text-align: center;
  animation: alertPulse 1.5s ease-in-out infinite;
}

@keyframes alertPulse {
  0%,100% { box-shadow: 0 0 10px rgba(255,140,0,0.3); }
  50%      { box-shadow: 0 0 25px rgba(255,140,0,0.6); }
}
.hidden { display: none !important; }

/* ══════════════════════════════════════════════════════════
   RIGHT PANEL
   ══════════════════════════════════════════════════════════ */
/* Ranking */
.ranking-list { padding: 10px 12px; }

.rank-item {
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
  padding: 8px 10px;
}

.rank-num {
  color: var(--text-dim);
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}
.rank-num.gold   { color: #ffd700; text-shadow: 0 0 10px rgba(255,215,0,0.6); }
.rank-num.silver { color: #c0c0c0; }
.rank-num.bronze { color: #cd7f32; }

.rank-info { flex: 1; display: flex; flex-direction: column; }
.rank-name { color: var(--text-main); font-size: 0.85rem; font-weight: 700; }
.rank-detail { color: var(--text-dim); font-size: 0.72rem; }

.rank-time {
  color: var(--gold);
  font-size: 0.8rem;
  font-weight: 700;
}

.rank-empty { color: var(--text-dim); font-size: 0.85rem; text-align: center; padding: 16px; }

/* Battle Log */
.log-section { flex: 1; display: flex; flex-direction: column; }
.battle-log {
  flex: 1;
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 280px;
  overflow-y: auto;
  padding: 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--ice-blue) transparent;
}
.battle-log::-webkit-scrollbar { width: 4px; }
.battle-log::-webkit-scrollbar-thumb { background: var(--ice-blue); border-radius: 4px; }

.log-entry { border-bottom: 1px solid rgba(255,255,255,0.04); padding: 3px 0; }
.log-entry.log-player { color: var(--ice-frost); }
.log-entry.log-enemy  { color: #ff8888; }
.log-entry.log-system { color: var(--gold); font-weight: 700; }
.log-entry.log-crit   { color: var(--gold-light); }
.log-entry.log-skill  { color: var(--epic-glow); }
.log-entry.log-regen  { color: var(--green-glow); }
.log-entry.log-perfect { color: #ff44ff; font-weight: 700; text-shadow: 0 0 10px rgba(255,80,255,0.6); }

/* Ads */
.ad-section { padding: 10px 12px; }
.ad-banner {
  background: rgba(255,255,255,0.02);
  border: 1px dashed rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 8px;
  text-align: center;
}
.ad-label { color: var(--text-dim); font-size: 0.68rem; letter-spacing: 1px; text-transform: uppercase; display: block; margin-bottom: 6px; }
.btn-reward {
  background: linear-gradient(135deg, rgba(40,120,200,0.3), rgba(80,160,255,0.2));
  border: 1px solid rgba(80,160,255,0.4);
  border-radius: var(--radius-sm);
  color: var(--ice-frost);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px 16px;
  transition: all 0.2s;
  width: 100%;
}
.btn-reward:hover { background: rgba(80,160,255,0.2); box-shadow: var(--glow-blue); }

/* ══════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════ */
.modal-overlay {
  align-items: center;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 20px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 1000;
}

.modal-box {
  background: linear-gradient(160deg, #071220, #091830);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.8), var(--glow-blue);
  max-height: 90vh;
  max-width: 480px;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  width: 100%;
}

.modal-close {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  height: 30px;
  position: absolute;
  right: 14px;
  top: 14px;
  width: 30px;
  transition: all 0.2s;
}
.modal-close:hover { background: rgba(255,80,80,0.2); color: var(--red-glow); }

.modal-title {
  color: var(--ice-crystal);
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
}

/* Enhance modal */
.enhance-info {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  padding: 16px;
}
.enhance-preview {
  align-items: center;
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}
.enhance-icon { font-size: 3rem; }
.enhance-details { flex: 1; }
.enhance-name { color: var(--ice-crystal); font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.enhance-stat { color: var(--gold); font-size: 1rem; font-weight: 700; }
.enhance-chance { color: var(--text-dim); font-size: 0.8rem; margin-top: 6px; }

.enhance-cost {
  color: var(--gold);
  font-size: 0.9rem;
  margin-bottom: 16px;
  text-align: center;
}

.enhance-btn-row { display: flex; gap: 10px; }
.enhance-btn-row .btn-primary { flex: 1; }

/* Shop modal */
.shop-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.shop-tab {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  flex: 1;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px;
  text-align: center;
  transition: all 0.2s;
}
.shop-tab.active { background: rgba(68,136,255,0.15); border-color: var(--ice-glow); color: var(--text-main); }

.shop-items { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 12px;
  padding: 10px 12px;
}
.shop-item-icon { font-size: 1.6rem; }
.shop-item-info { flex: 1; }
.shop-item-name { color: var(--text-main); font-size: 0.9rem; font-weight: 700; }
.shop-item-stat { color: var(--text-dim); font-size: 0.78rem; }
.shop-item-grade.normal { color: var(--text-dim); }
.shop-item-grade.rare   { color: var(--rare-glow); }
.shop-item-grade.epic   { color: var(--epic-glow); }
.shop-item-price { color: var(--gold); font-size: 0.85rem; font-weight: 700; }

/* Victory / Complete / LevelUp */
.victory-box, .complete-box, .levelup-box {
  text-align: center;
}
.victory-title, .complete-box h2, .levelup-box h2 {
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 16px;
  text-shadow: var(--glow-gold);
}
.complete-icon, .levelup-star { font-size: 4rem; margin-bottom: 10px; animation: floatBob 2s ease-in-out infinite; }

#completeContent, #levelUpContent, #victoryContent {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 20px;
  line-height: 1.7;
}

/* ── TOAST ── */
.toast {
  align-items: center;
  background: rgba(40,80,200,0.95);
  border: 1px solid var(--ice-glow);
  border-radius: var(--radius);
  bottom: 20px;
  box-shadow: var(--glow-blue);
  color: #fff;
  display: flex;
  font-size: 0.9rem;
  font-weight: 700;
  gap: 8px;
  left: 50%;
  padding: 12px 24px;
  position: fixed;
  transform: translateX(-50%) translateY(80px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2000;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── PERFECT ENHANCE EFFECT ── */
.perfect-enhance-overlay {
  animation: perfectFlash 2s ease forwards;
  background: radial-gradient(ellipse at center, rgba(255,80,255,0.4) 0%, transparent 70%);
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 9999;
}
@keyframes perfectFlash {
  0%   { opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.5; }
  100% { opacity: 0; }
}

/* ── GRADE COLORS ── */
.grade-normal { color: var(--text-dim); }
.grade-rare   { color: var(--rare-glow); }
.grade-epic   { color: var(--epic-glow); text-shadow: 0 0 8px rgba(160,80,255,0.5); }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .game-layout { grid-template-columns: 240px 1fr 240px; }
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    max-height: none;
  }
  .panel-left, .panel-right {
    max-height: none;
    overflow-y: visible;
  }
  .panel-center { order: -1; }
  .battle-log { max-height: 180px; }
}

@media (max-width: 480px) {
  .top-bar { gap: 6px; padding: 8px 10px; }
  .player-nameplate { font-size: 0.85rem; }
  .map-display { font-size: 0.78rem; padding: 5px 10px; }
  #goldDisplay { font-size: 0.78rem; }
  .battle-stage { min-height: 200px; }
  .sprite { font-size: 44px; }
  .battle-controls { gap: 6px; }
}

/* ── ANIMATIONS ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease; }

/* ── PLAYER BUFF/DEBUFF effects ── */
.sprite-wrap.buffed .sprite {
  filter: drop-shadow(0 0 12px rgba(100,255,150,0.7)) brightness(1.2);
}
.sprite-wrap.debuffed .sprite {
  filter: drop-shadow(0 0 12px rgba(255,100,100,0.7)) brightness(0.9);
}

/* ══════════════════════════════════════════════════════════
   V2 ADDITIONS — All new/changed styles
   ══════════════════════════════════════════════════════════ */

/* ── Screen transition: hard swap, no stacking ── */
.screen            { display: none; }
.screen.active     { display: block; }
#startScreen.active{ display: flex;  flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; }
#gameScreen.active { display: flex;  flex-direction: column; min-height: 100vh; }

/* ── Start Screen ranking block ── */
.start-ranking {
  margin-top: 28px;
  background: rgba(9,20,40,0.85);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  max-width: 420px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}
.start-rank-title {
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 12px;
  text-align: center;
}
.start-rank-list { display: flex; flex-direction: column; gap: 6px; }
/* reuse .rank-item etc from existing */

/* ── Remove "Continue Journey" button (handled via HTML removal) ── */

/* ── Speed Control ── */
.speed-control {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.speed-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 9px;
  transition: all 0.15s;
}
.speed-btn:hover  { background: rgba(68,136,255,0.12); color: var(--text-main); }
.speed-btn.active { background: rgba(68,136,255,0.25); color: var(--ice-frost); }

/* ── Section helper buttons (inside section-title) ── */
.section-btn {
  background: rgba(68,136,255,0.1);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  float: right;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  margin-top: -2px;
  transition: all 0.2s;
}
.section-btn:hover { background: rgba(68,136,255,0.2); color: var(--text-main); }

/* ── Player LEFT / Enemy RIGHT ── */
/* Override the old column-reverse on player-side */
.player-side {
  flex-direction: column !important;
  align-items: center;
  order: 0; /* LEFT */
  position: relative;
}
.enemy-side {
  flex-direction: column !important;
  align-items: center;
  order: 2; /* RIGHT */
}
.vs-divider { order: 1; }

/* ── Level-up chatbox (non-blocking) ── */
.levelup-chatbox {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: linear-gradient(135deg, rgba(10,30,60,0.97), rgba(20,50,100,0.97));
  border: 1px solid rgba(100,180,255,0.5);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(68,136,255,0.4);
  color: var(--ice-crystal);
  font-size: 0.82rem;
  min-width: 170px;
  opacity: 0;
  padding: 10px 12px;
  pointer-events: none;
  text-align: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
  z-index: 50;
}
.levelup-chatbox.luc-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.luc-title {
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 5px;
}
.luc-lv { color: var(--ice-frost); }
.luc-stats { color: var(--text-dim); font-size: 0.75rem; margin-bottom: 3px; }
.luc-sp { color: var(--gold); font-size: 0.75rem; font-weight: 700; }

/* ── Battle log BELOW arena (center panel) ── */
.log-section-center {
  border-top: 1px solid var(--border);
  background: rgba(5,13,26,0.6);
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 0 -14px -14px;
  overflow: hidden;
}
.log-section-center .section-title { border-radius: 0; }
.log-section-center .battle-log { max-height: 160px; }
.battle-log {
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-y: auto;
  padding: 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--ice-blue) transparent;
}
.battle-log::-webkit-scrollbar { width: 4px; }
.battle-log::-webkit-scrollbar-thumb { background: var(--ice-blue); border-radius: 4px; }
.log-entry { border-bottom: 1px solid rgba(255,255,255,0.04); padding: 3px 0; }
.log-entry.log-player { color: var(--ice-frost); }
.log-entry.log-enemy  { color: #ff8888; }
.log-entry.log-system { color: var(--gold); font-weight: 700; }
.log-entry.log-crit   { color: var(--gold-light); }
.log-entry.log-skill  { color: var(--epic-glow); }
.log-entry.log-regen  { color: var(--green-glow); }
.log-entry.log-perfect{ color: #ff44ff; font-weight:700; text-shadow:0 0 10px rgba(255,80,255,0.6); }

/* ── Inventory Panel (RIGHT) ── */
.inv-section { border-bottom: 1px solid var(--border); }
.inv-count-badge {
  background: rgba(68,136,255,0.12);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.7rem;
  margin-left: 6px;
  padding: 1px 6px;
}
.inv-toolbar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  flex-wrap: wrap;
}
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px 10px 10px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ice-blue) transparent;
}
.inventory-grid::-webkit-scrollbar { width: 4px; }
.inventory-grid::-webkit-scrollbar-thumb { background: var(--ice-blue); border-radius: 4px; }

.inv-empty {
  grid-column: 1/-1;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 16px;
  text-align: center;
  line-height: 1.6;
}

.inv-cell {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 5px 3px;
  text-align: center;
  transition: all 0.15s;
  position: relative;
  min-height: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.inv-cell:hover       { border-color: var(--ice-glow); background: rgba(68,136,255,0.1); }
.inv-cell.inv-selected{ border-color: var(--gold); background: rgba(240,192,64,0.12); }

.grade-border-normal { border-color: rgba(136,153,170,0.4); }
.grade-border-rare   { border-color: rgba(68,160,255,0.5); }
.grade-border-epic   { border-color: rgba(200,100,255,0.6); }
.grade-border-legend { border-color: rgba(255,170,0,0.7); box-shadow: 0 0 6px rgba(255,170,0,0.3); }

.inv-icon { font-size: 1.4rem; line-height: 1; }
.inv-name { color: var(--text-main); font-size: 0.65rem; font-weight: 700; line-height: 1.2; }
.inv-sub  { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.5px; }
.inv-stat { color: var(--ice-frost); font-size: 0.68rem; font-weight: 700; }

/* Item action modal */
.modal-sm { max-width: 360px; }
.item-detail {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.item-detail-row  { font-size: 0.9rem; }
.item-detail-stat { color: var(--ice-crystal); font-size: 1rem; font-weight: 700; }
.item-compare     { color: var(--text-dim); font-size: 0.8rem; }
.item-detail-sell { font-size: 0.82rem; }
.item-action-row  { display: flex; gap: 8px; flex-wrap: wrap; }
.item-action-row .btn-primary   { flex: 1; padding: 10px; }
.item-action-row .btn-secondary { flex: 1; padding: 10px; font-size: 0.85rem; }

/* ── Enhance Modal — slot tabs ── */
.enhance-slot-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.enh-slot-tab {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 6px;
  text-align: center;
  transition: all 0.2s;
  white-space: nowrap;
}
.enh-slot-tab:hover  { background: rgba(68,136,255,0.1); color: var(--text-main); }
.enh-slot-tab.active { background: rgba(68,136,255,0.2); border-color: var(--ice-glow); color: var(--ice-crystal); }

/* Enhance rate table */
.rate-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin: 10px 0;
}
.rate-table th {
  color: var(--text-dim);
  font-weight: 700;
  padding: 4px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.rate-table td {
  color: var(--text-main);
  padding: 3px 6px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.rate-table tr.rate-current td {
  color: var(--gold);
  font-weight: 700;
  background: rgba(240,192,64,0.08);
}

/* ── Shop subtitle ── */
.shop-subtitle { color: var(--text-dim); font-size: 0.78rem; margin: -10px 0 12px; }

/* ── Grade colours (global) ── */
.grade-normal { color: #8899aa; }
.grade-rare   { color: var(--rare-glow); }
.grade-epic   { color: var(--epic-glow); }
.grade-legend { color: #ffaa00; text-shadow: 0 0 8px rgba(255,170,0,0.5); }

/* ── Enhanced damage popups ── */
.dmg-popup {
  animation: dmgFloat 1.2s ease-out forwards;
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 900;
  left: 50%;
  pointer-events: none;
  position: absolute;
  text-shadow: 0 2px 4px rgba(0,0,0,0.9), 0 0 10px currentColor;
  top: 10px;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 20;
}
.dmg-popup.player-dmg { color: #ff6666; }
.dmg-popup.enemy-dmg  { color: #ffffff; }
.dmg-popup.crit-dmg   { color: var(--gold); font-size: 1.5rem; filter: drop-shadow(0 0 8px rgba(255,200,0,0.9)); }
.dmg-popup.heal-dmg   { color: var(--green-glow); }
.dmg-popup.miss-dmg   { color: var(--text-dim); font-size: 0.9rem; }

@keyframes dmgFloat {
  0%   { opacity:1; transform:translateX(-50%) translateY(0) scale(1); }
  20%  { opacity:1; transform:translateX(-50%) translateY(-22px) scale(1.25); }
  100% { opacity:0; transform:translateX(-50%) translateY(-70px) scale(0.8); }
}

/* Critical hit: glow enemy sprite */
.sprite.critical {
  animation: critGlow 0.6s ease forwards !important;
}
@keyframes critGlow {
  0%   { filter: drop-shadow(0 0 24px rgba(255,200,0,1)) brightness(2.5) saturate(2); transform: scale(1.3); }
  100% { filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6)); transform: scale(1); }
}

/* ── Rank section (inside right panel) ── */
.rank-section { border-bottom: 1px solid var(--border); }
.ranking-list { padding: 8px 10px; }
.rank-item {
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 8px;
  margin-bottom: 5px;
  padding: 7px 9px;
}
.rank-num        { color:var(--text-dim); font-family:'Cinzel',serif; font-size:1rem; font-weight:700; min-width:22px; text-align:center; }
.rank-num.gold   { color:#ffd700; text-shadow:0 0 10px rgba(255,215,0,0.6); }
.rank-num.silver { color:#c0c0c0; }
.rank-num.bronze { color:#cd7f32; }
.rank-info       { flex:1; display:flex; flex-direction:column; }
.rank-name       { color:var(--text-main); font-size:0.85rem; font-weight:700; }
.rank-detail     { color:var(--text-dim); font-size:0.72rem; }
.rank-time       { color:var(--gold); font-size:0.8rem; font-weight:700; }
.rank-empty      { color:var(--text-dim); font-size:0.82rem; text-align:center; padding:14px; }

/* ── RESPONSIVE — mobile vertical stack ── */
@media (max-width: 1100px) {
  .game-layout { grid-template-columns: 220px 1fr 220px; }
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .panel-center { order: 1; }
  .panel-left   { order: 2; }
  .panel-right  { order: 3; }
  .panel-left, .panel-right { max-height: none; overflow-y: visible; }
  .battle-log { max-height: 130px; }
  .inventory-grid { grid-template-columns: repeat(5, 1fr); max-height: 200px; }
}

@media (max-width: 520px) {
  .top-bar { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .speed-control { order: 3; }
  .battle-stage  { min-height: 180px; padding: 12px 6px; }
  .sprite        { font-size: 42px; }
  .battle-controls { gap: 6px; }
  .btn-attack    { padding: 12px 16px; font-size: 0.9rem; }
  .inventory-grid { grid-template-columns: repeat(4, 1fr); }
  .item-action-row { flex-direction: column; }
  .enhance-slot-tabs { gap: 3px; }
  .enh-slot-tab  { font-size: 0.72rem; padding: 5px 3px; }
}

/* ══════════════════════════════════════════════════════════
   V3 ADDITIONS — UI/UX updates
   ══════════════════════════════════════════════════════════ */

/* ── Start screen: center everything vertically + horizontally ── */
/* display is handled by .screen / #startScreen.active rules above */
#startScreen {
  align-items: center;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
}
.start-content {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 420px;
  padding: 32px 20px;
  position: relative;
  text-align: center;
  width: 100%;
  z-index: 2;
}
.name-form { width: 100%; }
.name-form input { width: 100%; }

/* ── Compact Character section ── */
.char-section .char-portrait { padding: 8px 12px 4px; }
.char-section .portrait-frame { height: 48px; width: 48px; }
.char-section .portrait-sprite { font-size: 26px; }
.char-section .stat-bar-wrap  { padding: 2px 12px; }
.char-section .stat-bar       { height: 7px; }
.char-section .stats-grid     { padding: 5px 10px 8px; gap: 3px; }
.char-section .stat-item      { padding: 4px 6px; }
.char-section .si-val         { font-size: 0.85rem; }

/* ── Larger battle arena ── */
.panel-center { flex: 1; min-width: 0; }
.battle-stage {
  min-height: 300px !important;
  padding: 24px 16px !important;
}
.sprite { font-size: clamp(56px, 9vw, 80px) !important; }

/* ── Level-up chatbox: inside arena, no overlap ── */
.levelup-chatbox {
  bottom: auto !important;
  left: 50% !important;
  position: absolute !important;
  top: 8px !important;
  transform: translateX(-50%) translateY(-6px) !important;
  z-index: 40 !important;
  max-width: 180px;
  pointer-events: none;
}
.levelup-chatbox.luc-show {
  transform: translateX(-50%) translateY(0) !important;
}
/* Ensure player-side has relative positioning for chatbox */
.combatant.player-side { position: relative !important; }

/* ── Enemy skill badges above enemy name ── */
.enemy-skill-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  min-height: 20px;
  margin-bottom: 3px;
}
.enemy-skill-badges .status-badge {
  font-size: 0.68rem;
  padding: 2px 6px;
}

/* ── Quit button ── */
.btn-quit {
  background: rgba(180,30,30,0.2);
  border: 1px solid rgba(255,80,80,0.4);
  border-radius: var(--radius-sm);
  color: #ff8888;
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 11px;
  transition: all 0.2s;
}
.btn-quit:hover { background: rgba(220,50,50,0.35); color: #ffaaaa; box-shadow: 0 0 10px rgba(255,80,80,0.3); }

/* ── Large Shop button ── */
.inv-shop-row {
  padding: 6px 10px 4px;
}
.btn-shop-big {
  background: linear-gradient(135deg, rgba(40,100,200,0.35), rgba(80,160,255,0.25));
  border: 1px solid rgba(68,136,255,0.5);
  border-radius: var(--radius);
  color: var(--ice-frost);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 10px 0;
  text-align: center;
  transition: all 0.2s;
  width: 100%;
}
.btn-shop-big:hover {
  background: linear-gradient(135deg, rgba(60,130,220,0.5), rgba(100,180,255,0.35));
  box-shadow: var(--glow-blue);
  transform: translateY(-1px);
}

/* ── Legend grade gold background for equip slots ── */
.equip-slot.grade-legend {
  background: linear-gradient(135deg, rgba(120,80,0,0.25), rgba(255,170,0,0.12)) !important;
  border-color: rgba(255,170,0,0.7) !important;
  box-shadow: 0 0 10px rgba(255,170,0,0.25);
}
.equip-slot.grade-legend .slot-name { color: #ffdd88; }

/* ── Equip slot stat: two-line compact layout ── */
.equip-slot { min-height: 52px; }
.slot-stat  { font-size: 0.82rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.slot-grade { font-size: 0.65rem !important; margin-top: 1px; }

/* ── Watch Ad disabled style ── */
.btn-reward-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
.btn-reward-disabled:hover { box-shadow: none !important; background: rgba(80,160,255,0.08) !important; }

/* ── Right panel: ranking always on top ── */
.rank-section { order: -1; }

/* ── Responsive tweaks ── */
@media (max-width: 1200px) {
  .game-layout { grid-template-columns: 250px 1fr 250px; }
}
@media (max-width: 920px) {
  .game-layout { grid-template-columns: 1fr; }
  .battle-stage { min-height: 240px !important; }
}

/* ══════════════════════════════════════════════════════════
   V4 PATCHES — Bugs, enhance, options, shop refresh
   ══════════════════════════════════════════════════════════ */

/* ── Item options display ── */
.item-options-block {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.item-option {
  color: #88ddff;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ── Inventory cell: show option count indicator ── */
.inv-cell .inv-opt {
  color: #88ddff;
  font-size: 0.58rem;
  font-weight: 700;
  position: absolute;
  top: 2px;
  right: 3px;
}

/* ── Enhance: item list panels ── */
.enh-gold-bar {
  background: rgba(240,192,64,0.08);
  border: 1px solid rgba(240,192,64,0.25);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 10px;
  padding: 7px 12px;
  text-align: center;
}
.enh-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ice-blue) transparent;
}
.enh-items-list::-webkit-scrollbar { width: 4px; }
.enh-items-list::-webkit-scrollbar-thumb { background: var(--ice-blue); border-radius: 4px; }

.enh-item-panel {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.enh-item-header {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
}
.enh-item-body { display: flex; flex-direction: column; gap: 2px; }
.enh-item-name {
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 700;
}
.enh-item-stat { color: var(--ice-frost); font-size: 0.82rem; }
.enh-item-rates { color: var(--text-dim); font-size: 0.75rem; }
.enh-item-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.enh-item-actions .btn-primary { font-size: 0.85rem; padding: 8px 12px; }

/* ── Shop refresh button ── */
.btn-refresh-shop {
  background: rgba(68,136,255,0.08);
  border: 1px dashed rgba(68,136,255,0.35);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 10px;
  padding: 6px 0;
  text-align: center;
  transition: all 0.2s;
  width: 100%;
}
.btn-refresh-shop:hover {
  background: rgba(68,136,255,0.15);
  border-color: var(--ice-glow);
  color: var(--text-main);
}

/* ══════════════════════════════════════════════════════════
   V5 — Shop buy confirmation card
   ══════════════════════════════════════════════════════════ */
.shop-buy-confirm {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(40,180,80,0.1);
  border: 1px solid rgba(64,255,120,0.35);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 4px;
}
.sbc-icon  { font-size: 2.4rem; flex-shrink: 0; }
.sbc-text  { display: flex; flex-direction: column; gap: 4px; }
.sbc-name  { font-size: 1rem; font-weight: 700; }
.sbc-grade { color: var(--text-dim); font-size: 0.8rem; }
.sbc-added { color: var(--green-glow); font-size: 0.85rem; font-weight: 700; margin-top: 2px; }

/* ══════════════════════════════════════════════════════════
   V8 — Final idle game polish
   ══════════════════════════════════════════════════════════ */

/* Mode label next to auto/farm buttons */
.mode-label {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  align-self: center;
}

/* Make battle controls more prominent for idle game */
.battle-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 6px 4px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius-sm);
}

/* Auto and Farm buttons bigger + clearer active state */
.btn-auto {
  background: rgba(40,120,60,0.25);
  border: 1px solid rgba(64,192,112,0.3);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 11px 18px;
  transition: all 0.2s;
  min-width: 90px;
  text-align: center;
}
.btn-auto:hover { background: rgba(40,192,80,0.2); border-color: var(--green-glow); color: var(--green-glow); }
.btn-auto.active {
  background: rgba(40,192,80,0.22);
  border-color: var(--green-glow);
  color: var(--green-glow);
  box-shadow: 0 0 12px rgba(64,255,100,0.3);
}
.btn-auto.btn-farm { color: var(--text-dim); border-color: rgba(240,192,64,0.3); background: rgba(120,80,0,0.2); }
.btn-auto.btn-farm:hover { color: var(--gold); border-color: var(--gold); }
.btn-auto.btn-farm.active {
  background: rgba(200,140,0,0.22);
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 12px rgba(240,192,64,0.35);
}

/* Ensure grade-legend gold background on equip slot */
.equip-slot.grade-legend {
  background: linear-gradient(135deg, rgba(120,80,0,0.3), rgba(255,170,0,0.14)) !important;
  border-color: rgba(255,170,0,0.75) !important;
  box-shadow: 0 0 12px rgba(255,170,0,0.28);
}

/* ══════════════════════════════════════════════════════════
   V10 — Pause, Equipment Info, Options display, Dodge stat
   ══════════════════════════════════════════════════════════ */

/* Pause button */
.btn-pause {
  background: rgba(80,80,160,0.25);
  border-color: rgba(140,140,255,0.4);
  color: #aaaaff;
}
.btn-pause:hover { background: rgba(100,100,200,0.35); color: #ccccff; }
.btn-pause.active {
  background: rgba(120,120,220,0.3);
  border-color: #aaaaff;
  color: #ccccff;
  box-shadow: 0 0 10px rgba(150,150,255,0.4);
}

/* Equip slot options tags */
.slot-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}
.eq-opt-tag {
  background: rgba(136,200,255,0.1);
  border: 1px solid rgba(136,200,255,0.25);
  border-radius: 3px;
  color: #88ccff;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 5px;
  white-space: nowrap;
}

/* Equip slot — taller now to fit options */
.equip-slot {
  min-height: 58px;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 10px 6px;
}
.equip-slot > * { width: 100%; }
.equip-slot .slot-icon { font-size: 1.1rem; margin-bottom: 2px; }

/* Equipment Info Modal card */
.equip-info-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 4px;
}
.eic-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.eic-icon { font-size: 2.2rem; flex-shrink: 0; }
.eic-main { flex: 1; }
.eic-name {
  color: var(--ice-crystal);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}
.eic-grade {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin-top: 2px;
}
.eic-stat {
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
}

/* Equipment Info options section */
.equip-info-options {
  background: rgba(136,200,255,0.06);
  border: 1px solid rgba(136,200,255,0.2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.eio-label {
  color: var(--ice-frost);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.eio-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.eio-row:last-child { border-bottom: none; }
.eio-key { color: var(--text-dim); font-size: 0.82rem; }
.eio-val { color: #88ddff; font-size: 0.88rem; font-weight: 700; }

/* Stats grid — 4 columns now (was 2-col for 6 stats, now 7 stats) */
.stats-grid {
  grid-template-columns: 1fr 1fr;
}
