:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2129;
  --border: #2d333b;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #c9a227;
  --gold: #e3b341;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --hp: #f85149;
  --energy: #58a6ff;
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;          /* lock the document — no page scroll */
  overscroll-behavior: none; /* no rubber-band / pull-to-refresh */
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;             /* app frame: topbar + scrollable content */
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;            /* fixed chrome bar, never scrolls away */
  z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .5px; }
.user-menu { position: relative; }
.user-menu-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  padding: 4px;
  border-radius: 50%;
}
.user-menu-btn:hover .avatar { box-shadow: 0 0 0 2px var(--gold); }
.avatar { width: 34px; height: 34px; border-radius: 50%; transition: box-shadow .12s ease; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--border);
  font-weight: 800; color: var(--gold);
}
.caret { color: var(--muted); font-size: 12px; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 170px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  z-index: 20;
}
.dropdown-head {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.dropdown-name { font-weight: 700; font-size: 14px; }
.dropdown-item {
  display: block;
  padding: 9px 10px;
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
}
.dropdown-item:hover { background: var(--panel-2); color: var(--red); }

/* Full-screen pages (login hero, bastion hub, battle arena): the shell
   is the app frame, so kill its padding/max-width — the scene fills the
   whole screen edge-to-edge (no dark border around the art). */
body.fullscreen .shell {
  max-width: none;
  padding: 0;
}
body.fullscreen .login-hero,
body.fullscreen .bastion,
body.fullscreen .arena {
  border-radius: 0;
}

/* The ONLY scroller in the app — internal, like a native app body. */
.shell {
  flex: 1;
  min-height: 0;             /* allows flex child to shrink & scroll */
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 60px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  scrollbar-width: thin;
  touch-action: manipulation; /* no double-tap zoom delay */
}

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--gold); color: #1a1200; font-weight: 700; border: none; }
.btn.gold {
  background: linear-gradient(180deg, #f0c75e, var(--gold) 55%, #b8860b);
  color: #1a1200; font-weight: 800; border: none;
  box-shadow: 0 3px 0 #8a6508, 0 6px 18px rgba(227,179,65,.25);
  text-shadow: 0 1px 0 rgba(255,255,255,.25);
}
.btn.gold:hover { filter: brightness(1.08); }
.btn.gold:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a6508; }
.btn.big { padding: 14px 28px; font-size: 18px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.hero { text-align: center; padding: 80px 16px; }
.hero h1 { font-size: 42px; margin: 0 0 8px; }
.tagline { color: var(--muted); font-size: 18px; margin-bottom: 32px; }

/* ---------- login hero (RD prologue banner full-bleed) ---------- */
.login-hero {
  position: relative;
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
  border-radius: 14px;
}
.login-hero-bg {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center 30%;
  image-rendering: pixelated;
  transform: scale(1.02);
}
.login-hero-shade {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(13,17,23,.25) 0%, rgba(13,17,23,.62) 62%, rgba(13,17,23,.92) 100%),
    linear-gradient(180deg, rgba(13,17,23,.2), rgba(13,17,23,.85));
}
.login-hero-content { position: relative; z-index: 1; padding: 24px; }
.login-hero h1 {
  margin: 14px 0 6px;
  font-size: clamp(34px, 7vw, 64px);
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 3px 0 #1a1200, 0 0 22px rgba(227,179,65,.45);
}
.login-hero .tagline { font-size: clamp(15px, 3vw, 20px); margin-bottom: 30px; color: #d7dde3; }
.login-crest img { width: 56px; height: 56px; filter: drop-shadow(0 0 10px rgba(227,179,65,.5)); }

/* ---------- Bastion (realm-aware backdrop + hero showcase) ---------- */
.bastion {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  border-radius: 14px;
}
.bastion-bg {
  position: absolute; inset: -8px;
  background-size: cover;
  background-position: center 30%;
  image-rendering: pixelated;
  animation: kenburns 40s ease-in-out infinite alternate;
}
@keyframes kenburns {
  from { transform: scale(1.02) translateY(0); }
  to   { transform: scale(1.08) translateY(-10px); }
}
.bastion-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg,
      rgba(13,17,23,.12) 0%,
      rgba(13,17,23,.38) 42%,
      rgba(13,17,23,.82) 78%,
      rgba(13,17,23,.96) 100%);
}
.bastion-grain {
  position: absolute; inset: 0;
  opacity: .16;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg,
      rgba(255,255,255,.022) 0 1px, transparent 1px 3px);
}
.bastion-vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 140px rgba(0,0,0,.75);
}

/* HUD strip */
.bastion-hud {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(10,13,18,.88), rgba(10,13,18,.55));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
}
.hud-left { display: flex; gap: 8px; }
.hud-chip {
  background: rgba(0,0,0,.42);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 14px;
}
.hud-xp { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.hud-xp-text { align-self: flex-end; }

/* hero showcase */
.bastion-stage {
  position: relative; z-index: 2;
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
  padding: 20px 16px 16px;
}
.hero-showcase {
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
}
.showcase-emblem {
  width: 92px; height: 92px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent) 65%, transparent));
  margin-bottom: -18px;
  z-index: 2;
}
.showcase-portrait {
  width: 168px; height: 168px;
  border-radius: 16px;
  border: 3px solid var(--accent);
  background: rgba(6,9,13,.72);
  box-shadow: 0 0 0 2px rgba(0,0,0,.6), 0 0 34px color-mix(in srgb, var(--accent) 42%, transparent);
  overflow: hidden;
}
.showcase-portrait img {
  width: 100%; height: 100%;
  image-rendering: pixelated;
}
.showcase-name {
  margin: 16px 0 0;
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 3px 0 #1a1200, 0 0 24px rgba(227,179,65,.4);
}
.showcase-role {
  margin: 4px 0 0;
  color: #d7dde3;
  font-size: 16px;
}
.showcase-quote {
  margin: 10px 0 0;
  color: var(--muted);
  font-style: italic;
  font-size: 15px;
  max-width: 420px;
}

/* location strip */
.location-strip {
  width: min(420px, 100%);
}
.location-link {
  display: flex; align-items: center; gap: 10px;
  background: rgba(10,13,18,.66);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
}
.location-link .travel-hint {
  margin-left: auto;
  color: var(--accent);
  font-weight: 700;
}

/* action dock */
.action-dock {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: min(420px, 100%);
}
.dock-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: rgba(10,13,18,.66);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 8px;
  color: var(--text);
  transition: transform .12s ease, border-color .12s ease;
}
.dock-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.dock-tile.primary {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 25%, transparent);
}
.dock-tile img { width: 34px; height: 34px; }
.dock-tile span { font-weight: 700; font-size: 15px; }

/* ---------- profile (pixel sheet, class accent) ---------- */
.profile { --accent: var(--accent, var(--gold)); }
.profile-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px;
  background: rgba(16,21,27,.85);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 14px;
}
.profile-ident h2 {
  margin: 0 0 4px;
  font-size: 26px;
  color: var(--gold);
  text-shadow: 0 2px 0 #1a1200;
}
.profile-quote {
  margin: 10px 0 0;
  color: var(--muted);
  font-style: italic;
  max-width: 380px;
}
.profile-portrait {
  width: 120px; height: 120px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 3px solid var(--accent);
  background: rgba(6,9,13,.72);
  box-shadow: 0 0 26px color-mix(in srgb, var(--accent) 35%, transparent);
  overflow: hidden;
}
.profile-portrait img {
  width: 100%; height: 100%;
  image-rendering: pixelated;
}
.profile-hud {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 14px;
}
.primary-star { color: var(--gold); }
.alloc-line { margin: 14px 0 10px; }
.alloc-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.alloc-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 6px;
  font-size: 13px;
}
.profile-back { text-align: center; margin-top: 18px; }

/* ---------- pixel bars ---------- */
.bar.pixel { border-radius: 3px; height: 16px; }
.bar.pixel > div { border-radius: 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 18px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* stat grid */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 22px; font-weight: 700; }

/* bars */
.bar { height: 14px; border-radius: 7px; background: #0a0d12; overflow: hidden; border: 1px solid var(--border); }
.bar > div { height: 100%; transition: width .35s ease; }
.bar.hp > div { background: linear-gradient(90deg, #b31d28, var(--hp)); }
.bar.energy > div { background: linear-gradient(90deg, #1f6feb, var(--energy)); }
.bar.xp > div { background: linear-gradient(90deg, #9e6a03, var(--gold)); }

/* battle arena v2 */
.arena {
  position: relative;
  height: 100%;
  display: flex; flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
}
.arena-bg {
  position: absolute; inset: -8px;
  background-size: cover;
  background-position: center 35%;
  image-rendering: pixelated;
  animation: kenburns 50s ease-in-out infinite alternate;
}
.arena-bg-shade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg,
    rgba(13,17,23,.55) 0%, rgba(13,17,23,.25) 40%, rgba(13,17,23,.9) 100%);
}
.arena-vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 150px rgba(0,0,0,.8);
}
.arena-hud {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(10,13,18,.9), rgba(10,13,18,.5));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
}
.arena-loc { font-weight: 800; color: var(--gold); letter-spacing: .5px; }
.arena-stage {
  position: relative; z-index: 2;
  flex: 1;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  align-items: center;
  padding: 18px 16px;
}
.player-panel {
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(10,13,18,.72);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 12px;
  padding: 12px;
}
.player-avatar {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid var(--accent);
  image-rendering: pixelated;
  background: rgba(6,9,13,.72);
}
.player-name { font-weight: 800; font-size: 14px; text-align: center; }
.enemy-panel {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  position: relative;
}
.enemy-panel .mob {
  width: min(260px, 55vw);
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.55));
  animation: mob-idle 2.4s ease-in-out infinite alternate;
}
.enemy-panel.elite .mob {
  filter: drop-shadow(0 0 22px rgba(255,60,60,.75))
          drop-shadow(0 6px 18px rgba(0,0,0,.55));
  animation: mob-idle 2.4s ease-in-out infinite alternate,
             elite-pulse 1.6s ease-in-out infinite alternate;
}
@keyframes mob-idle {
  from { transform: translateY(0); }
  to   { transform: translateY(-8px); }
}
@keyframes elite-pulse {
  from { filter: drop-shadow(0 0 10px rgba(255,60,60,.4)) drop-shadow(0 6px 18px rgba(0,0,0,.55)); }
  to   { filter: drop-shadow(0 0 30px rgba(255,60,60,.9)) drop-shadow(0 6px 18px rgba(0,0,0,.55)); }
}
.mob-name { margin-top: 4px; font-weight: 800; font-size: 18px; }
.elite-badge {
  background: var(--red); color: #fff;
  border-radius: 4px; padding: 2px 6px;
  font-size: 11px; font-weight: 800; letter-spacing: 1px;
  vertical-align: middle; margin-left: 6px;
}
.mob-emoji { font-size: 72px; line-height: 1.2; }
.bar-label { color: var(--muted); font-size: 12px; margin-top: 4px; }
.dmg-pop {
  position: absolute;
  font-weight: 800; font-size: 22px;
  animation: popup-fly 1s ease-out forwards;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 2px 0 rgba(0,0,0,.8);
}
.dmg-pop.enemy { color: #ff5b5b; top: 18%; right: 18%; }
.dmg-pop.player { color: var(--amber); bottom: 22%; left: 12%; }
@keyframes popup-fly {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-46px); }
}
.battle-log {
  position: relative; z-index: 2;
  margin: 0 16px 10px;
  background: rgba(8,11,15,.78);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  min-height: 84px;
  max-height: 140px;
  overflow-y: auto;
  font-size: 13px;
}
.battle-log .line.old { color: var(--muted); }
.battle-log .line.new { color: var(--text); font-weight: 700; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.battle-actions {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 2fr 1fr; gap: 10px;
  padding: 0 16px 16px;
}
.skill-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(180deg, #f0c75e, var(--gold) 55%, #b8860b);
  color: #1a1200; font-weight: 800; border: none;
  box-shadow: 0 3px 0 #8a6508, 0 0 18px color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 14px 12px; font-size: 16px;
}
.skill-btn img { width: 30px; height: 30px; }
.skill-cost { font-size: 12px; opacity: .85; }
.flee-btn { padding: 14px 12px; font-size: 15px; }
.battle-end {
  position: relative; z-index: 2;
  text-align: center;
  padding: 0 16px 16px;
}
.battle-end .panel { margin-bottom: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .arena-stage { grid-template-columns: 110px 1fr; }
}

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.flash.ok { background: #12291a; border: 1px solid var(--green); color: var(--green); }
.flash.err { background: #2a1214; border: 1px solid var(--red); color: var(--red); }

table.sheet { width: 100%; border-collapse: collapse; }
table.sheet td, table.sheet th { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
table.sheet th { color: var(--muted); font-weight: 600; }

.portrait {
  width: 96px; height: 96px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--panel-2);
  float: right;
  margin: 0 0 8px 12px;
  image-rendering: pixelated;
}
.hero-card h2 { margin-top: 0; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { text-align: center; padding: 12px; font-size: 16px; }
.inline-icon {
  width: 20px; height: 20px;
  vertical-align: -4px;
  image-rendering: pixelated;
  display: inline-block;
}

.realms { display: grid; gap: 16px; }
.realm-card {
  position: relative;
  background: rgba(16,21,27,.85);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 14px;
  overflow: hidden;
  transition: transform .12s ease, border-color .12s ease;
}
.realm-card:hover { border-color: var(--accent); }
.realm-card.current {
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 28%, transparent);
}
.realm-card.locked { opacity: .72; }
.realm-art {
  position: relative;
  height: 130px;
  overflow: hidden;
}
.realm-art img {
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}
.realm-art-shade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(13,17,23,.05), rgba(13,17,23,.78));
}
.realm-art-title {
  position: absolute; left: 12px; bottom: 8px;
  font-size: 20px; font-weight: 800;
  color: var(--gold);
  text-shadow: 0 2px 0 #1a1200;
  letter-spacing: .5px;
}
.realm-body { padding: 12px 14px 14px; }
.realm-body .mobs { margin: 2px 0 10px; }
.lock-note { color: var(--amber); font-style: italic; font-size: 13px; }
.small { font-size: 13px; }
.atlas-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.atlas-head h2 { margin: 0; font-size: 24px; color: var(--gold); }

/* shop */
.shop-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 4px;
}
.shop-head h2 { margin: 0; font-size: 24px; color: var(--gold); }
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.item-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: rgba(16,21,27,.85);
  border: 1px solid color-mix(in srgb, var(--rarity) 55%, var(--border));
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
  transition: transform .12s ease, border-color .12s ease;
}
.item-card:hover { transform: translateY(-2px); border-color: var(--rarity); }
.item-icon {
  position: relative;
  width: 72px; height: 72px;
  background: rgba(6,9,13,.72);
  border-radius: 10px;
  border: 1px solid var(--border);
  display: grid; place-items: center;
}
.item-icon img {
  width: 56px; height: 56px;
  image-rendering: pixelated;
}
.rar-badge {
  position: absolute; top: -8px; right: -8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #0a0d12;
  border: 2px solid var(--rarity);
  color: var(--rarity);
  font-size: 12px; font-weight: 800;
  display: grid; place-items: center;
}
.item-name { font-weight: 700; font-size: 14px; }
.item-stats { margin: 0; font-size: 12px; min-height: 30px; }
.buy-btn {
  width: 100%;
  background: var(--gold); color: #1a1200;
  font-weight: 800; border: none;
  box-shadow: 0 2px 0 #8a6508;
}
.small-btn { padding: 4px 10px; font-size: 12px; }
