:root {
  --bg-dark: #2b2b2b;
  --gold-primary: #f6c042;
  --gold-glow: #ffb703;
  --card-bg: rgba(22, 14, 10, 0.95);
  --border-amber: #542b18;
  --text-main: #fef3c7;
  --text-gold: #fde68a;
  --text-muted: #94a3b8;
  --font-fantasy: 'Cinzel', Georgia, serif;
  --font-sans: 'Montserrat', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
}

.mobile-app {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  max-width: 600px;
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  padding: max(6px, env(safe-area-inset-top, 6px)) 10px max(14px, env(safe-area-inset-bottom, 14px)) 10px;
  box-sizing: border-box;
  gap: 6px;
}

/* 1. Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border: 1.5px solid var(--border-amber);
  border-radius: 14px;
  padding: 6px 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  flex-direction: column;
}

.logo-text {
  font-family: var(--font-fantasy);
  font-size: 18px;
  font-weight: 900;
  color: #ffde59;
  letter-spacing: 1px;
  line-height: 1.1;
}

.logo-sub {
  font-size: 9px;
  color: #d1b89d;
  font-weight: 600;
  text-transform: uppercase;
}

.floor-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid #b45309;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 700;
  color: #fde68a;
}

.header-gold {
  font-size: 13px;
  font-weight: 800;
  color: #fcd34d;
}

/* 2. Combat Strip (Hero vs Monster) */
.combat-strip {
  display: grid;
  grid-template-columns: 1fr 75px 1fr;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.combat-unit {
  background: var(--card-bg);
  border: 1.5px solid var(--border-amber);
  border-radius: 12px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  transition: all 0.25s;
}

.combat-unit.active {
  border-color: #f59e0b;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.6);
  background: rgba(36, 18, 12, 0.98);
}

.unit-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.unit-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #d49a3f;
  object-fit: cover;
}

.enemy-avatar-box {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3b1812;
  border-radius: 50%;
  border: 2px solid #dc2626;
}

.enemy-emoji {
  font-size: 22px;
}

.turn-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 1.5px solid #000;
  box-shadow: 0 0 6px #22c55e;
}

.unit-meta {
  flex: 1;
  min-width: 0;
}

.unit-meta.text-right {
  text-align: right;
}

.unit-name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 3px;
}

.flex-end {
  justify-content: flex-end;
  gap: 6px;
}

.unit-name {
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-hp-text {
  font-size: 10px;
  color: #cbd5e1;
}

.hp-bar-track {
  width: 100%;
  height: 7px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid #4a2414;
  border-radius: 4px;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  transition: width 0.35s ease;
}

.hero-fill {
  background: linear-gradient(90deg, #10b981, #059669);
}

.enemy-fill {
  background: linear-gradient(90deg, #ef4444, #b91c1c);
}

/* Center Orb */
.charge-orb {
  background: rgba(18, 9, 6, 0.95);
  border: 2px solid #f59e0b;
  border-radius: 12px;
  padding: 4px;
  text-align: center;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
}

.orb-title {
  font-family: var(--font-fantasy);
  font-size: 9px;
  font-weight: 900;
  color: #ffde59;
}

.orb-val {
  font-size: 18px;
  font-weight: 900;
  color: #22c55e;
  line-height: 1;
  text-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
}

/* 3. Central Interactive Canvas */
.arena-canvas-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  max-height: 48vh;
  overflow: hidden;
}

/* Loader Overlay */
.asset-loader-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(22, 14, 10, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 50;
  transition: opacity 0.3s ease;
}

.loader-spinner {
  font-size: 38px;
  animation: spinDice 1s infinite cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

@keyframes spinDice {
  0% { transform: rotate(0deg) scale(0.9); }
  50% { transform: rotate(180deg) scale(1.15); }
  100% { transform: rotate(360deg) scale(0.9); }
}

.loader-text {
  font-family: var(--font-fantasy);
  font-size: 13px;
  color: #ffde8a;
  letter-spacing: 0.5px;
}

.loader-bar {
  width: 160px;
  height: 8px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid #7c4424;
  border-radius: 6px;
  overflow: hidden;
}

.loader-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #10b981);
  transition: width 0.2s ease;
}

#phaser-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#phaser-container canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Status Pill */
.status-pill {
  background: rgba(18, 10, 6, 0.9);
  border: 1px solid #7c4424;
  border-radius: 16px;
  padding: 5px 12px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #fde68a;
  flex-shrink: 0;
}

/* 4. Bottom Dock */
.app-dock {
  flex-shrink: 0;
  margin-bottom: 4px;
}

.action-grid {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.btn-action {
  flex: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 14px;
  font-family: var(--font-fantasy);
  font-weight: 900;
  font-size: 14px;
  padding: 11px 10px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.btn-roll {
  background: linear-gradient(180deg, #ffde59 0%, #f59e0b 50%, #b45309 100%);
  color: #3b1803;
  border: 2px solid #fff3a8;
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.6);
}

.btn-roll:hover:not(:disabled) {
  transform: translateY(-2px);
}

.btn-roll:disabled {
  filter: grayscale(0.7) opacity(0.5);
  cursor: not-allowed;
}

.btn-badge {
  background: rgba(60, 20, 5, 0.5);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 10px;
}

.btn-attack {
  background: linear-gradient(180deg, #dc2626 0%, #991b1b 100%);
  color: #fff;
  border: 2px solid #fca5a5;
  box-shadow: 0 0 16px rgba(220, 38, 38, 0.6);
}

.btn-attack:disabled {
  filter: grayscale(0.7) opacity(0.4);
  cursor: not-allowed;
}

.btn-next-floor {
  background: linear-gradient(180deg, #10b981 0%, #047857 100%);
  color: #fff;
  border: 2px solid #6ee7b7;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.8);
  animation: pulseElevator 1.2s infinite alternate;
}

@keyframes pulseElevator {
  0% { transform: scale(1); }
  100% { transform: scale(1.03); }
}

.btn-icon-square {
  flex: 0 0 46px;
  background: var(--card-bg);
  border: 1.5px solid var(--border-amber);
  border-radius: 14px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #d1b89d;
  transition: all 0.2s;
}

.btn-icon-square:hover {
  background: rgba(45, 22, 14, 0.95);
  transform: translateY(-1px);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--card-bg);
  border: 2px solid var(--border-amber);
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(138, 70, 36, 0.4);
  padding-bottom: 8px;
}

.modal-header h3 {
  font-family: var(--font-fantasy);
  font-size: 15px;
  color: #ffde8a;
}

.btn-close-modal {
  background: none;
  border: none;
  font-size: 18px;
  color: #94a3b8;
  cursor: pointer;
}

/* Tower list in modal */
.tower-floor-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.tower-floor-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(18, 9, 6, 0.85);
  border: 1px solid #4a2414;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
}

.tower-floor-item.current {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.2);
}

.tower-floor-item.cleared {
  opacity: 0.6;
  border-color: #10b981;
}

.tower-floor-item.locked {
  opacity: 0.35;
}

.floor-num-badge {
  font-family: var(--font-fantasy);
  font-weight: 800;
  color: #ffde59;
}

.floor-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.floor-enemy-name {
  font-weight: 700;
  color: #fff;
}

.floor-hp-val {
  font-size: 10px;
  color: #cbd5e1;
}

/* Combos grid in modal */
.combos-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 12px;
}

.combo-item {
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.combo-item.full-span {
  grid-column: span 2;
}

.die {
  font-size: 16px;
  color: #ffde59;
}

.modal-note {
  font-size: 10.5px;
  color: #cbd5e1;
  line-height: 1.3;
}
