:root {
  --bg-deep: #0f2136;
  --glass: rgba(15, 29, 48, 0.72);
  --glass-border: rgba(226, 240, 255, 0.24);
  --gold: #f6d468;
  --cyan: #52f0ff;
  --text: #f5f8ff;
  --muted: #b6c8de;
  --header-h: 52px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

[data-xgh-host] .masthead-left {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a4b84;
  color: var(--text);
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.masthead {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(10, 24, 42, 0.62), rgba(10, 24, 42, 0));
  pointer-events: none;
}

.masthead-left,
.masthead-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.masthead-left h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.hdr-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.hdr-btn:hover {
  border-color: var(--gold);
}

#viewport-root {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

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

#damage-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  overflow: hidden;
}

.dmg-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  font-size: 20px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85), 0 0 10px rgba(0, 0, 0, 0.5);
  animation: popUp 0.92s ease-out forwards;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dmg-pop.crit {
  font-size: 26px;
}

.dmg-react-tag {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@keyframes popUp {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.75); }
  18% { opacity: 1; transform: translate(-50%, -60%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -155%) scale(0.95); }
}

/* Live Cinematic Title Overlay */
#title-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 28px 18px 46px;
  background: radial-gradient(circle at 50% 42%, rgba(16, 40, 74, 0.06), rgba(10, 22, 42, 0.48));
  pointer-events: auto;
}

.title-card {
  text-align: center;
  padding: 22px 34px 26px;
  border-radius: 20px;
  background: rgba(14, 28, 48, 0.62);
  border: 1px solid rgba(255, 232, 168, 0.42);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 48px rgba(6, 18, 36, 0.45);
  max-width: 92vw;
}

.title-crest {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--gold);
  margin-bottom: 6px;
}

.title-card h2 {
  margin: 0;
  font-size: clamp(26px, 4.4vw, 40px);
  letter-spacing: 0.1em;
  color: #ffffff;
  text-shadow: 0 3px 16px rgba(40, 145, 255, 0.5);
}

.title-card p {
  margin: 6px 0 18px;
  font-size: 14px;
  color: #dbeeff;
}

.start-cta {
  padding: 12px 34px;
  border-radius: 999px;
  border: 1px solid #fff3c4;
  background: linear-gradient(135deg, #f6d468, #e69e3a);
  color: #1c1810;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(246, 196, 83, 0.45);
  transition: transform 0.16s ease;
}

.start-cta:hover {
  transform: translateY(-2px) scale(1.02);
}

/* Hide gameplay HUD during clean cinematic title panorama */
body.title-active #hud {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.hud-top-left {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  left: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: auto;
}

.minimap-frame {
  position: relative;
  width: 108px;
  height: 108px;
  padding: 0;
  border-radius: 50%;
  border: 2.5px solid rgba(246, 212, 104, 0.85);
  background: #14324c;
  box-shadow: 0 8px 22px rgba(6, 18, 36, 0.48);
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}

#minimap-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.minimap-tag {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 8px;
  background: rgba(12, 26, 42, 0.8);
  color: var(--gold);
}

.region-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.biome-title {
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
}

.meta-row,
.quick-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-pill,
.mini-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: #eaf4ff;
  backdrop-filter: blur(6px);
}

.mini-pill {
  cursor: pointer;
}

.mini-pill:hover {
  border-color: var(--gold);
}

.progress-line {
  font-size: 11px;
  color: #f3f9ff;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.72);
}

/* Top-Center Boss / Trial / Toast */
.hud-top-center {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(440px, 60vw);
}

.boss-bar {
  width: 100%;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid rgba(255, 198, 128, 0.45);
  backdrop-filter: blur(8px);
}

.boss-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 5px;
}

.boss-track {
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff5168, #ffb347);
  transition: width 0.12s ease;
}

.trial-banner,
.toast-banner {
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(14, 28, 48, 0.86);
  border: 1px solid var(--cyan);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.38);
}

/* Right Edge 4-Hero Party Swap */
.party-list {
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-54%);
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: auto;
}

.party-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 148px;
  padding: 6px 8px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.party-slot.active {
  border-color: var(--gold);
  background: rgba(26, 48, 76, 0.88);
  transform: translateX(-5px);
}

.slot-key {
  font-size: 11px;
  font-weight: 800;
  color: var(--gold);
  width: 14px;
}

.slot-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.slot-name {
  font-size: 12px;
  font-weight: 700;
}

.slot-hp-track {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.slot-hp-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: #67e68b;
}

.slot-el {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #0e1e2e;
  opacity: 0.72;
}

.slot-el.full {
  opacity: 1;
  box-shadow: 0 0 12px #fff;
}

/* Arc Stamina Indicator */
.stamina-wrap {
  position: fixed;
  left: 55%;
  top: 46%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* Bottom Center HP & Interact */
.hud-bottom-center {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: min(360px, 56vw);
}

.interact-pill {
  pointer-events: auto;
  padding: 7px 18px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: rgba(16, 30, 50, 0.88);
  color: #fff6d6;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
}

.hero-hp-box {
  width: 100%;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
}

.hero-hp-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.hp-track {
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #56e287, #9af77a);
  transition: width 0.15s ease;
}

.controls-hint {
  font-size: 11px;
  color: rgba(240, 248, 255, 0.86);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  text-align: center;
  white-space: nowrap;
}

/* Bottom-Right Action Skills */
.action-cluster {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
}

.skill-btn {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.36);
  background: var(--glass);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  overflow: hidden;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.skill-btn.cooling {
  opacity: 0.6;
}

.burst-btn {
  width: 60px;
  height: 60px;
}

.burst-btn.ready {
  box-shadow: 0 0 18px rgba(100, 240, 255, 0.65);
}

.burst-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  opacity: 0.38;
  transition: height 0.2s ease;
}

.skill-txt {
  position: relative;
  z-index: 2;
}

.atk-btn {
  width: 64px;
  height: 64px;
  font-size: 22px;
  border-color: var(--gold);
  background: rgba(246, 212, 104, 0.24);
}

.sub-btn {
  width: 44px;
  height: 44px;
  font-size: 16px;
}

/* Mobile Touch Joystick */
.touch-joystick {
  position: fixed;
  left: 20px;
  bottom: 22px;
  display: none;
  pointer-events: auto;
}

.joy-base {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(14, 30, 50, 0.42);
  border: 2px solid rgba(255, 255, 255, 0.26);
  position: relative;
}

.joy-knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(246, 212, 104, 0.78);
  border: 2px solid #fff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 18, 32, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: rgba(16, 30, 48, 0.96);
  border: 1px solid rgba(246, 212, 104, 0.45);
  border-radius: 18px;
  padding: 18px 20px;
  color: #fff;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
}

.modal-wide {
  width: min(760px, 95vw);
}

.modal-narrow {
  width: min(360px, 90vw);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
  color: var(--gold);
}

.close-x {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

.modal-tip {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.map-layout {
  display: flex;
  gap: 14px;
  overflow: auto;
}

#world-map-canvas {
  width: min(400px, 60vw);
  height: min(400px, 60vw);
  border-radius: 12px;
  border: 2px solid rgba(246, 212, 104, 0.45);
  cursor: pointer;
  flex-shrink: 0;
}

.spire-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 180px;
}

.spire-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
}

.spire-btn.unlocked:hover {
  border-color: var(--cyan);
}

.spire-btn.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.spire-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cyan);
}

.spire-btn.locked .spire-dot {
  background: #78889c;
}

.spire-name {
  flex: 1;
  font-weight: 600;
}

.spire-tag {
  font-size: 11px;
  color: var(--cyan);
}

.tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.06);
  color: #d8e8fa;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--gold);
  color: #1c1810;
  border-color: var(--gold);
}

.modal-scroll {
  overflow-y: auto;
  padding-right: 4px;
}

.mat-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 10px;
}

.rpg-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rpg-card.active {
  border-color: var(--gold);
  background: rgba(246, 212, 104, 0.1);
}

.rpg-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.el-pill {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid;
}

.rpg-sub,
.rpg-cost,
.rpg-stats {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.action-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #f6d468, #e6a43e);
  color: #1c1810;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.action-btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid var(--glass-border);
}

.action-btn.danger {
  background: rgba(255, 86, 104, 0.25);
  color: #ffb8c0;
  border: 1px solid #ff5668;
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row.wrap {
  flex-wrap: wrap;
}

.options-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.opt-group h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--gold);
}

#save-code-box {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(8, 16, 28, 0.8);
  color: #a6f2ff;
  padding: 8px;
  font-family: monospace;
  font-size: 12px;
  margin-bottom: 8px;
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guide-sec h3 {
  margin: 0 0 5px;
  font-size: 14px;
  color: var(--gold);
}

.guide-sec p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.6;
  color: #dcebf8;
}

/* Responsive Mobile / Coarse Pointer Adaptation */
@media (hover: none) and (pointer: coarse), (max-width: 900px) {
  .touch-joystick {
    display: block;
  }
  .controls-hint {
    display: none;
  }
  .minimap-frame {
    width: 78px;
    height: 78px;
  }
  .party-slot {
    width: 112px;
    padding: 5px 6px;
  }
  .hud-bottom-center {
    bottom: 10px;
    width: min(240px, 46vw);
  }
  .skill-btn {
    width: 46px;
    height: 46px;
  }
  .atk-btn {
    width: 56px;
    height: 56px;
  }
  .map-layout {
    flex-direction: column;
    align-items: center;
  }
  #world-map-canvas {
    width: min(320px, 82vw);
    height: min(320px, 82vw);
  }
}

@media (max-width: 600px) {
  .progress-line {
    display: none;
  }
  .hud-bottom-center {
    bottom: 146px;
    width: min(268px, 74vw);
  }
  .touch-joystick {
    left: 14px;
    bottom: 18px;
  }
  .joy-base {
    width: 98px;
    height: 98px;
  }
  .action-cluster {
    display: grid;
    grid-template-columns: repeat(3, auto);
    align-items: center;
    justify-items: center;
    gap: 8px;
    right: 12px;
    bottom: 16px;
  }
  .atk-btn {
    grid-column: 3;
    grid-row: 2;
    width: 56px;
    height: 56px;
  }
  .burst-btn {
    grid-column: 1;
    grid-row: 1;
    width: 46px;
    height: 46px;
  }
  #btn-skill {
    grid-column: 2;
    grid-row: 1;
    width: 46px;
    height: 46px;
  }
  #btn-jump {
    grid-column: 3;
    grid-row: 1;
    width: 42px;
    height: 42px;
  }
  #btn-dash {
    grid-column: 2;
    grid-row: 2;
    width: 42px;
    height: 42px;
  }
  .party-list {
    right: 8px;
    top: 40%;
  }
}
