:root {
  --bg-color: #1a1c23;
  --panel-bg: rgba(28, 32, 42, 0.95);
  --panel-border: #44372e;
  --gold: #f4b41a;
  --gold-glow: rgba(244, 180, 26, 0.4);
  --accent-red: #d9383a;
  --accent-blue: #2c75d8;
  --text-main: #f0f0f0;
  --text-muted: #9aa0a6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  gap: 24px;
}

#viewport-wrapper {
  position: relative;
  width: 450px;
  height: 800px;
  max-height: 100vh;
  max-width: calc(100vh * 9 / 16);
  aspect-ratio: 9 / 16;
  background: #000;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 0 4px var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Desktop Sidebars */
.desktop-sidebar {
  width: 260px;
  height: 800px;
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.hud-card {
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.hero-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.hero-avatar {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background-color: #2b3a4a;
  border: 2px solid var(--gold);
}

.hero-name {
  font-weight: bold;
  font-size: 16px;
  color: var(--gold);
}

.hero-title {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-bar-container {
  margin-bottom: 8px;
}

.stat-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-bar {
  width: 100%;
  height: 10px;
  background: #111;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid #333;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff3344, #ff6677);
  transition: width 0.15s ease-out;
}

.ability-box {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: 6px;
  border-left: 3px solid var(--gold);
  margin-top: 8px;
}

.ability-title {
  font-size: 13px;
  font-weight: bold;
  color: #fff;
}

.ability-status {
  font-size: 11px;
  color: #a0ffa0;
  margin-top: 2px;
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 8px;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
}

.level-pips {
  color: var(--gold);
  letter-spacing: 2px;
  font-size: 12px;
}

.empty-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.time-display {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.time-val {
  font-size: 24px;
  color: #fff;
}

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

.stat-cell {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: 6px;
  text-align: center;
}

.cell-val {
  display: block;
  font-size: 18px;
  font-weight: bold;
  color: var(--gold);
}

.cell-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.evo-card {
  border-color: var(--gold);
  box-shadow: 0 0 15px var(--gold-glow);
}

.gold-title {
  color: #ffd700;
}

.evo-row {
  font-weight: bold;
  font-size: 13px;
  color: #fff;
  padding: 6px;
  background: rgba(244, 180, 26, 0.15);
  border-radius: 4px;
}

/* Mobile HUD */
.mobile-topbar {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: linear-gradient(180deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 100%);
  padding: 8px 12px;
  z-index: 10;
}

.mobile-hp-wrapper {
  position: relative;
  width: 140px;
  height: 14px;
  background: #222;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid #444;
  float: left;
}

.mobile-hp-fill {
  height: 100%;
  background: #ff3344;
}

.mobile-hp-text {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 9px;
  font-weight: bold;
  text-align: center;
  line-height: 14px;
  color: #fff;
}

.mobile-center-info {
  float: left;
  margin-left: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.mobile-lvl {
  background: var(--gold);
  color: #111;
  font-weight: bold;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}

.mobile-timer {
  font-size: 14px;
  font-weight: bold;
  color: #fff;
}

.mobile-pause-btn {
  float: right;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.mobile-xp-bar {
  clear: both;
  width: 100%;
  height: 4px;
  background: #111;
  margin-top: 6px;
  border-radius: 2px;
  overflow: hidden;
}

.mobile-xp-fill {
  height: 100%;
  background: #00e5ff;
}

.mobile-ability-btn {
  display: none;
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: radial-gradient(circle, #f4b41a, #b8860b);
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  color: #111;
  font-weight: bold;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  cursor: pointer;
  overflow: hidden;
}

.mobile-ability-btn.disabled {
  filter: grayscale(0.8);
  opacity: 0.6;
}

.ability-icon {
  font-size: 20px;
}

.ability-label {
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
}

.ability-cd-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: rgba(0, 0, 0, 0.7);
  pointer-events: none;
  transition: height 0.1s linear;
}

/* UI Modals Overlay */
.screens-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 12, 16, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  padding: 20px;
}

.menu-modal {
  background: #202430;
  border: 3px solid var(--panel-border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.logo-title {
  font-size: 36px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 2px 2px 0px #8b5a2b, 0 0 18px var(--gold-glow);
  letter-spacing: 2px;
}

.logo-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.currency-bar {
  display: flex;
  justify-content: center;
}

.coin-badge {
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: bold;
  font-size: 14px;
}

.home-menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: transform 0.1s, border-color 0.15s;
}

.menu-btn:hover {
  transform: translateY(-2px);
}

.btn-icon {
  font-size: 26px;
}

.btn-main {
  display: block;
  font-size: 16px;
  font-weight: bold;
}

.btn-sub {
  display: block;
  font-size: 11px;
  opacity: 0.8;
}

.primary-btn {
  background: linear-gradient(135deg, #f4b41a, #d4940a);
  color: #111;
  border-color: #ffe082;
}

.pulse-glow {
  box-shadow: 0 0 16px var(--gold-glow);
}

.secondary-btn {
  background: #2a3344;
  color: #fff;
  border-color: #3d4a60;
}

.tertiary-btn {
  background: #242936;
  color: #ddd;
  border-color: #343c4e;
}

.danger-btn {
  background: #a82424;
  color: #fff;
}

.back-btn {
  justify-content: center;
  background: #191c24;
  color: #aaa;
  margin-top: 8px;
}

/* Level Up Modal */
.level-up-modal {
  max-width: 420px;
}

.level-up-banner h2 {
  font-size: 28px;
  color: var(--gold);
  text-shadow: 0 0 10px var(--gold-glow);
}

.level-up-banner p {
  font-size: 12px;
  color: var(--text-muted);
}

.upgrade-cards-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upgrade-card {
  position: relative;
  background: #272d3c;
  border: 2px solid #3e475d;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s, border-color 0.12s;
}

.upgrade-card:hover {
  transform: scale(1.02);
  border-color: var(--gold);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.evolution-card {
  border-color: var(--gold);
  background: linear-gradient(135deg, #302615, #222938);
}

.card-shortcut {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 11px;
  color: var(--gold);
  font-weight: bold;
}

.card-icon {
  font-size: 22px;
  margin-bottom: 4px;
}

.card-title {
  font-size: 15px;
  font-weight: bold;
  color: #fff;
}

.card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.choose-card-btn {
  margin-top: 8px;
  padding: 4px 10px;
  background: var(--gold);
  color: #111;
  font-size: 11px;
  font-weight: bold;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Hero Cards */
.hero-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
}

.hero-select-card {
  background: #272d3c;
  border: 2px solid #3e475d;
  border-radius: 8px;
  padding: 12px;
  text-align: left;
}

.hero-select-card.unlocked {
  border-color: var(--gold);
}

.hero-select-name {
  font-weight: bold;
  color: var(--gold);
  font-size: 16px;
}

.hero-select-title {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}

.hero-card-desc {
  font-size: 12px;
  margin: 4px 0;
  color: #ccc;
}

.hero-card-stats {
  display: flex;
  gap: 14px;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.25);
  padding: 4px 8px;
  border-radius: 4px;
  margin: 6px 0;
}

.hero-card-ability {
  font-size: 11px;
  color: #a0d8ef;
  margin-bottom: 8px;
}

.select-btn, .unlock-btn {
  width: 100%;
  padding: 8px;
  font-weight: bold;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}

.select-btn {
  background: var(--gold);
  color: #111;
}

.unlock-btn {
  background: #3c5478;
  color: #fff;
}

/* Results */
.results-modal.victory h2 {
  color: var(--gold);
}

.results-modal.defeat h2 {
  color: #ff4444;
}

.results-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.res-item {
  background: rgba(0, 0, 0, 0.35);
  padding: 10px;
  border-radius: 6px;
}

.res-num {
  display: block;
  font-size: 20px;
  font-weight: bold;
  color: #fff;
}

.res-lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.results-leaderboard {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  padding: 10px;
  max-height: 180px;
  overflow-y: auto;
}

.lb-title {
  font-size: 12px;
  font-weight: bold;
  color: var(--gold);
  margin-bottom: 6px;
}

.lb-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
}

.lb-table th {
  color: var(--text-muted);
  text-align: left;
  padding: 3px;
}

.lb-table td {
  padding: 3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.highlight-player {
  background: rgba(244, 180, 26, 0.25);
  font-weight: bold;
  color: var(--gold);
}

/* Talents */
.talents-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
}

.talent-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #272d3c;
  padding: 10px;
  border-radius: 6px;
  text-align: left;
}

.talent-title {
  font-weight: bold;
  font-size: 13px;
  color: var(--gold);
}

.talent-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.upgrade-talent-btn {
  background: var(--gold);
  color: #111;
  font-weight: bold;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.max-badge {
  font-size: 11px;
  color: #88ff88;
  font-weight: bold;
}

.sound-toggle-bar {
  margin-top: 4px;
}

.sound-btn {
  background: none;
  border: 1px solid #444;
  color: #aaa;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

/* Responsive queries */
@media (max-width: 1000px) {
  .desktop-sidebar {
    display: none !important;
  }
  .mobile-topbar {
    display: block !important;
  }
  .mobile-ability-btn {
    display: flex !important;
  }
  #viewport-wrapper {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
  }
}
