:root {
  --gold: #e8c84a;
  --gold-dim: #8a7a3a;
  --bronze: #cd7f32;
  --marble: #d4c9a8;
  --marble-dark: #8a7a5a;
  --royal-purple: #6a3a8a;
  --divine-blue: #4a6a9a;
  --divine-blue-dark: #1a3a6a;
  --blood-red: #8a1a1a;
  --hp-green: #4aff6a;
  --hp-yellow: #e8c84a;
  --hp-red: #ff4a2a;
  --panel-bg: #121010;
  --panel-border: #2a1a10;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #0a0a0f;
  color: #d4c9a8;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 860px;
  height: 100vh;
  max-height: 100vh;
  background: linear-gradient(135deg, #1a1210 0%, #0f0a08 50%, #1a1210 100%);
  border: 1px solid #2a1a10;
  border-radius: 6px;
  box-shadow: 0 0 30px rgba(0,0,0,0.8);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 16px;
  overflow-y: auto;
}
.screen.hidden { display: none !important; }
.hidden { display: none !important; }

/* Title Screen */
#title-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  background: radial-gradient(ellipse at center, #1a1520 0%, #0a0a0f 100%);
}
.title-container { padding: 20px; }
.game-title {
  font-size: clamp(36px, 8vw, 64px);
  letter-spacing: 8px;
  color: #e8c84a;
  text-shadow: 0 0 30px rgba(232, 200, 74, 0.4), 0 4px 8px rgba(0,0,0,0.8);
  font-weight: 900;
}
.subtitle {
  font-size: clamp(13px, 2.5vw, 18px);
  color: #8a7a5a;
  margin: 8px 0 20px;
  letter-spacing: 3px;
  font-style: italic;
}
.title-decoration { font-size: 32px; margin: 15px 0; opacity: 0.6; }
.name-input-group {
  margin: 15px 0;
}
.name-input-group label {
  display: block;
  color: #8a7a5a;
  font-size: 14px;
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.hero-name-input {
  background: #121010;
  border: 2px solid #4a3828;
  color: #e8c84a;
  padding: 10px 16px;
  font-size: 20px;
  text-align: center;
  border-radius: 4px;
  width: 260px;
  max-width: 80vw;
  outline: none;
  letter-spacing: 2px;
  font-weight: bold;
  transition: border-color 0.3s;
}
.hero-name-input:focus {
  border-color: #e8c84a;
  box-shadow: 0 0 15px rgba(232,200,74,0.2);
}
.hero-name-input::placeholder { color: #3a2a1a; letter-spacing: 1px; }
.title-lore { color: #5a4a3a; font-style: italic; margin-top: 30px; font-size: 13px; }

/* Buttons */
.gold-btn, .boss-btn {
  padding: 10px 24px;
  font-size: clamp(14px, 2vw, 18px);
  cursor: pointer;
  border-radius: 4px;
  letter-spacing: 1px;
  transition: all 0.2s;
  font-weight: bold;
  border: 2px solid;
}
.gold-btn {
  background: linear-gradient(180deg, #4a3828, #2a1a10);
  color: #e8c84a;
  border-color: #6a5030;
}
.gold-btn:hover {
  background: linear-gradient(180deg, #5a4838, #3a2a18);
  border-color: #e8c84a;
  box-shadow: 0 0 20px rgba(232, 200, 74, 0.3);
}
.boss-btn {
  background: linear-gradient(180deg, #5a1a1a, #2a0a0a);
  color: #ff6a4a;
  border-color: #8a3020;
}
.boss-btn:hover {
  background: linear-gradient(180deg, #7a2a2a, #3a1010);
  border-color: #ff6a4a;
  box-shadow: 0 0 20px rgba(255, 106, 74, 0.4);
}
.locked-btn {
  opacity: 0.6;
  cursor: not-allowed;
}
.locked-btn:hover {
  border-color: #6a5030;
  box-shadow: none;
}

/* Map Screen */
.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #2a2018;
  flex-shrink: 0;
}
.map-header h2 {
  color: #e8c84a;
  font-size: clamp(16px, 3vw, 24px);
  letter-spacing: 2px;
}
.player-stats-bar {
  display: flex;
  gap: clamp(8px, 2vw, 20px);
  font-size: clamp(12px, 1.8vw, 14px);
  color: #a09070;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats-row {
  display: flex;
  gap: clamp(6px, 1.5vw, 14px);
  padding: 6px 0;
  font-size: clamp(11px, 1.6vw, 13px);
  color: #8a7a5a;
  flex-wrap: wrap;
  border-bottom: 1px solid #1a1410;
  flex-shrink: 0;
}
.stats-row b { color: #d4c9a8; }

.map-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.map-info { color: #8a7a5a; font-size: clamp(12px, 1.8vw, 14px); }
.progress-section { margin: 8px 0; }
.progress-bar {
  width: 100%;
  height: 18px;
  background: #1a1210;
  border: 1px solid #3a2a1a;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6a5030, #e8c84a);
  width: 0%;
  transition: width 0.5s;
}
.map-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.map-actions button {
  width: 100%;
  max-width: 400px;
}
.foe-preview {
  font-size: clamp(11px, 1.5vw, 13px);
  color: #6a5a4a;
  background: #121010;
  border: 1px solid #2a1a10;
  border-radius: 4px;
  padding: 6px 12px;
  width: 100%;
  max-width: 400px;
}
.foe-preview strong { color: #d4c9a8; }
.foe-preview .stat-preview {
  display: block;
  color: #8a7a5a;
  font-size: 11px;
  margin-top: 2px;
}
.foe-preview .defeated { color: #4aff6a; }

/* XP Bar */
.xp-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  flex-shrink: 0;
}
.xp-bar {
  flex: 1;
  height: 10px;
  background: #0a0a10;
  border: 1px solid #2a2040;
  border-radius: 5px;
  overflow: hidden;
}
.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, #5a3a8a, #9a5aff);
  width: 0%;
  transition: width 0.4s;
}
.xp-text {
  font-size: clamp(10px, 1.4vw, 12px);
  color: #8a7aaa;
  white-space: nowrap;
}

/* Last Battle Box */
.last-battle-box {
  background: #121010;
  border: 1px solid #3a2a1a;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 4px 0;
  font-size: clamp(11px, 1.5vw, 13px);
  line-height: 1.6;
}
.last-battle-box strong { color: #e8c84a; }

/* Battle Screen */
#battle-screen {
  padding: 4px 8px;
  overflow: hidden;
  gap: 4px;
}
.battlefield-zone {
  flex: 6;
  min-height: 0;
  position: relative;
}
.battlefield-zone canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
}
.combat-log {
  flex: 1.5;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.combat-log #battle-log {
  flex: 1;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: clamp(12px, 3.5vw, 14px);
  color: var(--marble-dark);
  line-height: 1.5;
}
#battle-log .log-dmg { color: var(--hp-red); }
#battle-log .log-heal { color: var(--hp-green); }
#battle-log .log-special { color: var(--gold); }
#battle-log .log-defend { color: #4acaff; }
#battle-log .log-system { color: #6a5a4a; font-style: italic; }

.action-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex: 3;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
}
.action-btn {
  position: relative;
  min-height: 44px;
  padding: 8px 6px;
  font-size: clamp(11px, 3vw, 14px);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: bold;
  background: var(--panel-bg);
  color: var(--marble);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.action-btn::before {
  font-size: clamp(16px, 4vw, 22px);
}
.action-btn:hover {
  border-color: var(--gold);
  background: #2a1a10;
  box-shadow: 0 0 12px rgba(232, 200, 74, 0.15);
}
.action-btn:active { transform: scale(0.95); }
.attack-btn { color: var(--hp-red); }
.attack-btn::before { content: '⚔'; }
.special-btn { color: var(--gold); }
.special-btn::before { content: '⚡'; }
.defend-btn { color: #4acaff; }
.defend-btn::before { content: '🛡'; }
.item-btn { color: var(--hp-green); }
.item-btn::before { content: '🧪'; }

/* Result Screen */
#result-screen, #victory-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
}
.result-container {
  padding: 20px;
}
#result-title {
  font-size: clamp(24px, 4.5vw, 36px);
  margin-bottom: 10px;
  text-shadow: 0 0 20px rgba(232,200,74,0.3);
  color: #e8c84a;
}
#result-title.level-up-title {
  color: #9a5aff;
  text-shadow: 0 0 30px rgba(154,90,255,0.5);
}
#result-text {
  font-size: clamp(13px, 2.2vw, 16px);
  margin-bottom: 8px;
  color: #d4c9a8;
  white-space: pre-line;
}
#result-drops { color: #e8c84a; margin-bottom: 20px; font-weight: bold; }

/* Menu Screen */
.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #2a2018;
  flex-shrink: 0;
}
.menu-header h2 { color: #e8c84a; font-size: clamp(16px, 3vw, 22px); letter-spacing: 1px; }
.menu-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.shop-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.shop-card {
  flex: 1;
  min-width: 140px;
  background: #121010;
  border: 1px solid #2a1a10;
  border-radius: 4px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.shop-card:hover {
  border-color: #6a5030;
  background: #1a1510;
}
.shop-card:active { transform: scale(0.97); }
.shop-card h3 {
  color: #e8c84a;
  font-size: clamp(11px, 1.5vw, 13px);
  margin-bottom: 4px;
}
.shop-card p { font-size: clamp(10px, 1.3vw, 12px); color: #8a7a5a; }
.shop-card .cost { color: #e8c84a; margin-top: 4px; font-weight: bold; }

.suggestions-box {
  background: #1a1210;
  border: 1px solid #3a2a1a;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 6px 0;
  font-size: clamp(11px, 1.5vw, 13px);
  color: #c8b88a;
  line-height: 1.6;
}
.suggestions-box strong { color: #e8c84a; }

.abilities-section {
  margin-top: 6px;
  padding: 8px 12px;
  background: #121010;
  border: 1px solid #2a1a10;
  border-radius: 4px;
}
.abilities-section h3 { color: #e8c84a; font-size: clamp(12px, 1.8vw, 14px); }
.abilities-section .sub-text { color: #5a4a3a; font-size: 11px; font-weight: normal; }
.abilities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.ability-tag {
  background: #1a1510;
  border: 1px solid #3a2a1a;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: clamp(10px, 1.3vw, 12px);
  color: #d4c9a8;
  cursor: help;
}
.ability-tag:hover { border-color: #e8c84a; }
.ability-tag.ability-selected { border-color: #4aff6a; background: #1a2a1a; color: #4aff6a; }

.continue-btn {
  width: 100%;
  flex-shrink: 0;
}

/* Ability Codex Screen */
#abilities-screen {
  padding: 10px 16px;
  overflow-y: auto;
}
.abilities-codex-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.abilities-codex-list::-webkit-scrollbar { width: 6px; }
.abilities-codex-list::-webkit-scrollbar-track { background: #0a0808; }
.abilities-codex-list::-webkit-scrollbar-thumb { background: #4a3a2a; border-radius: 3px; }
.ability-codex-card {
  background: #121010;
  border: 1px solid #2a1a10;
  border-radius: 4px;
  padding: 8px 12px;
}
.codex-header {
  color: #e8c84a;
  font-size: clamp(13px, 2vw, 16px);
  font-weight: bold;
  letter-spacing: 1px;
}
.codex-desc {
  color: #8a7a5a;
  font-size: clamp(11px, 1.5vw, 13px);
  margin: 2px 0;
}
.codex-stats {
  color: #6a5a4a;
  font-size: clamp(10px, 1.3vw, 12px);
  font-family: monospace;
  margin-top: 2px;
}
.farming-btn {
  color: #ff6a4a !important;
  border-color: #8a3020 !important;
}
.farming-btn::before { content: '⏹'; }
.farming-btn:hover { border-color: #ff4a2a !important; }
#auto-btn.auto-active {
  border-color: #4aff6a;
  color: #4aff6a;
}
.auto-btn::before { content: '🤖'; }

/* Game Over / Victory */
.death-title { font-size: clamp(28px, 5vw, 36px); color: #ff4a2a; margin-bottom: 10px; }
.victory-title {
  font-size: clamp(36px, 7vw, 48px);
  color: #e8c84a;
  text-shadow: 0 0 40px rgba(232,200,74,0.5);
  letter-spacing: 6px;
  margin-bottom: 10px;
}
#final-stats { color: #8a7a5a; margin: 15px 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: #0a0808; }
::-webkit-scrollbar-thumb { background: #3a2a1a; border-radius: 2px; }

/* Mobile portrait — smaller canvas, bigger action buttons */
@media (max-width: 500px) {
  .battlefield-zone { flex: 7; }
  .combat-log { flex: 1.5; }
  .action-bar { flex: 1.5; }
  .action-btn { min-height: 40px; padding: 4px 6px; font-size: 11px; }
  .action-btn::before { font-size: 16px; }
  #battle-screen { gap: 2px; padding: 2px 4px; }
  .combat-log #battle-log { font-size: 11px; padding: 3px 6px; }
}

/* Mobile landscape / small screens */
@media (max-height: 600px) {
  #app { max-height: 100vh; }
  .screen { padding: 6px 10px; }
  #battle-canvas { max-height: 40vh; }
  #battle-log { min-height: 30px; }
  .map-header h2 { font-size: 14px; }
  .stats-row { font-size: 10px; gap: 4px; }
  .shop-card { min-width: 100px; padding: 6px; }
  .game-title { font-size: 28px; }
}
@media (max-width: 480px) {
  .shop-row { flex-direction: column; }
  .shop-card { min-width: unset; }
  .player-stats-bar { font-size: 11px; gap: 6px; }
  .stats-row { font-size: 10px; gap: 4px; }
}
