:root {
  --bg: #090714;
  --panel: #141026;
  --panel-hi: #1d1736;
  --border: #2f2552;
  --text: #f1ecff;
  --muted: #9e93c4;
  --gold: #f5b942;
  --amber: #ff9f43;
  --emerald: #34e89e;
  --purple: #c58aff;
  --crimson: #ff477e;
  --green: #3fb950;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  background: radial-gradient(circle at top, #1f163b 0%, var(--bg) 72%);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  user-select: none;
}
.shell { width: 100%; max-width: 980px; display: flex; flex-direction: column; gap: 10px; }
.hud {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 9px 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { font-weight: 900; letter-spacing: 0.14em; color: var(--gold); font-size: 0.96rem; text-shadow: 0 0 12px rgba(245, 185, 66, 0.3); }
.stat { display: flex; align-items: center; gap: 6px; }
.lbl { font-size: 0.68rem; font-weight: 700; color: var(--muted); letter-spacing: 0.08em; }
.val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.98rem; font-weight: 800; }
.gold { color: var(--gold); }
.emerald { color: var(--emerald); }
.purple { color: var(--purple); }
.crimson { color: var(--crimson); }

.icon-btn {
  position: relative;
  background: var(--panel-hi); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; width: 34px; height: 30px; cursor: pointer; font-size: 0.92rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: #2b224d; border-color: #513e8a; }
.skill-icon-btn.has-avail { border-color: var(--purple); box-shadow: 0 0 10px rgba(197, 138, 255, 0.45); }
.notif-dot {
  position: absolute; top: -3px; right: -3px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--emerald); border: 1.5px solid var(--panel);
  box-shadow: 0 0 6px var(--emerald);
}

.main-grid { display: grid; grid-template-columns: 1fr 320px; gap: 10px; }
.stage-wrap {
  position: relative; background: #0c081a; border: 2px solid var(--border);
  border-radius: 12px; overflow: hidden; aspect-ratio: 660 / 500;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.48);
}
#gameCanvas {
  width: 100%; height: 100%; display: block; cursor: pointer; touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.stage-hint {
  position: absolute; bottom: 8px; left: 0; right: 0; text-align: center;
  font-size: 0.74rem; color: rgba(241, 236, 255, 0.84); pointer-events: none;
  text-shadow: 0 1px 5px #000, 0 0 10px rgba(0, 0, 0, 0.9); padding: 0 10px;
}
.challenge-pill {
  position: absolute; top: 10px; left: 10px; background: rgba(52, 232, 158, 0.16);
  border: 1px solid rgba(52, 232, 158, 0.55); color: var(--emerald); padding: 4px 10px;
  border-radius: 999px; font-size: 0.74rem; font-weight: 700; z-index: 4;
}

/* Realm Boss Crucible HUD */
.boss-hud {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.boss-charge-wrap {
  background: rgba(14, 9, 28, 0.86); border: 1px solid rgba(255, 71, 126, 0.45);
  border-radius: 8px; padding: 5px 9px; min-width: 182px; backdrop-filter: blur(2px);
}
.boss-charge-meta {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 0.65rem; font-weight: 800; letter-spacing: 0.06em; color: #f9b8cd; margin-bottom: 4px;
}
.boss-charge-track {
  height: 6px; background: #211430; border-radius: 999px; overflow: hidden;
}
.boss-charge-fill {
  height: 100%; background: linear-gradient(90deg, var(--amber), var(--crimson));
  transition: width 0.25s ease;
}
.boss-btn {
  background: linear-gradient(135deg, #d62865 0%, #ff7b00 100%);
  color: #fff; border: 1.5px solid #ffd19c; border-radius: 8px;
  padding: 7px 12px; font-weight: 900; font-size: 0.76rem; letter-spacing: 0.05em;
  cursor: pointer; box-shadow: 0 0 16px rgba(255, 71, 126, 0.55);
  animation: bossPulse 1.5s infinite ease-in-out;
}
.boss-btn:hover { filter: brightness(1.12); transform: scale(1.03); }
@keyframes bossPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255, 71, 126, 0.45); }
  50% { box-shadow: 0 0 22px rgba(255, 159, 67, 0.9); }
}
.boss-cleared-pill {
  background: rgba(52, 232, 158, 0.18); border: 1px solid rgba(52, 232, 158, 0.55);
  color: var(--emerald); padding: 4px 10px; border-radius: 999px; font-size: 0.7rem; font-weight: 800;
  letter-spacing: 0.05em;
}

/* Post-Boss Victory Share Banner */
.boss-victory-banner {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  width: min(92%, 345px);
  background: linear-gradient(135deg, rgba(28, 16, 48, 0.96) 0%, rgba(16, 26, 36, 0.96) 100%);
  border: 1.5px solid var(--gold); border-radius: 11px; padding: 10px 12px; z-index: 8;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.72), 0 0 18px rgba(245, 185, 66, 0.35);
}
.bv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bv-title { font-size: 0.78rem; font-weight: 900; letter-spacing: 0.07em; color: var(--gold); }
.bv-close {
  background: var(--panel-hi); border: 1px solid var(--border); color: var(--muted);
  border-radius: 5px; width: 24px; height: 24px; cursor: pointer; font-weight: 800; font-size: 0.75rem;
}
.bv-close:hover { color: var(--text); border-color: var(--muted); }
.bv-sub { font-size: 0.73rem; color: var(--text); line-height: 1.35; }
.bv-share-btn {
  background: linear-gradient(135deg, #34e89e 0%, #c58aff 100%);
  color: #090714; border: none; border-radius: 7px; padding: 8px 10px;
  font-weight: 900; font-size: 0.76rem; letter-spacing: 0.05em; cursor: pointer;
}
.bv-share-btn:hover { filter: brightness(1.08); }

/* Wordle-Style Share Toast */
.share-toast {
  position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: rgba(18, 13, 36, 0.96); border: 1.5px solid var(--emerald);
  border-radius: 10px; padding: 10px 14px; z-index: 9;
  width: min(92%, 350px); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.68);
  pointer-events: none;
}
.share-toast-head {
  font-size: 0.74rem; font-weight: 900; color: var(--emerald); letter-spacing: 0.08em; margin-bottom: 5px;
}
.share-toast-body {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem; line-height: 1.4; color: var(--text); white-space: pre-wrap; word-break: break-word;
}

.shop {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.shop-title { font-size: 0.76rem; font-weight: 800; letter-spacing: 0.12em; color: var(--muted); }
.upgrades-list { display: flex; flex-direction: column; gap: 7px; flex: 1; }
.upg-btn {
  background: var(--panel-hi); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 10px; color: var(--text); text-align: left; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  transition: border-color 0.15s, transform 0.08s;
}
.upg-btn:hover:not(:disabled) { border-color: var(--gold); transform: translateY(-1px); }
.upg-btn:disabled { opacity: 0.48; cursor: not-allowed; }
.upg-name { font-weight: 800; font-size: 0.84rem; }
.upg-sub { font-size: 0.71rem; color: var(--muted); margin-top: 2px; }
.upg-cost { font-family: ui-monospace, monospace; font-weight: 800; color: var(--gold); font-size: 0.83rem; white-space: nowrap; text-align: right; }
.upg-count { font-size: 0.71rem; color: var(--emerald); text-align: right; }

/* Daily Alchemist Crate */
.daily-crate-box {
  background: linear-gradient(135deg, rgba(245, 185, 66, 0.15) 0%, rgba(52, 232, 158, 0.11) 100%);
  border: 1.5px solid rgba(245, 185, 66, 0.62); border-radius: 10px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 0 14px rgba(245, 185, 66, 0.16);
}
.daily-crate-box.claimed {
  background: rgba(24, 19, 44, 0.85); border-color: var(--border); box-shadow: none;
}
.crate-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.crate-title { font-size: 0.72rem; font-weight: 900; letter-spacing: 0.07em; color: var(--gold); }
.daily-crate-box.claimed .crate-title { color: var(--muted); }
.crate-streak {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.67rem; font-weight: 900;
  color: #0b0816; background: var(--gold); padding: 2px 7px; border-radius: 999px;
}
.daily-crate-box.claimed .crate-streak {
  background: rgba(52, 232, 158, 0.2); color: var(--emerald); border: 1px solid rgba(52, 232, 158, 0.5);
}
.daily-crate-btn {
  background: linear-gradient(135deg, #f5b942 0%, #ff9500 100%);
  color: #0b0816; border: 1px solid #ffe08a; border-radius: 7px; padding: 7px 10px;
  font-weight: 900; font-size: 0.74rem; letter-spacing: 0.03em; cursor: pointer;
  animation: crateGlow 1.8s infinite ease-in-out; transition: transform 0.1s, filter 0.15s;
}
.daily-crate-btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.daily-crate-btn:disabled {
  animation: none; background: var(--panel-hi); border-color: var(--border);
  color: var(--emerald); cursor: default;
}
@keyframes crateGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(245, 185, 66, 0.45); }
  50% { box-shadow: 0 0 18px rgba(245, 185, 66, 0.9); }
}
.crate-countdown {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.69rem;
  color: var(--emerald); text-align: center; font-weight: 700;
}

.prestige-box {
  background: rgba(197, 138, 255, 0.09); border: 1px solid rgba(197, 138, 255, 0.36);
  border-radius: 9px; padding: 10px; display: flex; flex-direction: column; gap: 6px;
}
.prestige-head { display: flex; justify-content: space-between; font-size: 0.78rem; font-weight: 800; }
.prestige-desc { font-size: 0.71rem; color: var(--muted); line-height: 1.35; }
.prestige-actions { display: flex; gap: 6px; }
.prestige-btn {
  flex: 1; background: var(--purple); color: #0c0716; border: none; border-radius: 7px;
  padding: 8px 6px; font-weight: 800; font-size: 0.75rem; cursor: pointer;
}
.prestige-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.skills-mini-btn {
  background: rgba(197, 138, 255, 0.18); color: var(--purple); border: 1px solid rgba(197, 138, 255, 0.55);
  border-radius: 7px; padding: 8px 10px; font-weight: 800; font-size: 0.75rem; cursor: pointer; white-space: nowrap;
}
.skills-mini-btn:hover { background: rgba(197, 138, 255, 0.3); }

/* Modals */
.overlay {
  position: absolute; inset: 0; background: rgba(9, 6, 20, 0.88); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 12;
  overflow-y: auto;
}
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; max-width: 430px; width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: 11px; max-height: 100%; overflow-y: auto;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.65);
}
.card h1, .card h2 { color: var(--gold); letter-spacing: 0.08em; font-size: 1.25rem; }
.card p { font-size: 0.84rem; color: var(--muted); line-height: 1.4; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-head h2 { font-size: 1.02rem; color: var(--purple); text-align: left; }
.close-x {
  background: var(--panel-hi); border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; width: 28px; height: 28px; cursor: pointer; font-weight: 800;
}
.close-x:hover { color: var(--text); border-color: var(--muted); }

/* Offline Welcome Back Card */
.offline-card { border-color: rgba(52, 232, 158, 0.45); box-shadow: 0 0 28px rgba(52, 232, 158, 0.16); }
.offline-badge {
  display: inline-block; align-self: center; font-size: 0.7rem; font-weight: 900; letter-spacing: 0.09em;
  color: var(--emerald); background: rgba(52, 232, 158, 0.14); border: 1px solid rgba(52, 232, 158, 0.42);
  padding: 4px 10px; border-radius: 999px;
}
.offline-reward-box {
  background: #0d0a1a; border: 1px solid rgba(245, 185, 66, 0.45); border-radius: 10px;
  padding: 12px; display: flex; flex-direction: column; gap: 4px;
}
.offline-gold {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.55rem; font-weight: 900; color: var(--gold);
}
.offline-meta { font-size: 0.74rem; color: var(--emerald); font-weight: 700; }

/* Arcane Essence Skill Tree Card */
.skills-card { max-width: 580px; padding: 14px 16px; gap: 8px; }
.skills-status {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px;
  background: #0e0a1d; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 0.78rem;
}
.skills-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; text-align: left;
}
.skill-node {
  background: var(--panel-hi); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 9px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  color: var(--text); text-align: left; cursor: pointer; transition: border-color 0.15s, transform 0.08s;
}
.skill-node:hover:not(:disabled) { border-color: var(--purple); transform: translateY(-1px); }
.skill-node:disabled { opacity: 0.56; cursor: not-allowed; }
.skill-node.maxed { border-color: rgba(52, 232, 158, 0.55); opacity: 0.92; }
.skill-top { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.skill-title { font-weight: 800; font-size: 0.8rem; }
.skill-lvl { font-family: ui-monospace, monospace; font-size: 0.7rem; color: var(--emerald); font-weight: 800; }
.skill-desc { font-size: 0.69rem; color: var(--muted); line-height: 1.3; }
.skill-foot { display: flex; justify-content: space-between; align-items: center; font-size: 0.72rem; font-weight: 800; }
.skill-effect { color: var(--gold); font-family: ui-monospace, monospace; }
.skill-cost { color: var(--purple); font-family: ui-monospace, monospace; }
.skill-cost.max { color: var(--emerald); }

.primary-btn {
  background: linear-gradient(135deg, #f5b942 0%, #ff9f43 100%); color: #0c0716; border: none; border-radius: 8px;
  padding: 10px 16px; font-weight: 900; letter-spacing: 0.08em; cursor: pointer; font-size: 0.85rem;
}
.primary-btn:hover { filter: brightness(1.06); }
.sec-btn {
  background: rgba(52, 232, 158, 0.14); color: var(--emerald); border: 1px solid rgba(52, 232, 158, 0.45);
  border-radius: 8px; padding: 9px 14px; font-weight: 700; cursor: pointer; font-size: 0.82rem;
}
.ok-btn {
  background: var(--emerald); color: #06140e; border: none; border-radius: 6px;
  padding: 7px 12px; font-weight: 800; font-size: 0.78rem; cursor: pointer;
}
.lb-list {
  background: #0d0a1a; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-family: ui-monospace, monospace; font-size: 0.78rem; text-align: left; display: flex; flex-direction: column; gap: 4px;
}
.lb-row { display: flex; justify-content: space-between; gap: 8px; }
.lb-submit { display: flex; gap: 6px; }
.lb-submit input {
  flex: 1; min-width: 0; background: #0d0a1a; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; font-size: 0.8rem;
}
.btn-row { display: flex; flex-direction: column; gap: 8px; }
.share-out {
  background: #0d0a1a; color: var(--emerald); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 0.72rem; font-family: monospace; text-align: center;
}
.challenge-box {
  background: rgba(52, 232, 158, 0.12); border: 1px solid rgba(52, 232, 158, 0.42);
  color: var(--emerald); padding: 8px; border-radius: 8px; font-size: 0.82rem; font-weight: 700;
}
.footer { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.76rem; color: var(--muted); padding: 0 4px; }
.footer a { color: var(--gold); text-decoration: none; font-weight: 700; }
.hidden { display: none !important; }

@media (max-width: 780px) {
  .main-grid { grid-template-columns: 1fr; }
  .hud { padding: 8px 10px; gap: 8px; }
  .brand { display: none; }
}
@media (max-width: 520px) {
  body { padding: 6px; }
  .hud-left, .hud-right { gap: 8px; }
  .skills-grid { grid-template-columns: 1fr; }
  .stage-wrap { aspect-ratio: 660 / 540; }
  .boss-charge-wrap { min-width: 150px; }
}
