:root {
  --bg: #07070b;
  --bg2: #0d0f1d;
  --ink: #f2f5ff;
  --muted: #afb6cf;
  --accent: #7a84ff;
  --accent2: #26d0ce;
  --danger: #ff496a;
  --gold: #ffc845;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(18, 21, 38, 0.7);
  --font: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(122, 132, 255, 0.24), transparent 32%),
    radial-gradient(circle at 85% 20%, rgba(38, 208, 206, 0.2), transparent 34%),
    radial-gradient(circle at 50% 80%, rgba(255, 73, 106, 0.18), transparent 40%),
    linear-gradient(180deg, var(--bg2), var(--bg));
}

h1, h2, h3, h4, p { margin: 0; }
[hidden] { display: none !important; }

/* ─── TOPBAR ─── */
.topbar, .wrap { position: relative; z-index: 1; }

.topbar {
  width: min(1080px, calc(100% - 2rem));
  margin: 0.8rem auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-right { display: flex; align-items: center; gap: 0.8rem; }

.token-display {
  font-size: 0.82rem;
  color: var(--accent2);
  letter-spacing: 0.06em;
}

.brand, .launch { color: var(--ink); text-decoration: none; }
.brand { letter-spacing: 0.1em; font-weight: 600; font-size: 0.85rem; }
.launch { border: 1px solid var(--line); padding: 0.4rem 0.7rem; border-radius: 999px; font-size: 0.78rem; }

/* ─── LAYOUT ─── */
.wrap {
  width: min(1080px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
  display: grid;
  gap: 0.8rem;
}

/* ─── CREATURE HERO ─── */
.creature-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.2rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  padding: 1rem 1.2rem;
}

.creature-visual {
  position: relative;
  width: 160px;
  height: 160px;
}

.creature-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 18px rgba(122, 132, 255, 0.35));
  transition: filter 0.4s;
}

.stage-badge {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
}

.creature-info { min-width: 0; }

.creature-name-input {
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 600;
  width: 100%;
  max-width: 260px;
  padding: 0.2rem 0;
  outline: none;
  font-family: inherit;
}

.creature-name-input:focus {
  border-color: var(--accent);
}

.stat-bars {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.stat-row {
  display: grid;
  grid-template-columns: 80px 1fr 36px;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
}

.stat-row label { color: var(--muted); }
.stat-row .val { text-align: right; font-weight: 600; }

.stat-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.stat-fill.hp { background: var(--accent2); }
.stat-fill.brain { background: var(--accent); }
.stat-fill.dna { background: var(--danger); }
.stat-fill.train { background: var(--gold); }

.creature-meta {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.decay-warning {
  margin-top: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: rgba(255, 73, 106, 0.15);
  border: 1px solid rgba(255, 73, 106, 0.35);
  color: var(--danger);
  font-size: 0.78rem;
  animation: pulse-warn 2s ease-in-out infinite;
}

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* ─── TABS ─── */
.game-tabs {
  display: flex;
  gap: 2px;
  border-radius: 14px;
  background: rgba(18, 21, 38, 0.5);
  padding: 3px;
  overflow-x: auto;
}

.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: 600 0.76rem/1 var(--font);
  letter-spacing: 0.06em;
  padding: 0.6rem 0.5rem;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
  min-height: 40px;
}

.tab.active, .tab:hover { background: rgba(122, 132, 255, 0.18); color: var(--ink); }
.tab.active { box-shadow: 0 0 0 1px rgba(122, 132, 255, 0.4) inset; }

.tab-panels { min-height: 0; }

.tab-panel {
  display: none;
  animation: fadeUp 0.22s ease-out;
}

.tab-panel.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-inner {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  padding: 1rem;
}

/* ─── SHARED CONTROLS ─── */
.control-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }

.btn {
  appearance: none;
  border: none;
  text-decoration: none;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  font: 600 0.8rem/1.2 var(--font);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.1s, box-shadow 0.18s;
}

.btn:active { transform: scale(0.97); }

.btn.primary {
  color: #05152a;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
}

.btn.primary:hover { box-shadow: 0 0 16px rgba(38, 208, 206, 0.4); }

.game-btn {
  border: 1px solid var(--line);
  background: #141c38;
  color: var(--ink);
}

.game-btn:hover { background: #1c2650; border-color: rgba(122,132,255,0.5); }

.game-btn.accent { border-color: rgba(122,132,255,0.5); background: #1a2354; }
.game-btn.accent:hover { background: #222c68; box-shadow: 0 0 10px rgba(122,132,255,0.25); }

.game-btn.danger { background: #301424; border-color: rgba(255, 73, 106, 0.45); }
.game-btn.danger:hover { background: #401c30; }

.game-btn.sm { font-size: 0.72rem; padding: 0.35rem 0.55rem; }

.cost { opacity: 0.55; font-size: 0.72rem; margin-left: 0.2rem; }

.muted-line, .small-note { color: var(--muted); }
.small-note { margin-top: 0.5rem; font-size: 0.78rem; line-height: 1.45; }

/* ─── XP & TRAINING BARS ─── */
.xp-bar, .training-bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  margin-top: 0.4rem;
}

.xp-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width 0.5s ease;
}

.training-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--gold), #ff9500);
  transition: width 0.5s ease;
}

/* ─── SCOUT ─── */
.scout-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  margin-bottom: 0.7rem;
  background: rgba(0,0,0,0.25);
}

.scout-panel h4 { margin-bottom: 0.4rem; font-size: 0.88rem; }

.scout-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* ─── BREED ─── */
.breed-selectors {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.6rem;
}

.breed-selectors label {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.game-select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d1224;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.82rem;
}

.breed-cross {
  font-size: 1.4rem;
  color: var(--danger);
  padding-top: 1rem;
}

.breed-preview {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.5rem;
}

.stud-list {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.4rem;
  margin-bottom: 0.5rem;
}

.stud-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  font-size: 0.78rem;
  color: #d6defa;
  display: flex;
  justify-content: space-between;
}

/* ─── ECONOMY ─── */
.economy-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.35rem;
  font-size: 0.84rem;
}

.sponsor-line {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.phase-chip {
  margin-top: 0.45rem;
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.7rem;
  color: var(--accent2);
}

.phase-rail {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.phase-node {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.74rem;
  text-align: center;
  color: var(--muted);
}

.phase-node.active {
  color: var(--ink);
  border-color: rgba(122, 132, 255, 0.7);
  box-shadow: 0 0 0 1px rgba(122, 132, 255, 0.28) inset;
}

.evolution-grid,
.customizer-grid {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.subpanel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.22);
}

.subpanel h4 {
  margin-bottom: 0.35rem;
  font-size: 0.88rem;
}

.gene-buttons {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.gate-list {
  margin: 0.45rem 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.gate-list li.pass {
  color: var(--accent2);
}

.gate-list li.fail {
  color: var(--danger);
}

.customizer-svg {
  width: 100%;
  height: 190px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(10, 12, 26, 0.75);
}

.customizer-grid label {
  display: grid;
  gap: 0.2rem;
  margin-bottom: 0.36rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.customizer-grid input[type="range"] {
  width: 100%;
}

/* ─── ROSTER ─── */
.roster-list { display: grid; gap: 0.35rem; margin-top: 0.5rem; }

.roster-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  font-size: 0.78rem;
  color: #d6defa;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.roster-row button {
  border: 1px solid var(--line);
  background: #192144;
  color: var(--ink);
  border-radius: 8px;
  font-size: 0.7rem;
  padding: 0.22rem 0.4rem;
  cursor: pointer;
  transition: background 0.15s;
}

.roster-row button:hover { background: #243060; }

.roster-row.active {
  border-color: rgba(122, 132, 255, 0.8);
  box-shadow: 0 0 0 1px rgba(122, 132, 255, 0.3) inset;
}

/* ─── SHOP ─── */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.shop-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem;
  background: rgba(0,0,0,0.2);
  transition: border-color 0.2s;
}

.shop-item:hover { border-color: rgba(122,132,255,0.5); }
.shop-item h4 { font-size: 0.88rem; margin-bottom: 0.25rem; }
.shop-item p { font-size: 0.76rem; color: var(--muted); line-height: 1.4; }
.shop-item .shop-effect { color: var(--accent2); font-size: 0.74rem; margin-top: 0.25rem; }

.shop-item button {
  margin-top: 0.4rem;
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: #141c38;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.4rem;
  font: 600 0.76rem/1 var(--font);
  cursor: pointer;
  transition: background 0.15s;
}

.shop-item button:hover { background: #1c2650; }
.shop-item button:disabled { opacity: 0.4; cursor: default; }

/* ─── LOG ─── */
.log-wrap {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  padding: 0.8rem;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.log-controls { display: flex; gap: 0.3rem; }

.log {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.25rem;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.log p { margin: 0; font-size: 0.76rem; color: #cfdaff; line-height: 1.4; }
.log p.win { color: var(--accent2); }
.log p.lose { color: var(--danger); }
.log p.breed { color: #d9a0ff; }
.log p.evolve { color: var(--accent); }

/* ─── COMBAT OVERLAY ─── */
.combat-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(4, 4, 12, 0.92);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.3s;
}

@keyframes fadeIn { from { opacity: 0; } }

.combat-box {
  width: min(560px, calc(100% - 2rem));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(14, 16, 34, 0.95);
  padding: 1.2rem;
  text-align: center;
}

.combat-box h3 {
  font-size: 1.1rem;
  margin-bottom: 0.8rem;
  letter-spacing: 0.08em;
}

.combat-arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
}

.combatant { text-align: center; }
.combatant p { margin-top: 0.3rem; font-size: 0.82rem; }

.combat-svg {
  width: 100px;
  height: 100px;
  margin: 0 auto;
}

.combat-vs {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--danger);
  text-shadow: 0 0 12px rgba(255,73,106,0.6);
}

.combat-hp-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  margin-top: 0.3rem;
  overflow: hidden;
}

.combat-hp-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.combat-hp-fill.you-hp { background: var(--accent2); }
.combat-hp-fill.enemy-hp { background: var(--danger); }

.combat-narration {
  margin-top: 0.8rem;
  min-height: 80px;
  text-align: left;
  font-size: 0.78rem;
  color: #d6defa;
  line-height: 1.55;
}

.combat-narration p {
  margin: 0.2rem 0;
  animation: fadeUp 0.3s ease-out;
}

/* ─── TUTORIAL ─── */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: rgba(4, 4, 12, 0.94);
  backdrop-filter: blur(8px);
}

.tutorial-overlay[hidden] { display: none; }

.tutorial-box {
  width: min(480px, calc(100% - 2rem));
  border: 1px solid rgba(122,132,255,0.4);
  border-radius: 20px;
  background: rgba(14, 16, 34, 0.97);
  padding: 1.4rem;
  text-align: center;
}

.tutorial-box h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tutorial-step { display: none; }
.tutorial-step.active { display: block; }

.tutorial-step p {
  font-size: 0.92rem;
  line-height: 1.6;
  color: #dbe0f5;
  text-align: left;
}

.tutorial-nav {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tutorial-dots {
  display: flex;
  gap: 0.3rem;
}

.tutorial-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  transition: background 0.2s;
}

.tutorial-dots span.active { background: var(--accent); }

/* ─── FLASH FEEDBACK ─── */
@keyframes flash-green {
  0% { box-shadow: 0 0 0 0 rgba(38, 208, 206, 0.6); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes flash-red {
  0% { box-shadow: 0 0 0 0 rgba(255, 73, 106, 0.6); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.flash-win { animation: flash-green 0.6s ease-out; }
.flash-lose { animation: flash-red 0.6s ease-out; }

/* ─── RESPONSIVE ─── */
@media (max-width: 700px) {
  .creature-hero {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .creature-visual {
    margin: 0 auto;
    width: 120px;
    height: 120px;
  }

  .creature-name-input { text-align: center; max-width: none; }
  .creature-meta { justify-content: center; }
  .control-row { justify-content: center; }

  .economy-grid { grid-template-columns: 1fr 1fr; }
  .evolution-grid,
  .customizer-grid { grid-template-columns: 1fr; }

  .breed-selectors { flex-direction: column; }
  .breed-cross { padding-top: 0; }

  .combat-arena { grid-template-columns: 1fr; gap: 0.5rem; }
  .combat-vs { font-size: 1.2rem; }
}

body.godot-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.godot-wrap {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 1.4rem));
  margin: 0.7rem auto 1.2rem;
  display: grid;
  gap: 0.75rem;
  flex: 1;
}

.godot-copy h1 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  letter-spacing: 0.06em;
}

.godot-copy p {
  color: var(--muted);
  max-width: 62ch;
  line-height: 1.45;
}

.godot-copy .eyebrow {
  color: var(--accent2);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.controls-line {
  font-size: 0.82rem;
  color: var(--ink) !important;
}

.godot-frame-wrap {
  min-height: min(78vh, 820px);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: #05060c;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35);
}

.godot-frame {
  display: block;
  width: 100%;
  height: min(78vh, 820px);
  border: 0;
  background: #05060c;
}
