:root {
  --bg-obsidian: #09080d;
  --panel-bg: rgba(16, 14, 22, 0.92);
  --panel-border: rgba(212, 175, 55, 0.45);
  --gold: #e5b84b;
  --gold-bright: #ffd978;
  --text-light: #f3ece0;
  --text-muted: #a69c8e;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-obsidian);
  color: var(--text-light);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

#game-canvas-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  background: radial-gradient(circle at 50% 35%, #1d1829 0%, #09080d 85%);
}

#game-canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Floating 3D Health Bars & Damage Popups */
#floating-labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}

.unit-hud-tag {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(10, 9, 15, 0.88);
  border: 1px solid rgba(229, 184, 75, 0.45);
  border-radius: 6px;
  padding: 2px 7px;
  min-width: 72px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.85);
}

.unit-hud-tag.ally { border-color: #38bdf8; }
.unit-hud-tag.enemy { border-color: #ef4444; }
.unit-hud-tag.active-turn {
  border-color: var(--gold-bright);
  box-shadow: 0 0 14px rgba(255, 217, 120, 0.9);
}

.unit-hud-name {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.unit-hud-hpbar {
  width: 100%;
  height: 5px;
  background: #272230;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 2px;
}

.unit-hud-hpfill {
  height: 100%;
  transition: width 0.3s ease;
}
.unit-hud-hpfill.ally { background: linear-gradient(90deg, #10b981, #34d399); }
.unit-hud-hpfill.enemy { background: linear-gradient(90deg, #dc2626, #f87171); }

.unit-hud-meta {
  font-size: 9px;
  color: #e2d9c8;
  margin-top: 1px;
}

.float-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 19px;
  text-shadow: 0 2px 6px #000, 0 0 10px #000;
  pointer-events: none;
  animation: floatUpFade 1.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  white-space: nowrap;
}

@keyframes floatUpFade {
  0% { opacity: 0; transform: translate(-50%, -10%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -65%) scale(1.15); }
  80% { opacity: 1; transform: translate(-50%, -140%) scale(1.0); }
  100% { opacity: 0; transform: translate(-50%, -185%) scale(0.9); }
}

/* TOP BAR */
#top-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(8, 7, 13, 0.95) 0%, rgba(12, 10, 18, 0.72) 80%, transparent 100%);
  pointer-events: none;
}

#top-hud > * { pointer-events: auto; }

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.65);
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--gold);
}

.brand-titles h1 {
  font-family: Georgia, serif;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--gold-bright);
}

.brand-titles p {
  font-size: 11px;
  color: var(--text-muted);
}

#turn-order-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 5px 10px;
  overflow-x: auto;
  max-width: 55vw;
}

.init-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 7px;
  background: rgba(32, 28, 44, 0.9);
  border: 1px solid rgba(255,255,255,0.14);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}
.init-badge.ally { border-left: 3px solid #38bdf8; }
.init-badge.enemy { border-left: 3px solid #ef4444; }
.init-badge.active {
  background: linear-gradient(135deg, rgba(229, 184, 75, 0.35), rgba(140, 109, 35, 0.5));
  border-color: var(--gold-bright);
  box-shadow: 0 0 12px rgba(229, 184, 75, 0.5);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-medieval {
  background: linear-gradient(180deg, #2b2438 0%, #171320 100%);
  color: var(--gold-bright);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.btn-medieval:hover {
  border-color: var(--gold-bright);
  transform: translateY(-1px);
}

.btn-medieval.primary {
  background: linear-gradient(180deg, #c28e26 0%, #7d5610 100%);
  color: #fff;
  border-color: #ffd978;
}

/* LEFT PARTY ROSTER */
#party-panel {
  position: fixed;
  top: 68px;
  left: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 215px;
  pointer-events: none;
}
#party-panel > * { pointer-events: auto; }

.hero-card-mini {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.14);
  border-left: 4px solid var(--gold);
  border-radius: 9px;
  padding: 7px 10px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}
.hero-card-mini.selected {
  border-color: var(--gold-bright);
  background: linear-gradient(90deg, rgba(229, 184, 75, 0.24), rgba(16, 14, 22, 0.94));
}
.hero-card-mini.dead {
  opacity: 0.4;
  filter: grayscale(0.9);
}

.hero-mini-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.hero-mini-name {
  font-weight: 800;
  font-size: 12px;
  color: #fff;
}
.hero-mini-class {
  font-size: 10px;
  color: var(--gold-bright);
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.hp-bar-outer {
  flex: 1;
  height: 6px;
  background: #262030;
  border-radius: 3px;
  margin: 0 6px;
  overflow: hidden;
}
.hp-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, #dc2626, #10b981);
  transition: width 0.3s ease;
}

/* SIMPLE BOTTOM ACTION BAR (Move + Attack + End Turn) */
#action-bar-dock {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(14, 12, 22, 0.95);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.9), 0 0 20px rgba(229, 184, 75, 0.25);
  min-width: 340px;
  max-width: 94vw;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#action-bar-dock.hidden-menu {
  opacity: 0;
  pointer-events: none !important;
  transform: translate(-50%, 130%);
}

#targeting-pill {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  background: rgba(14, 12, 22, 0.92);
  border: 1.5px solid var(--gold-bright);
  border-radius: 999px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.85);
}

#targeting-pill.hidden {
  display: none !important;
}

#active-hero-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  padding-bottom: 6px;
}

#active-hero-name {
  font-weight: 800;
  font-size: 14px;
  color: var(--gold-bright);
}

#active-hero-hint {
  font-size: 12px;
  color: #cbd5e1;
}

.action-buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-action-big {
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.2);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.18s ease;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

.btn-action-big.move-btn {
  background: linear-gradient(180deg, #0284c7 0%, #0369a1 100%);
  border-color: #38bdf8;
}
.btn-action-big.move-btn.active {
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.9);
  transform: translateY(-2px) scale(1.03);
}

.btn-action-big.attack-btn {
  background: linear-gradient(180deg, #dc2626 0%, #991b1b 100%);
  border-color: #f87171;
}
.btn-action-big.attack-btn.active {
  box-shadow: 0 0 18px rgba(248, 113, 113, 0.9);
  transform: translateY(-2px) scale(1.03);
}

.btn-action-big.pass-btn {
  background: linear-gradient(180deg, #4b5563 0%, #1f2937 100%);
  border-color: #9ca3af;
}

.btn-action-big:disabled {
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(0.8);
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(4, 3, 8, 0.84);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.hidden { display: none !important; }

.modal-window {
  background: linear-gradient(165deg, #1b1626 0%, #0e0b14 100%);
  border: 2px solid var(--gold);
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.95);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.modal-header h2 {
  font-family: Georgia, serif;
  color: var(--gold-bright);
  font-size: 20px;
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.scenario-card {
  background: rgba(28, 23, 39, 0.9);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

@media (max-width: 768px) {
  #party-panel {
    width: 160px;
    top: 62px;
    left: 6px;
  }
  .btn-action-big {
    padding: 10px 14px;
    font-size: 13px;
  }
}
