/* =========================================================
   TOKENS
   ========================================================= */
:root,
[data-theme="dark"] {
  --bg: #0a0e16;
  --bg-alt: #0d1420;
  --panel: #101927;
  --panel-alt: #16213256;
  --panel-solid: #16213299;
  --border: #24344a;
  --border-soft: #1a2536;
  --accent: #4fd9ff;
  --accent-dim: #2a7f96;
  --accent2: #ff4fa8;
  --accent3: #4dffa0;
  --text: #dfe9f5;
  --text-dim: #869bb3;
  --text-faint: #4f6076;
  --code-bg: #0b121c;
  --shadow: 0 20px 60px rgba(0,0,0,.45);
  --radius: 4px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #dfe6ef;
  --bg-alt: #eef2f7;
  --panel: #ffffff;
  --panel-alt: #f3f6fa;
  --panel-solid: #ffffff;
  --border: #aebdd1;
  --border-soft: #c7d3e2;
  --accent: #1f5fc4;
  --accent-dim: #4a80cf;
  --accent2: #c9701f;
  --accent3: #2f9e52;
  --text: #1c2836;
  --text-dim: #56677d;
  --text-faint: #8496ab;
  --code-bg: #f4f7fb;
  --shadow: 0 12px 30px rgba(30,50,80,.15);
  --radius: 3px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  line-height: 1.5;
  overflow-x: hidden;
  transition: background .3s ease, color .3s ease;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; }
a { color: inherit; text-decoration: none; }
p { color: var(--text-dim); }

::selection { background: var(--accent); color: var(--bg); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* =========================================================
   BACKGROUND FX
   ========================================================= */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: .55;
  pointer-events: none;
}
[data-theme="light"] #bg-canvas { opacity: .25; }

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.015) 0px,
    rgba(255,255,255,0.015) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: .5;
}
[data-theme="light"] .scanlines { display: none; }

/* =========================================================
   TOPBAR
   ========================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
  color: var(--text);
}
.logo-mark { color: var(--accent); font-size: 12px; }
.logo:hover .logo-text { animation: logo-glitch .45s steps(2, end) infinite; }
@keyframes logo-glitch {
  0%   { text-shadow: 2px 0 var(--accent2), -2px 0 var(--accent); transform: translate(0, 0); }
  25%  { text-shadow: -2px 0 var(--accent2), 2px 0 var(--accent); transform: translate(1px, -1px); }
  50%  { text-shadow: 2px 0 var(--accent), -2px 0 var(--accent2); transform: translate(-1px, 1px); }
  75%  { text-shadow: -1px 0 var(--accent), 1px 0 var(--accent2); transform: translate(1px, 1px); }
  100% { text-shadow: none; transform: translate(0, 0); }
}
.nav { display: flex; gap: 28px; }
.nav a {
  font-size: 13px;
  color: var(--text-dim);
  padding: 4px 0;
  border-bottom: 1px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.nav a:hover { color: var(--text); border-color: var(--accent); }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .08em;
}
.theme-toggle-track {
  width: 30px; height: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
}
.theme-toggle-thumb {
  position: absolute;
  top: 1px; left: 1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform .25s ease;
}
[data-theme="light"] .theme-toggle-thumb { transform: translateX(14px); }

/* =========================================================
   HERO
   ========================================================= */
.hero {
  position: relative;
  z-index: 2;
  min-height: 88vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 80px 24px 40px;
  overflow: hidden;
}

.grid-floor {
  position: absolute;
  left: 50%;
  bottom: -10%;
  width: 220%;
  height: 60%;
  transform: translateX(-50%) perspective(400px) rotateX(62deg);
  background-image:
    linear-gradient(var(--accent-dim) 1px, transparent 1px),
    linear-gradient(90deg, var(--accent-dim) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: .22;
  animation: floor-scroll 6s linear infinite;
  -webkit-mask-image: linear-gradient(to top, black, transparent 85%);
  mask-image: linear-gradient(to top, black, transparent 85%);
}
@keyframes floor-scroll {
  from { background-position: 0 0; }
  to { background-position: 0 48px; }
}

.hero-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 30%), color-mix(in srgb, var(--accent) 24%, transparent), transparent 55%);
}

.hero-content { position: relative; z-index: 1; max-width: 720px; }

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--accent);
  margin: 0 0 18px;
}
.hero-title {
  font-size: clamp(32px, 6vw, 56px);
  font-weight: 700;
  line-height: 1.08;
  margin-bottom: 20px;
  color: var(--text);
  background: linear-gradient(100deg, var(--text) 25%, var(--accent) 45%, var(--accent2) 58%, var(--text) 80%);
  background-size: 250% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: title-sweep 7s ease-in-out infinite;
}
@keyframes title-sweep {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.hero-sub {
  font-size: 15px;
  max-width: 520px;
  margin: 0 auto 32px;
}
.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 12px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  display: inline-block;
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent); }
.btn-ghost { color: var(--text); background: transparent; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* classic bevel on light/"classic" theme buttons */
[data-theme="light"] .btn {
  box-shadow: inset 1px 1px 0 rgba(255,255,255,.8), inset -1px -1px 0 rgba(0,0,0,.15);
}
[data-theme="light"] .btn:active { box-shadow: inset -1px -1px 0 rgba(255,255,255,.8), inset 1px 1px 0 rgba(0,0,0,.15); }

/* Stats strip */
.stats-strip {
  position: relative;
  margin-top: 56px;
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  flex-wrap: wrap;
}
.stat-item {
  flex: 1 1 140px;
  padding: 18px 20px;
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}
.stat-item:last-child { border-right: none; }
.stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.stat-label {
  font-size: 10px;
  letter-spacing: .05em;
  color: var(--text-faint);
}
.stat-live .stat-value { color: var(--accent3); }
.stat-dot {
  position: absolute;
  top: 14px; right: 14px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent3);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent3) 60%, transparent);
  animation: pulse-dot 1.8s ease-out infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent3) 55%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* =========================================================
   SECTIONS (shared)
   ========================================================= */
.section {
  position: relative;
  z-index: 2;
  max-width: 1180px;
  margin: 0 auto;
  padding: 100px 28px;
}
.section-head { margin-bottom: 40px; max-width: 560px; }
.section-head h2 {
  font-size: clamp(24px, 3.4vw, 34px);
  margin-bottom: 10px;
}
.section-head p { font-size: 14px; margin: 0; }

/* =========================================================
   GAME CARDS (3D tilt)
   ========================================================= */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  perspective: 1000px;
}
.game-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transform-style: preserve-3d;
  transition: transform .12s ease, box-shadow .2s ease;
  will-change: transform;
}
.game-card:hover { box-shadow: var(--shadow); }
.game-thumb {
  height: 130px;
  background: linear-gradient(135deg, var(--thumb-a, var(--accent)), var(--thumb-b, var(--accent2)));
  position: relative;
}
.game-thumb::after {
  content: attr(data-role);
  position: absolute;
  bottom: 8px; left: 10px;
  font-size: 10px;
  letter-spacing: .05em;
  background: rgba(0,0,0,.45);
  color: #fff;
  padding: 3px 8px;
  border-radius: 999px;
}
.game-body { padding: 16px 18px 18px; transform: translateZ(20px); }
.game-body h3 { font-size: 16px; margin-bottom: 6px; }
.game-body p { font-size: 12.5px; margin: 0 0 12px; }
.game-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}
.game-meta .game-visits { color: var(--accent); font-weight: 600; }
.game-meta a { color: var(--text-dim); }
.game-meta a:hover { color: var(--accent); }

/* =========================================================
   STUDIO / EXPLORER WINDOW
   ========================================================= */
.studio-window {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel);
  animation: radiant-pulse 4.5s ease-in-out infinite;
}
@keyframes radiant-pulse {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 1px color-mix(in srgb, var(--accent) 20%, transparent); }
  50% { box-shadow: var(--shadow), 0 0 34px 2px color-mix(in srgb, var(--accent) 32%, transparent); }
}
.studio-titlebar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border-soft);
}
.studio-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--border);
}
.studio-titletext {
  margin-left: 10px;
  font-size: 11px;
  color: var(--text-faint);
}
.studio-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 420px;
}
@media (max-width: 760px) {
  .studio-body { grid-template-columns: 1fr; }
}

.explorer-pane {
  border-right: 1px solid var(--border-soft);
  background: var(--bg-alt);
  overflow-y: auto;
  max-height: 520px;
}
.explorer-header {
  font-size: 10px;
  letter-spacing: .08em;
  color: var(--text-faint);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.explorer-tree { padding: 6px 0; font-size: 13px; }

.tree-node { user-select: none; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  cursor: pointer;
  color: var(--text-dim);
  white-space: nowrap;
}
.tree-row:hover { background: var(--panel-alt); color: var(--text); }
.tree-row.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }
.tree-caret {
  width: 10px;
  font-size: 9px;
  color: var(--text-faint);
  transition: transform .15s ease;
  flex-shrink: 0;
}
.tree-node.open > .tree-row .tree-caret { transform: rotate(90deg); }
.tree-icon { width: 14px; text-align: center; flex-shrink: 0; font-size: 12px; }
.tree-icon.folder { color: var(--accent2); }
.tree-icon.script-server { color: var(--accent); }
.tree-icon.script-local { color: var(--accent3); }
.tree-icon.script-module { color: #d7b74f; }
.tree-children {
  display: none;
  padding-left: 16px;
}
.tree-node.open > .tree-children { display: block; }

.viewer-pane { display: flex; flex-direction: column; min-width: 0; }
.viewer-tabs {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
  min-height: 34px;
  align-items: center;
  padding: 0 10px 0 14px;
  font-size: 11px;
  color: var(--text-faint);
  gap: 8px;
}
.viewer-tab-active {
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.viewer-actions { display: flex; gap: 6px; }
.viewer-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .03em;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.viewer-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
}
.viewer-body { flex: 1; overflow: auto; max-height: 486px; }
.code-viewer {
  margin: 0;
  padding: 18px 20px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-dim);
  min-height: 100%;
  white-space: pre;
  tab-size: 4;
}
.tok-kw { color: var(--accent); }
.tok-str { color: var(--accent3); }
.tok-com { color: var(--text-faint); font-style: italic; }
.tok-fn { color: var(--accent2); }
.tok-num { color: #d7b74f; }

/* =========================================================
   REVIEWS
   ========================================================= */
.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.review-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.review-stars { color: var(--accent2); font-size: 13px; margin-bottom: 10px; letter-spacing: 2px; }
.review-quote { font-size: 13.5px; color: var(--text); margin: 0 0 14px; line-height: 1.6; }
.review-author { display: flex; align-items: center; gap: 10px; }
.review-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  flex-shrink: 0;
}
.review-name { font-size: 12.5px; color: var(--text); font-weight: 600; }
.review-role { font-size: 11px; color: var(--text-faint); }

/* =========================================================
   CONTACT / FOOTER
   ========================================================= */
.contact {
  position: relative;
  z-index: 2;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-alt);
  padding: 90px 28px 40px;
}
.contact-inner { max-width: 700px; margin: 0 auto; text-align: center; }
.contact h2 { font-size: clamp(24px, 4vw, 36px); margin-bottom: 10px; }
.contact-foot { font-size: 11px; color: var(--text-faint); margin: 40px 0 0; }

/* Terminal contact window */
.terminal-window {
  margin: 34px 0 10px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--code-bg);
  animation: radiant-pulse 4.5s ease-in-out infinite;
}
.terminal-body {
  padding: 20px 22px 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 200px;
}
.terminal-output .terminal-line { color: var(--accent3); }
.terminal-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.terminal-line-block { align-items: flex-start; }
.terminal-prompt { color: var(--accent); flex-shrink: 0; }
.terminal-cursor {
  display: inline-block;
  width: 7px; height: 14px;
  background: var(--accent3);
  animation: blink 1s steps(1) infinite;
  vertical-align: middle;
}
@keyframes blink { 50% { opacity: 0; } }

.terminal-form { margin-top: 4px; }
.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 4px 2px;
  outline: none;
  min-width: 0;
}
.terminal-input:focus { border-color: var(--accent); }
.terminal-textarea { resize: vertical; }
.terminal-submit {
  margin-top: 16px;
  background: transparent;
  border: 1px solid var(--accent3);
  color: var(--accent3);
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 9px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.terminal-submit:hover {
  background: var(--accent3);
  color: var(--bg);
  box-shadow: 0 0 20px color-mix(in srgb, var(--accent3) 45%, transparent);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 640px) {
  .nav { display: none; }
  .stats-strip { flex-direction: column; }
  .stat-item { border-right: none; border-bottom: 1px solid var(--border-soft); }
  .stat-item:last-child { border-bottom: none; }
}