/* ===================== tokens ===================== */
:root {
  --bg-0: #0B0B0C;
  --bg-1: #1C1C1E;
  --surface: #2C2C2E;
  --beige: #E8DCC8;
  --ink: #F5F5F7;
  --ink-dim: #9a9a9e;
  --accent: #FF3B30;
  --steel: #A2AAAD;
  --money: #30D158;
  --gold: #FFD60A;
  --line: #333335;

  --font-display: "Press Start 2P", ui-monospace, monospace;
  --font-body: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius: 2px;
  --container: 640px;
  --header-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  background-color: #101216;
  background-image:
    linear-gradient(45deg, #24262b 25%, transparent 25%),
    linear-gradient(-45deg, #24262b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #24262b 75%),
    linear-gradient(-45deg, transparent 75%, #24262b 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  background-attachment: fixed;
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 10 10" shape-rendering="crispEdges"><rect x="0" y="0" width="1" height="7" fill="%23F5F5F7" stroke="%230B0B0C" stroke-width="0.3"/><rect x="1" y="5" width="1" height="1" fill="%23F5F5F7"/><rect x="1" y="6" width="1" height="1" fill="%23F5F5F7"/><rect x="2" y="6" width="1" height="1" fill="%23F5F5F7"/><rect x="1" y="1" width="4" height="1" fill="%23F5F5F7"/><rect x="1" y="2" width="1" height="4" fill="%23F5F5F7"/><rect x="2" y="4" width="3" height="1" fill="%23F5F5F7"/><rect x="4" y="1" width="1" height="3" fill="%23F5F5F7"/></svg>') 0 0, auto;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; }
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 999;
  background: var(--ink); color: var(--bg-0); padding: 10px 16px;
}

/* ===================== the "app window" on the desktop ===================== */
.mac-frame {
  max-width: 1040px;
  margin: 28px auto;
  border: 3px solid var(--ink);
  box-shadow: 10px 10px 0 rgba(0,0,0,0.55);
  background: var(--bg-0);
  position: relative;
  z-index: 1;
}
.mac-frame-bar {
  height: 30px;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: repeating-linear-gradient(to bottom, #0B0B0C 0, #0B0B0C 2px, var(--beige) 2px, var(--beige) 4px);
  border-bottom: 3px solid var(--ink);
}
.mac-frame-dot {
  width: 12px; height: 12px; flex-shrink: 0;
  background: var(--beige); border: 1.5px solid var(--ink);
}
.mac-frame-title {
  margin: 0 auto;
  background: var(--beige); color: #1a1a1a;
  padding: 1px 10px;
  font-family: var(--font-display); font-size: 10px;
  white-space: nowrap;
}
.mac-frame-body { background: var(--bg-0); }

@media (max-width: 700px) {
  .mac-frame { margin: 0; border-left: none; border-right: none; border-top: none; box-shadow: none; }
}
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid var(--money); outline-offset: 2px; }

.section-inner { max-width: var(--container); margin: 0 auto; padding: 0 20px; }

/* ===================== fx overlays ===================== */
.fx-grain {
  position: fixed; inset: 0; z-index: 9998; pointer-events: none;
  opacity: 0.04; mix-blend-mode: overlay;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23n)"/></svg>');
}
.fx-scanlines {
  position: fixed; inset: 0; z-index: 9997; pointer-events: none;
  opacity: 0.03;
  background: repeating-linear-gradient(to bottom, #000 0px, #000 1px, transparent 1px, transparent 3px);
}

/* ===================== topbar (the only chrome) ===================== */
.topbar {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-0);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon {
  width: 26px; height: 26px; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
  border-radius: 3px;
}
.brand-text { font-family: var(--font-display); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.btn-buy {
  font-family: var(--font-display); font-size: 10px;
  background: var(--accent); color: #fff;
  padding: 9px 14px; border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}
.btn-buy:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.icon-link { font-size: 16px; color: var(--ink-dim); }
.icon-link:hover { color: var(--ink); }

/* ===================== stage ===================== */
.stage {
  min-height: calc(100svh - var(--header-h));
  min-height: calc(100vh - var(--header-h));
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 16px 28px;
  text-align: center;
  background: radial-gradient(ellipse 60% 45% at 50% 42%, rgba(255,255,255,0.05), transparent 70%);
}

.stage-stats {
  width: 100%; max-width: 680px;
  display: flex; gap: 18px; align-items: flex-end;
  margin-bottom: 10px;
}
.stat-block { display: flex; flex-direction: column; gap: 6px; align-items: center; min-width: 64px; }
.stat-k { font-family: var(--font-display); font-size: 8px; letter-spacing: 0.04em; color: var(--steel); text-transform: uppercase; }
.stat-v { font-family: var(--font-display); font-size: 15px; color: var(--gold); }
.stat-bar-block { min-width: 96px; }
.stat-bar { width: 100%; height: 8px; background: #000; border: 1px solid var(--line); }
.stat-bar-fill { height: 100%; width: 0%; transition: width 0.3s ease; }
.energy-fill { background: var(--gold); }
.rank-fill { background: var(--money); }

/* ===================== the game viewport ===================== */
.game-viewport {
  position: relative;
  width: 100%; max-width: 760px;
  aspect-ratio: 16 / 9;
  max-height: 60vh;
  border: 2px solid var(--line);
  overflow: hidden;
  background: #0a0e18;
  touch-action: none;
  margin-bottom: 12px;
  outline: none;
}
#game-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
  cursor: default;
}

.interact-hint {
  position: absolute; right: 10px; bottom: 10px; z-index: 6;
  background: var(--beige); color: #1a1a1a; border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  padding: 7px 10px; font-family: var(--font-display); font-size: 9px;
  pointer-events: none;
}
.interact-hint .kbd {
  display: inline-block; background: var(--ink); color: var(--beige);
  padding: 1px 5px; margin-right: 5px; border-radius: 2px;
}

.joystick-zone {
  position: absolute; left: 14px; bottom: 14px; z-index: 6;
  width: 92px; height: 92px;
  display: none;
}
.joystick-base {
  position: relative; width: 100%; height: 100%; border-radius: 50%;
  background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.25);
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 40px;
  margin-left: -20px; margin-top: -20px; border-radius: 50%;
  background: rgba(255,255,255,0.35); border: 2px solid var(--ink);
}
.interact-btn-mobile {
  position: absolute; right: 16px; bottom: 16px; z-index: 6;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; border: 2px solid var(--ink);
  font-family: var(--font-display); font-size: 14px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.interact-btn-mobile.active { background: var(--money); }

@media (pointer: coarse) {
  .joystick-zone, .interact-btn-mobile { display: flex; }
}

.world-hint {
  font-size: 11.5px; color: var(--ink-dim); margin-bottom: 2px;
}
.kbd {
  display: inline-block; background: var(--bg-1); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 2px; font-family: var(--font-display); font-size: 8px;
}

.speech-bubble {
  position: absolute; top: 0; left: 0; z-index: 7;
  transform: translate(-50%, -100%);
  background: var(--beige); color: #1a1a1a;
  border: 2px solid var(--ink);
  padding: 7px 10px;
  font-size: 12px; font-weight: 600;
  max-width: min(60%, 260px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
  white-space: normal;
}
.speech-bubble::after {
  content: ""; position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
  border: 8px solid transparent; border-top-color: var(--ink);
}
.speech-bubble::before {
  content: ""; position: absolute; bottom: -5.5px; left: 50%; transform: translateX(-50%);
  border: 6.5px solid transparent; border-top-color: var(--beige); z-index: 1;
}
.speech-bubble.show { opacity: 1; }

.cash-pop {
  position: absolute; z-index: 7;
  transform: translate(-50%, -50%);
  font-family: var(--font-display); font-size: 12px; color: var(--money);
  pointer-events: none; animation: cash-float 0.9s ease forwards;
  white-space: nowrap;
}
@keyframes cash-float {
  0% { opacity: 0; transform: translate(-50%, -50%); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, calc(-50% - 34px)); }
}

.inventory-row {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  min-height: 30px; margin-bottom: 14px; max-width: 420px;
}
.inv-chip {
  font-size: 15px; background: var(--surface); border: 1px solid var(--line);
  width: 30px; height: 30px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.inv-chip .inv-count {
  position: absolute; bottom: -5px; right: -5px;
  background: var(--accent); color: #fff;
  font-family: var(--font-display); font-size: 8px;
  border-radius: 999px; min-width: 15px; height: 15px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--bg-0);
}

.shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.scroll-hint {
  margin-top: 22px; font-size: 11.5px; color: var(--ink-dim);
  border-bottom: 1px dashed var(--line);
}
.scroll-hint:hover { color: var(--ink); }

/* ===================== footer (compact, secondary) ===================== */
.footer-compact { border-top: 1px solid var(--line); padding: 44px 0 40px; }
.ca-block {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--bg-1); border: 1px solid var(--line);
  padding: 12px; margin-bottom: 20px; border-radius: var(--radius);
}
.ca-label { font-family: var(--font-display); font-size: 9px; color: var(--steel); }
#ca-address { font-size: 12px; color: var(--ink-dim); background: rgba(255,255,255,0.05); padding: 3px 7px; flex: 1; min-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-btn {
  font-family: var(--font-display); font-size: 9px;
  padding: 8px 10px; border: 1.5px solid var(--line); background: transparent; color: var(--ink);
  cursor: pointer;
}
.mini-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.htb-mini { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; counter-reset: htb; }
.htb-mini li { font-size: 13.5px; color: var(--ink-dim); padding-left: 22px; position: relative; counter-increment: htb; }
.htb-mini li::before {
  content: counter(htb); position: absolute; left: 0; top: 0;
  font-family: var(--font-display); font-size: 9px; color: var(--accent);
}

.tokenomics-mini, .roadmap-mini { font-size: 12px; color: var(--ink-dim); margin-bottom: 6px; }
.disclaimer { font-size: 11px; line-height: 1.7; color: #6f6f73; margin: 16px 0 14px; }
.credits { font-size: 11.5px; color: #55555a; font-family: var(--font-display); margin-bottom: 18px; }
.link-btn { background: none; border: none; color: var(--money); text-decoration: underline; cursor: pointer; font: inherit; font-size: 0.9em; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-dim); }
.footer-links a:hover { color: var(--ink); }

/* ===================== upgrade modal ===================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-panel {
  width: 100%; max-width: 420px; max-height: 80vh; overflow-y: auto;
  background: var(--bg-1); border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-family: var(--font-display); font-size: 11px;
  position: sticky; top: 0; background: var(--bg-1);
}
.modal-close { background: none; border: none; color: var(--ink); font-size: 20px; cursor: pointer; line-height: 1; padding: 4px 8px; }
.modal-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.shop-item {
  background: var(--surface); border: 1px solid var(--line); padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.shop-item-name { font-size: 13.5px; font-weight: 700; }
.shop-item-desc { font-size: 12px; color: var(--ink-dim); }
.shop-item-btn {
  align-self: flex-start; font-family: var(--font-display); font-size: 9px;
  padding: 7px 12px; background: var(--money); border: 1.5px solid #06210f; color: #06210f; cursor: pointer;
}
.shop-item-btn:disabled { opacity: 0.4; cursor: not-allowed; background: #666; border-color: #444; color: #ccc; }
.shop-item.owned .shop-item-btn { background: var(--steel); }

/* ===================== mascot CTA (fixed, bottom-right) ===================== */
.mascot-cta {
  position: fixed; right: 14px; bottom: 14px; z-index: 400;
  display: flex; align-items: flex-end; gap: 8px;
  max-width: min(80vw, 260px);
}
.mascot-cta[hidden] { display: none; }
.mascot-bubble {
  position: relative;
  background: var(--beige); color: #1a1a1a;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  padding: 8px 10px; margin-bottom: 6px;
  font-size: 11.5px; font-weight: 600; line-height: 1.4;
}
.mascot-bubble::after {
  content: ""; position: absolute; bottom: -9px; right: 14px;
  border: 8px solid transparent; border-top-color: var(--ink);
}
.mascot-bubble::before {
  content: ""; position: absolute; bottom: -6px; right: 15.5px;
  border: 6.5px solid transparent; border-top-color: var(--beige); z-index: 1;
}
.mascot-avatar-link { flex-shrink: 0; display: block; }
.mascot-avatar {
  width: 54px; height: 54px; border-radius: 10px;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  image-rendering: pixelated; image-rendering: crisp-edges;
  animation: mascot-bob 2.4s ease-in-out infinite;
}
@keyframes mascot-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.mascot-close {
  position: absolute; top: -8px; left: -8px; z-index: 2;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink); color: var(--beige); border: 1.5px solid var(--beige);
  font-size: 12px; line-height: 1; cursor: pointer; padding: 0;
}
@media (pointer: coarse) {
  .mascot-cta { bottom: 86px; }
}
@media (max-width: 420px) {
  .mascot-avatar { width: 46px; height: 46px; }
  .mascot-bubble { font-size: 10.5px; padding: 7px 9px; }
}

/* ===================== boot overlay / toast ===================== */
.boot-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: #000; color: #F5F5F7;
  display: none; align-items: center; justify-content: center;
  font-family: var(--font-display);
}
.boot-overlay.show { display: flex; }
.boot-window { text-align: center; }
.boot-line { font-size: 16px; margin-bottom: 18px; letter-spacing: 0.05em; }
.boot-progress { width: 220px; height: 10px; border: 2px solid #F5F5F7; margin: 0 auto; }
.boot-progress-fill { height: 100%; width: 0%; background: #F5F5F7; animation: bootfill 1.6s ease forwards; }
@keyframes bootfill { to { width: 100%; } }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  z-index: 9999; background: var(--ink); color: var(--bg-0);
  font-size: 13px; padding: 12px 18px; border-radius: var(--radius);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

::selection { background: var(--accent); color: #fff; }

@media (max-width: 420px) {
  .stage-stats { gap: 10px; }
  .stat-bar-block { min-width: 62px; }
  .stat-k { font-size: 7px; }
  .game-viewport { max-height: 50vh; }
  .joystick-zone { width: 78px; height: 78px; }
  .joystick-knob { width: 34px; height: 34px; margin-left: -17px; margin-top: -17px; }
  .interact-btn-mobile { width: 50px; height: 50px; }
}

@media (max-height: 680px) {
  .game-viewport { max-height: 44vh; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
