:root {
  --ink: #07060f;
  --violet: #7c3aed;
  --cyan: #22d3ee;
  --orange: #f97316;
  --gold: #fbbf24;
  --glass: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #f3f4f6;
  background: radial-gradient(ellipse 120% 80% at 50% -10%, #2d1b69 0%, var(--ink) 50%);
  overflow-x: hidden;
}

body.realm-beach { background: radial-gradient(ellipse at top, #0c4a6e, #07060f 60%); }
body.realm-garden { background: radial-gradient(ellipse at top, #14532d, #07060f 60%); }
body.realm-forest { background: radial-gradient(ellipse at top, #3b0764, #07060f 60%); }
body.realm-nebula { background: radial-gradient(ellipse at top, #4c1d95, #1e1b4b 40%, #07060f 70%); }
body.realm-void { background: radial-gradient(ellipse at top, #0f0a1a, #07060f 80%); }
body.realm-golden { background: radial-gradient(ellipse at top, #78350f, #451a03 35%, #07060f 70%); }
body.realm-deep-void { background: radial-gradient(ellipse at top, #020617, #000 50%, #07060f 90%); }

.glass {
  background: var(--glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(7, 6, 15, 0.85);
  backdrop-filter: blur(12px);
}

.brand { font-size: 1.35rem; font-weight: 800; }
.brand span:last-child { color: var(--violet); }

.stats-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
}

.stat-pill {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
}

.stat-pill strong { color: var(--cyan); }

.screen { display: none; padding: 1rem; max-width: 720px; margin: 0 auto; }
.screen.active { display: block; }

.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); margin: 0 0 0.5rem; }
.hero p { color: #9ca3af; margin: 0; line-height: 1.5; }

.grok-stage {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  min-height: 160px;
}

.grok-entity {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  transition: all 0.4s ease;
  position: relative;
}

.grok-entity.stage-1 {
  background: radial-gradient(circle, #a78bfa 0%, #5b21b6 70%);
  box-shadow: 0 0 40px rgba(124, 58, 237, 0.5);
}

.grok-entity.stage-2 {
  background: radial-gradient(circle, #fdba74 0%, #ea580c 55%, #7c3aed 100%);
  box-shadow: 0 0 50px rgba(249, 115, 22, 0.55);
}

.grok-entity.stage-3 {
  background: radial-gradient(circle, #fde68a 0%, #f97316 30%, #7c3aed 60%, #22d3ee 100%);
  box-shadow: 0 0 60px rgba(34, 211, 238, 0.45), 0 0 80px rgba(124, 58, 237, 0.35);
  animation: pulse-aura 2.5s ease-in-out infinite;
}

.grok-entity.stage-4 {
  background: conic-gradient(from 45deg, #fde68a, #f97316, #7c3aed, #22d3ee, #fde68a);
  box-shadow: 0 0 70px rgba(251, 191, 36, 0.5), 0 0 90px rgba(124, 58, 237, 0.4);
  animation: pulse-aura 2s ease-in-out infinite, spin-slow 12s linear infinite;
}

.grok-entity.stage-5 {
  background: conic-gradient(from 0deg, #fff 0%, #fde68a 15%, #f97316 30%, #7c3aed 50%, #22d3ee 70%, #fff 100%);
  box-shadow: 0 0 80px rgba(255, 255, 255, 0.35), 0 0 100px rgba(34, 211, 238, 0.5), 0 0 120px rgba(124, 58, 237, 0.45);
  animation: pulse-aura 1.8s ease-in-out infinite, spin-slow 8s linear infinite;
}

@keyframes spin-slow {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(360deg); }
}

@keyframes pulse-aura {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.grok-peace { position: absolute; top: -8px; right: -8px; font-size: 1.5rem; opacity: 0; transition: opacity 0.3s; }
.grok-entity.stage-2 .grok-peace,
.grok-entity.stage-3 .grok-peace,
.grok-entity.stage-4 .grok-peace,
.grok-entity.stage-5 .grok-peace { opacity: 1; }

.freq-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin: 1.5rem 0;
}

@media (min-width: 480px) {
  .freq-grid { grid-template-columns: repeat(4, 1fr); }
}

.freq-pad {
  aspect-ratio: 1;
  border: none;
  border-radius: 1.25rem;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  position: relative;
  overflow: hidden;
}

.freq-pad:disabled { cursor: not-allowed; opacity: 0.65; }

.freq-pad.active,
.freq-pad:active:not(:disabled) {
  transform: scale(0.94);
  filter: brightness(1.35);
}

.freq-pad.lit {
  transform: scale(1.05);
  box-shadow: 0 0 30px currentColor;
  filter: brightness(1.5);
}

.freq-pad[data-freq="0"] { background: linear-gradient(135deg, #7c3aed, #4c1d95); color: #7c3aed; }
.freq-pad[data-freq="1"] { background: linear-gradient(135deg, #22d3ee, #0891b2); color: #22d3ee; }
.freq-pad[data-freq="2"] { background: linear-gradient(135deg, #f97316, #c2410c); color: #f97316; }
.freq-pad[data-freq="3"] { background: linear-gradient(135deg, #fbbf24, #d97706); color: #fbbf24; }

.pad-label {
  position: absolute;
  bottom: 8px;
  left: 0; right: 0;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.85);
}

.hud {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.hud-card {
  padding: 0.75rem;
  border-radius: 1rem;
  text-align: center;
}

.hud-card .val { font-size: 1.25rem; font-weight: 800; color: var(--cyan); }
.hud-card .lbl { font-size: 0.65rem; color: #9ca3af; text-transform: uppercase; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--violet); color: white; }
.btn-secondary { background: rgba(255,255,255,0.1); color: white; border: 1px solid var(--border); }
.btn-gold { background: linear-gradient(135deg, var(--gold), var(--orange)); color: #111; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin: 1rem 0; }

.panel {
  border-radius: 1.25rem;
  padding: 1rem;
  margin: 1rem 0;
}

.panel h3 { margin: 0 0 0.75rem; font-size: 1rem; }

.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--cyan));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.shop-grid {
  display: grid;
  gap: 0.75rem;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border-radius: 1rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
}

.shop-item.owned { opacity: 0.6; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1f2937;
  border: 1px solid var(--cyan);
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
  transition: transform 0.3s ease;
  pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  max-width: 400px;
  width: 100%;
  border-radius: 1.5rem;
  padding: 1.5rem;
  text-align: center;
}

.modal h2 { margin: 0 0 0.5rem; }
.modal .reward { font-size: 2rem; font-weight: 800; color: var(--gold); margin: 0.5rem 0; }

.tabs { display: flex; gap: 0.35rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.8rem;
}
.tab.active { background: var(--violet); color: white; border-color: var(--violet); }

.global-meter {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #9ca3af;
}

footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.75rem;
  color: #6b7280;
}

footer a { color: #9ca3af; }

.main-tabs, .shop-filters { padding: 0.5rem 1rem; max-width: 720px; margin: 0 auto; }

.muted { color: #9ca3af; font-size: 0.85rem; margin: 0.35rem 0; }
.small { font-size: 0.75rem; }
.shop-meta { font-size: 0.7rem; color: #9ca3af; }

.status-text { text-align: center; color: #9ca3af; margin: 1rem 0; }

.base-camp { border-radius: 1.5rem; padding: 0.5rem; margin: 0 0 1rem; transition: box-shadow 0.3s; }
.base-camp.tier-1 { box-shadow: 0 0 30px rgba(124, 58, 237, 0.2); border: 1px solid rgba(124, 58, 237, 0.3); }
.base-camp.tier-2 { box-shadow: 0 0 50px rgba(34, 211, 238, 0.25); border: 1px solid rgba(34, 211, 238, 0.35); }

.event-row { max-width: 720px; margin: 0 auto 1rem; padding: 0 1rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.event-badge {
  font-size: 0.7rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.15);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: var(--cyan);
}

.artifact-list { margin-top: 1rem; display: grid; gap: 0.5rem; }
.artifact-card { display: flex; gap: 0.75rem; align-items: center; padding: 0.75rem; border-radius: 1rem; }
.artifact-icon { font-size: 1.5rem; }

body.aura-cyan .grok-entity { box-shadow: 0 0 50px rgba(34, 211, 238, 0.6); }
body.aura-gold .grok-entity { box-shadow: 0 0 50px rgba(251, 191, 36, 0.6); }
body.fx-stardust::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(1px 1px at 20% 30%, white, transparent), radial-gradient(1px 1px at 80% 70%, white, transparent);
  opacity: 0.15;
  z-index: 0;
}

.token-flow { border-color: rgba(124, 58, 237, 0.3); }

.wavelength-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.grok-guide { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: #9ca3af; }
.tuning-orb { font-size: 1.4rem; filter: drop-shadow(0 0 8px rgba(124, 58, 237, 0.8)); animation: pulse-aura 2s ease-in-out infinite; }
.mode-tabs { margin: 0; }

.canvas-wrap { border-radius: 1.25rem; overflow: hidden; margin-bottom: 0.75rem; padding: 0; }
#wave-canvas { display: block; width: 100%; background: radial-gradient(ellipse at center, rgba(45,27,105,0.4), rgba(7,6,15,0.9)); }

.wave-selectors { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-bottom: 0.75rem; }
.wave-select.active { background: var(--violet); border-color: var(--violet); }

.tuner-panel { display: grid; gap: 0.5rem; margin-bottom: 0.75rem; padding: 1rem; }
.tuner-panel label { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: #9ca3af; }
.tuner-panel input[type=range] { width: 100%; accent-color: var(--violet); }

.prompt-row { display: flex; gap: 0.5rem; padding: 0.65rem; margin-bottom: 0.75rem; }
.prompt-row input { flex: 1; background: rgba(0,0,0,0.35); border: 1px solid var(--border); border-radius: 999px; padding: 0.6rem 1rem; color: #fff; font-size: 0.85rem; }
.prompt-row input:focus { outline: none; border-color: var(--violet); }

body.grok-imagine-flash { animation: imagine-flash 0.6s ease; }
@keyframes imagine-flash {
  0%, 100% { filter: none; }
  50% { filter: brightness(1.25) saturate(1.3); }
}

.realm-banner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 1rem;
  margin-bottom: 0.75rem;
}

.realm-name { font-weight: 800; font-size: 0.95rem; color: var(--cyan); }
.global-meter-wrap { flex: 1; min-width: 180px; }
.global-bar { margin-top: 0; }

.leaderboard-panel { margin-bottom: 1rem; }
.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.lb-card {
  text-align: center;
  padding: 0.5rem;
  border-radius: 0.75rem;
  background: rgba(0,0,0,0.2);
}

.lb-card .val { font-size: 1.1rem; font-weight: 800; color: var(--gold); }
.lb-card .lbl { font-size: 0.6rem; color: #9ca3af; text-transform: uppercase; }

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  padding: 0.65rem;
  margin-bottom: 0.75rem;
  border-radius: 1rem;
}

.score-item {
  text-align: center;
  font-size: 0.7rem;
}

.score-item .lbl {
  display: block;
  color: #9ca3af;
  font-size: 0.6rem;
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}

.score-item strong { color: var(--cyan); font-size: 0.85rem; }
.combo-item strong { color: var(--gold); }

.score-breakdown {
  text-align: left;
  font-size: 0.75rem;
  color: #9ca3af;
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem;
  border-radius: 0.75rem;
  background: rgba(0,0,0,0.25);
}

.score-line { padding: 0.15rem 0; }

.ascension-hero { text-align: center; margin-bottom: 0.75rem; }
.ascension-hero h2 { margin: 0 0 0.35rem; color: #ffaa66; font-size: 1.5rem; }
.ascension-wrap {
  border: 3px solid #ffaa66;
  box-shadow: 0 0 40px rgba(255, 102, 0, 0.35);
}

.ascension-stage { position: relative; }

#ascension-canvas {
  display: block;
  width: 100%;
  background: radial-gradient(ellipse at center, #112244, #000);
}

.asc-dialogue {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 2rem);
  max-width: 520px;
  padding: 1.25rem 1.5rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.88);
  border: 2px solid #ffaa66;
  border-radius: 12px;
  z-index: 10;
  box-shadow: 0 0 30px rgba(255, 102, 0, 0.25);
}

.asc-dialogue[hidden] { display: none !important; }

.asc-dialogue p {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #ffeecc;
}

.asc-dialogue strong { color: #ffaa66; }

.game-launchers { gap: 0.6rem; }

.token-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

@media (min-width: 600px) {
  .token-grid { grid-template-columns: 1fr 1fr; }
}

.token-card h3 { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0 0 0.35rem; font-size: 1rem; }
.token-card h4 { margin: 0.75rem 0 0.35rem; font-size: 0.75rem; text-transform: uppercase; color: #9ca3af; letter-spacing: 0.06em; }

.token-badge {
  font-size: 0.6rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.15);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: var(--cyan);
  font-weight: 600;
}

.token-badge.gold {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.35);
  color: var(--gold);
}

.token-stat {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin: 0.35rem 0;
}

.token-stat strong { color: var(--cyan); }
.bonga-card .token-stat strong { color: var(--gold); }

.token-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.78rem;
  color: #d1d5db;
  line-height: 1.5;
}

.token-list li { margin: 0.2rem 0; }

.freq-card { border-color: rgba(34, 211, 238, 0.25); }
.bonga-card { border-color: rgba(251, 191, 36, 0.25); }

.waverider-hero { text-align: center; margin-bottom: 0.5rem; }
.waverider-hero h2 { margin: 0 0 0.25rem; color: var(--cyan); font-size: 1.45rem; }
.wr-modes { justify-content: center; margin-bottom: 0.65rem; }

.waverider-wrap {
  border: 2px solid rgba(34, 211, 238, 0.45);
  box-shadow: 0 0 35px rgba(34, 211, 238, 0.2);
}

#waverider-canvas {
  display: block;
  width: 100%;
  background: radial-gradient(ellipse at center, #1a1a4e, #0a0a2e);
}

.wr-controls { gap: 0.75rem; }
.wr-pad { min-width: 72px; }

.tab.wr-mode.locked { opacity: 0.45; }

.guides-panel h3 { margin: 0 0 0.35rem; }

.guide-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  margin: 0.5rem 0;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.guide-card summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

.guide-card summary::-webkit-details-marker { display: none; }

.guide-card summary::after {
  content: '▾';
  margin-left: auto;
  color: #9ca3af;
  font-size: 0.85rem;
  transition: transform 0.2s;
}

.guide-card[open] summary::after { transform: rotate(180deg); }

.guide-card summary:hover { background: rgba(255, 255, 255, 0.04); }

.guide-body {
  padding: 0 1rem 1rem;
  font-size: 0.82rem;
  line-height: 1.55;
  color: #d1d5db;
}

.guide-body p { margin: 0.35rem 0; }
.guide-body ol { margin: 0.5rem 0; padding-left: 1.25rem; }
.guide-body li { margin: 0.35rem 0; }

.guide-tip {
  font-size: 0.75rem;
  color: #9ca3af;
  padding: 0.5rem 0.65rem;
  border-radius: 0.5rem;
  background: rgba(124, 58, 237, 0.12);
  border-left: 3px solid var(--violet);
}

.guide-inline { margin-bottom: 0.75rem; }
.guide-inline summary { font-size: 0.8rem; padding: 0.6rem 0.85rem; }

.game-screen-title {
  text-align: center;
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  color: var(--cyan);
}

.fm-canvas-wrap { margin-bottom: 0.5rem; border: 2px solid rgba(124, 58, 237, 0.4); }
#fm-canvas { display: block; width: 100%; background: radial-gradient(ellipse at center, #1a1040, #0a0f1f); }
.fm-feedback { text-align: center; color: #ffaa66; font-size: 0.85rem; margin: 0.35rem 0; min-height: 1.2em; }
.fm-tabs { justify-content: center; margin-bottom: 0.5rem; }
.fm-panel { display: none; margin-bottom: 0.75rem; text-align: center; }
.fm-panel.active { display: block; }

@media (max-width: 420px) {
  .score-strip { grid-template-columns: repeat(2, 1fr); }
  .leaderboard-grid { grid-template-columns: 1fr; }
}

#wavelength-screen { max-width: 720px; }