:root {
  --bg-obsidian: #07080b;
  --bg-panel: #12151c;
  --bg-panel-elevated: #1a1e28;
  --border-iron: #2d3340;
  --border-highlight: #475063;
  --text-main: #edf0f5;
  --text-dim: #9aa3b2;
  --crimson: #c92a2a;
  --crimson-bright: #ff3b30;
  --gold: #d4af37;
  --mist: #38d9a9;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #040507;
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 430px;
  max-height: 932px;
  background: var(--bg-obsidian);
  overflow: hidden;
  border-left: 1px solid #1a1d24;
  border-right: 1px solid #1a1d24;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.92);
}

@media (max-width: 480px) {
  #app-shell {
    max-width: 100%;
    max-height: 100dvh;
    border: none;
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

#screen-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, #ff4d4d 0%, #090305 100%);
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}

/* Top Bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 8px;
  background: linear-gradient(180deg, #10131a 0%, #0b0d12 100%);
  border-bottom: 1px solid var(--border-iron);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 16px;
}

.ver-tag {
  font-size: 10px;
  font-weight: 800;
  color: #ff8787;
  background: rgba(255, 59, 48, 0.16);
  border: 1px solid rgba(255, 59, 48, 0.4);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
}

.skull-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--crimson-bright);
  box-shadow: 0 0 10px var(--crimson-bright);
}

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

.soul-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: #171217;
  border: 1px solid #592025;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #ffd8d6;
}

.soul-pill.compact {
  padding: 3px 8px;
  font-size: 12px;
}

.gem-icon {
  width: 9px;
  height: 12px;
  background: linear-gradient(135deg, #ff8787 0%, #ff2b2b 60%, #7f1111 100%);
  clip-path: polygon(50% 0%, 100% 35%, 80% 100%, 20% 100%, 0% 35%);
  box-shadow: 0 0 8px rgba(255, 59, 48, 0.8);
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border-iron);
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  font-size: 14px;
  cursor: pointer;
}

.cure-bar-wrap {
  padding: 8px 14px 10px;
  background: #0b0d12;
  border-bottom: 1px solid #1b1f29;
}

.cure-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: #9bb8d6;
  margin-bottom: 5px;
}

.bar-track {
  width: 100%;
  height: 7px;
  background: #141923;
  border: 1px solid #262e3d;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill.cure-fill {
  height: 100%;
  background: linear-gradient(90deg, #1c7ed6, #74c0fc);
  transition: width 0.3s ease;
}

.map-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: radial-gradient(circle at 50% 45%, #161820 0%, #07080b 80%);
}

#map-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.map-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(10, 12, 16, 0.82);
  border: 1px solid #2f3543;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  pointer-events: none;
}

.city-drawer {
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #12151c 0%, #0c0e13 100%);
  border-top: 1px solid var(--border-iron);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.city-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.city-title-row h2 {
  font-size: 17px;
  font-weight: 800;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(201, 42, 42, 0.22);
  border: 1px solid rgba(255, 59, 48, 0.45);
  color: #ffc9c9;
}

.badge.conquered {
  background: rgba(201, 42, 42, 0.48);
  border-color: var(--crimson-bright);
  color: #fff;
}

.badge.sanctuary {
  background: rgba(212, 175, 55, 0.18);
  border-color: var(--gold);
  color: #ffe066;
}

.city-desc {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.city-stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #b4bccb;
  background: #0d1016;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #202531;
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
}

.btn-primary,
.btn-secondary {
  height: 44px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: linear-gradient(180deg, #d93636 0%, #9b1c1c 100%);
  border-color: #ff5c5c;
  color: #fff;
  box-shadow: 0 4px 18px rgba(201, 42, 42, 0.4);
}

.btn-secondary {
  background: #1a1f29;
  border-color: var(--border-highlight);
  color: var(--text-main);
}

.btn-primary:disabled {
  opacity: 0.45;
}

.full-btn {
  width: 100%;
}

/* Battle HUD */
.battle-hud {
  padding: 10px 12px 8px;
  background: linear-gradient(180deg, #0d0f14 0%, #090b0f 100%);
  border-bottom: 1px solid #232833;
  z-index: 5;
}

.hud-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.hud-city-name {
  font-size: 14px;
  font-weight: 800;
}

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

.hud-mini-btn {
  padding: 4px 8px;
  border-radius: 7px;
  background: #171b24;
  border: 1px solid var(--border-iron);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.infection-gauge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gothic-bar-frame {
  position: relative;
  flex: 1;
  height: 22px;
  background: #0d0f13;
  border: 2px solid #484f5e;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
}

.gothic-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #7f1111 0%, #e03131 70%, #ff6b6b 100%);
  box-shadow: 0 0 12px rgba(255, 59, 48, 0.6);
  transition: width 0.14s linear;
}

.bar-overlay-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 3px #000;
}

.timer-pill {
  min-width: 46px;
  text-align: center;
  padding: 4px 6px;
  border-radius: 6px;
  background: #171a22;
  border: 1px solid var(--border-iron);
  font-size: 12px;
  font-weight: 800;
}

.timer-pill.urgent {
  border-color: var(--crimson-bright);
  color: #ff8787;
}

/* Battle 3D Stage */
.battle-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #050608;
  overflow: hidden;
}

#gl-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.fx-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.float-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 900;
  color: #ffe3e3;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 10px rgba(255, 59, 48, 0.8);
  white-space: nowrap;
}

.float-pop.block {
  color: #ffe066;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 10px rgba(255, 212, 59, 0.7);
}

.stage-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(12, 13, 18, 0.86);
  border: 1px solid rgba(255, 59, 48, 0.6);
  color: #ffe3e3;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
  transition: opacity 0.25s ease;
}

.stage-banner.hidden {
  opacity: 0;
}

/* Skill Dock */
.skill-dock {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #101319 0%, #090b0f 100%);
  border-top: 2px solid #2b313e;
  z-index: 5;
}

.skill-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 4px 6px;
  background: linear-gradient(180deg, #1c202a 0%, #11141b 100%);
  border: 2px solid #3f4656;
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  overflow: hidden;
}

.skill-slot.selected {
  border-color: var(--crimson-bright);
  box-shadow: 0 0 16px rgba(255, 59, 48, 0.55);
  background: linear-gradient(180deg, #2d1619 0%, #170d10 100%);
}

.skill-slot.disabled {
  opacity: 0.5;
}

.skill-icon-box {
  width: 34px;
  height: 34px;
  margin-bottom: 3px;
}

.skill-icon-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.skill-name {
  font-size: 11px;
  font-weight: 800;
}

.skill-cost {
  position: absolute;
  top: 4px;
  right: 5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(10, 12, 16, 0.88);
  border: 1px solid #592025;
  font-size: 10px;
  font-weight: 800;
  color: #ff8787;
}

.skill-cd {
  position: absolute;
  inset: 0;
  background: rgba(7, 8, 11, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
  color: #fff;
}

.skill-cd.active {
  display: flex;
}

/* Modals */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 9, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-height: 86dvh;
  overflow-y: auto;
  background: linear-gradient(180deg, #161a23 0%, #0e1016 100%);
  border: 1px solid #3c4353;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 800;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.upgrade-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #10131b;
  border: 1px solid #262c3a;
}

.upgrade-info h4 {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 2px;
}

.upgrade-info p {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.35;
}

.upgrade-buy {
  min-width: 70px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #6b262c;
  background: #2b1316;
  color: #ffd8d6;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.upgrade-buy:disabled {
  opacity: 0.45;
  cursor: default;
}

.result-card {
  text-align: center;
}

.result-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
  background: rgba(201, 42, 42, 0.25);
  border: 1px solid var(--crimson-bright);
  color: #ffc9c9;
}

.result-badge.fail {
  background: rgba(73, 80, 87, 0.35);
  border-color: #868e96;
  color: #dee2e6;
}

.result-card h3 {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 12px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.result-stat {
  background: #0d1016;
  border: 1px solid #222834;
  border-radius: 9px;
  padding: 9px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.result-stat .label {
  font-size: 11px;
  color: var(--text-dim);
}

.result-stat strong {
  font-size: 14px;
  font-weight: 800;
}

.result-tip {
  font-size: 12px;
  line-height: 1.45;
  color: #ffd8a8;
  background: rgba(212, 175, 55, 0.08);
  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 14px;
}

/* Comparison Floating Switcher & Scene Loader */
.mode-pill-bar {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(10, 12, 17, 0.9);
  border: 1px solid #353c4c;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
}

.mode-pill-bar.hidden {
  display: none;
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.mode-pill.active {
  background: linear-gradient(180deg, #d93636 0%, #9b1c1c 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(224, 49, 49, 0.5);
}

.scene-loader {
  position: absolute;
  inset: 0;
  background: rgba(6, 7, 11, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 25;
  color: #e9ecef;
  font-size: 12px;
  font-weight: 700;
  transition: opacity 0.25s ease;
}

.scene-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-ring {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255, 59, 48, 0.2);
  border-top-color: #ff3b30;
  animation: spinLoader 0.8s linear infinite;
}

@keyframes spinLoader {
  to {
    transform: rotate(360deg);
  }
}
