:root {
  --bg: #070b12;
  --panel: #111824;
  --border: #253247;
  --text: #e6edf3;
  --muted: #8b9bb4;
  --gold: #f5b942;
  --cyan: #58d5ff;
  --purple: #c58aff;
  --crimson: #ff477e;
  --green: #3fb950;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: radial-gradient(circle at top, #131d2e 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;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { font-weight: 900; letter-spacing: 0.16em; color: var(--gold); font-size: 0.96rem; }
.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); }
.cyan { color: var(--cyan); }
.purple { color: var(--purple); }
.crimson { color: var(--crimson); }

.icon-btn {
  position: relative;
  background: #1b2434; 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: #27344a; border-color: #3a4f70; }
.skill-icon-btn.has-avail { border-color: var(--purple); box-shadow: 0 0 10px rgba(197, 138, 255, 0.35); }
.notif-dot {
  position: absolute; top: -3px; right: -3px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--purple); border: 1.5px solid var(--panel);
  box-shadow: 0 0 6px var(--purple);
}

.main-grid { display: grid; grid-template-columns: 1fr 315px; gap: 10px; }
.stage-wrap {
  position: relative; background: #060a10; border: 2px solid var(--border);
  border-radius: 12px; overflow: hidden; aspect-ratio: 660 / 500;
}
#gameCanvas {
  width: 100%; height: 100%; display: block; cursor: crosshair; 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(230, 237, 243, 0.78); pointer-events: none;
  text-shadow: 0 1px 4px #000; padding: 0 10px;
}
.challenge-pill {
  position: absolute; top: 10px; left: 10px; background: rgba(88, 213, 255, 0.16);
  border: 1px solid rgba(88, 213, 255, 0.5); color: var(--cyan); padding: 4px 10px;
  border-radius: 999px; font-size: 0.74rem; font-weight: 700; z-index: 4;
}

/* Sector Boss Stage 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(11, 16, 26, 0.84); border: 1px solid rgba(255, 71, 126, 0.42);
  border-radius: 8px; padding: 5px 9px; min-width: 178px; 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: #f6b7cb; margin-bottom: 4px;
}
.boss-charge-track {
  height: 6px; background: #1d1424; border-radius: 999px; overflow: hidden;
}
.boss-charge-fill {
  height: 100%; background: linear-gradient(90deg, var(--purple), var(--crimson));
  transition: width 0.25s ease;
}
.boss-btn {
  background: linear-gradient(135deg, #d62865 0%, #8f3dff 100%);
  color: #fff; border: 1.5px solid #ff9ec2; border-radius: 8px;
  padding: 7px 12px; font-weight: 900; font-size: 0.76rem; letter-spacing: 0.06em;
  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, 71, 126, 0.9); }
}
.boss-cleared-pill {
  background: rgba(63, 185, 80, 0.18); border: 1px solid rgba(63, 185, 80, 0.55);
  color: #7ee787; padding: 4px 10px; border-radius: 999px; font-size: 0.7rem; font-weight: 800;
  letter-spacing: 0.05em;
}

/* Wordle-Style Share Toast */
.share-toast {
  position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: rgba(14, 21, 34, 0.96); border: 1.5px solid var(--cyan);
  border-radius: 10px; padding: 10px 14px; z-index: 9;
  width: min(92%, 340px); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.65);
  pointer-events: none;
}
.share-toast-head {
  font-size: 0.74rem; font-weight: 900; color: var(--green); 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: #172131; border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 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.85rem; }
.upg-sub { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.upg-cost { font-family: ui-monospace, monospace; font-weight: 800; color: var(--gold); font-size: 0.84rem; white-space: nowrap; }
.upg-count { font-size: 0.72rem; color: var(--cyan); text-align: right; }

.prestige-box {
  background: rgba(197, 138, 255, 0.08); border: 1px solid rgba(197, 138, 255, 0.35);
  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.72rem; color: var(--muted); line-height: 1.35; }
.prestige-actions { display: flex; gap: 6px; }
.prestige-btn {
  flex: 1; background: var(--purple); color: #0b0e14; border: none; border-radius: 7px;
  padding: 8px 6px; font-weight: 800; font-size: 0.76rem; 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.76rem; cursor: pointer; white-space: nowrap;
}
.skills-mini-btn:hover { background: rgba(197, 138, 255, 0.3); }

/* Modals */
.overlay {
  position: absolute; inset: 0; background: rgba(6, 10, 16, 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;
}
.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: #1b2434; 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(88, 213, 255, 0.45); box-shadow: 0 0 28px rgba(88, 213, 255, 0.16); }
.offline-badge {
  display: inline-block; align-self: center; font-size: 0.7rem; font-weight: 900; letter-spacing: 0.09em;
  color: var(--cyan); background: rgba(88, 213, 255, 0.14); border: 1px solid rgba(88, 213, 255, 0.4);
  padding: 4px 10px; border-radius: 999px;
}
.offline-reward-box {
  background: #0a101b; border: 1px solid rgba(245, 185, 66, 0.45); border-radius: 10px;
  padding: 12px; display: flex; flex-direction: column; gap: 4px;
}
.offline-ore {
  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(--cyan); font-weight: 700; }

/* Dark Matter 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: #0b101a; 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: #161f30; 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(63, 185, 80, 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(--cyan); 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(--green); }

.primary-btn {
  background: var(--gold); color: #0a0e14; 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(88, 213, 255, 0.14); color: var(--cyan); border: 1px solid rgba(88, 213, 255, 0.45);
  border-radius: 8px; padding: 9px 14px; font-weight: 700; cursor: pointer; font-size: 0.82rem;
}
.ok-btn {
  background: var(--green); color: #07120a; border: none; border-radius: 6px;
  padding: 7px 12px; font-weight: 800; font-size: 0.78rem; cursor: pointer;
}
.lb-list {
  background: #090e17; 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; }
.lb-submit { display: flex; gap: 6px; }
.lb-submit input {
  flex: 1; background: #090e17; 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: #090e17; color: var(--cyan); 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(88, 213, 255, 0.12); border: 1px solid rgba(88, 213, 255, 0.4);
  color: var(--cyan); 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; }
  .skills-grid { grid-template-columns: 1fr; }
  .stage-wrap { aspect-ratio: 660 / 540; }
  .boss-charge-wrap { min-width: 145px; }
}
