:root {
  --bg: #0d0b1a;
  --bg-alt: #131029;
  --panel: #1c1738;
  --border: #4a3f7a;
  --gold: #ffcc4d;
  --gold-dim: #d1a530;
  --purple: #a06cff;
  --text: #e6e1ff;
  --text-dim: #a9a2c9;
  --font-pixel: 'Press Start 2P', monospace;
  --font-body: 'VT323', monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 20px;
  line-height: 1.5;
  overflow-x: hidden;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Starfield background */
.stars, .stars2 {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: transparent;
}
.stars {
  background-image:
    radial-gradient(2px 2px at 20px 30px, var(--gold), transparent),
    radial-gradient(2px 2px at 120px 80px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 200px 150px, var(--purple), transparent),
    radial-gradient(1.5px 1.5px at 300px 60px, #fff, transparent),
    radial-gradient(2px 2px at 400px 200px, var(--gold), transparent),
    radial-gradient(1.5px 1.5px at 500px 100px, #fff, transparent);
  background-repeat: repeat;
  background-size: 550px 300px;
  opacity: 0.5;
  animation: drift 60s linear infinite;
}
.stars2 {
  background-image:
    radial-gradient(1.5px 1.5px at 50px 200px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 250px 50px, var(--purple), transparent),
    radial-gradient(1.5px 1.5px at 350px 250px, #fff, transparent);
  background-repeat: repeat;
  background-size: 400px 400px;
  opacity: 0.3;
  animation: drift 90s linear infinite reverse;
}
@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-1000px); }
}

/* Pixel border utility */
.pixel-border {
  box-shadow:
    0 -4px 0 0 var(--border),
    0 4px 0 0 var(--border),
    -4px 0 0 0 var(--border),
    4px 0 0 0 var(--border);
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(13, 11, 26, 0.9);
  backdrop-filter: blur(4px);
  border-bottom: 4px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
}
.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.logo-icon { height: 48px; width: auto; }
.site-nav { display: flex; gap: 24px; }
.site-nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 20px;
  transition: color 0.15s ease;
}
.site-nav a:hover { color: var(--gold); }

/* Hero */
.hero {
  padding: 100px 0 80px;
  text-align: center;
}
.title-pixel {
  font-family: var(--font-pixel);
  font-size: 48px;
  color: var(--gold);
  margin: 0 0 24px;
  letter-spacing: 4px;
}
.glow { text-shadow: 0 0 12px rgba(255, 204, 77, 0.5), 0 0 24px rgba(160, 108, 255, 0.3); }
.subtitle {
  font-size: 26px;
  color: var(--text);
  margin: 0 0 8px;
}
.hero-desc {
  max-width: 620px;
  margin: 0 auto 36px;
  color: var(--text-dim);
  font-size: 22px;
}
.cta-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 14px 28px;
  font-family: var(--font-pixel);
  font-size: 12px;
  text-decoration: none;
  border: 4px solid var(--border);
  transition: transform 0.1s ease, background 0.15s ease;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  background: var(--gold);
  color: #1a1330;
  border-color: var(--gold-dim);
}
.btn-primary:hover { background: #ffd86b; }
.btn-ghost {
  background: var(--panel);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

/* Sections */
.section { padding: 80px 0; }
.section-alt { background: var(--bg-alt); }
.section-title {
  font-family: var(--font-pixel);
  font-size: 24px;
  color: var(--gold);
  text-align: center;
  margin: 0 0 48px;
}

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
}
.pixel-card {
  background: var(--panel);
  border: 4px solid var(--border);
  padding: 28px 24px;
}
.card-icon { font-size: 32px; margin-bottom: 12px; }
.pixel-card h3 {
  font-family: var(--font-pixel);
  font-size: 15px;
  color: var(--text);
  margin: 0 0 12px;
}
.pixel-card p {
  color: var(--text-dim);
  font-size: 20px;
  margin: 0;
}

/* Project card */
.project-card {
  background: var(--panel);
  border: 4px solid var(--border);
  padding: 40px;
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
}
.project-info h3 {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--gold);
  margin: 0 0 16px;
}
.project-info p {
  color: var(--text-dim);
  font-size: 22px;
  margin: 0 0 20px;
}
.status-badge {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--purple);
  border: 2px solid var(--purple);
  padding: 6px 14px;
}

/* CTA section */
.cta-section { text-align: center; }

/* Footer */
.site-footer {
  border-top: 4px solid var(--border);
  padding: 40px 0;
  background: var(--bg-alt);
}
.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.footer-nav {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}
.footer-nav a, .footer-nav .soon {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 18px;
}
.footer-nav a:hover { color: var(--gold); }
.footer-nav .soon { opacity: 0.5; }
.footer-copy { color: var(--text-dim); font-size: 16px; margin: 0; }

/* 3D homepage scene */
body.game-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
body.game-page main {
  flex: 1;
  display: flex;
  min-height: 0;
}
#scene-root {
  display: flex;
  flex: 1;
  width: 100%;
  min-height: 420px;
  overflow: hidden;
}
#game-view {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #221d3a;
  overflow: hidden;
}
#scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#scene-canvas:active {
  cursor: grabbing;
}
#scene-loading[hidden],
#scene-fallback[hidden] {
  display: none;
}
#scene-loading,
#scene-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  background: var(--bg);
  padding: 24px;
}
.loading-text {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--gold);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}
#scene-fallback p { color: var(--text-dim); max-width: 420px; }

/* Right-side HUD */
#hud {
  flex-shrink: 0;
  width: 220px;
  background: #43434c;
  border-left: 4px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.hud-name {
  font-family: var(--font-pixel);
  font-size: 13px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
  text-align: center;
}
.stat-bars {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-bar-track {
  position: relative;
  height: 18px;
  background: #1a1a20;
  border: 2px solid #000;
  display: flex;
  align-items: center;
}
.stat-bar-fill { position: absolute; inset: 0; height: 100%; }
.stat-bar-fill.hp { width: 100%; background: #c0392b; }
.stat-bar-fill.mp { width: 100%; background: #2f6fd6; }
.stat-bar-text {
  position: relative;
  z-index: 1;
  padding-left: 6px;
  font-size: 13px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

#minimap-wrap {
  border: 3px solid var(--border);
  background: #1a1a20;
  line-height: 0;
}
#minimap-canvas { display: block; width: 100%; height: 140px; }

.inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.inv-slot {
  aspect-ratio: 1;
  background: #2a2a32;
  border: 2px solid #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.hud-tips {
  margin: auto 0 0;
  padding-left: 18px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-dim);
}
.hud-tips li { margin-bottom: 2px; }

#touch-joystick {
  position: absolute;
  left: 24px;
  bottom: 24px;
  width: 100px;
  height: 100px;
  touch-action: none;
}
#joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(28, 23, 56, 0.55);
  border: 3px solid var(--border);
  touch-action: none;
}
#joystick-knob {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 204, 77, 0.85);
  border: 2px solid var(--gold-dim);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

@media (max-width: 640px) {
  .site-nav { gap: 14px; }
  .site-nav a { font-size: 16px; }
  .title-pixel { font-size: 32px; }
  #hud { width: 150px; padding: 10px; gap: 10px; }
  #minimap-canvas { height: 100px; }
  .hud-tips { font-size: 13px; }
}
