*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#overlay {
  position: fixed; inset: 0;
  background: #000;
  display: flex; flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 100;
  padding: 0 0 32px;
}
#overlay.hidden { display: none; }

#overlay-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  width: 100%;
  flex-shrink: 0;
}

#start-btn {
  background: transparent;
  border: 2px solid rgba(255,255,255,0.8);
  color: rgba(255,255,255,0.9);
  font-size: clamp(18px, 5vw, 28px);
  font-family: monospace;
  letter-spacing: 0.15em;
  padding: 16px 48px;
  cursor: pointer;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
#start-btn:active { background: rgba(255,255,255,0.15); }
#start-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

#rom-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  width: min(300px, 80vw);
}
#rom-progress.visible { display: flex; }
#rom-progress-label {
  font-family: monospace;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 1px;
}
#rom-progress-bar-wrap {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}
#rom-progress-bar {
  height: 100%;
  width: 0%;
  background: rgba(255,255,255,0.7);
  border-radius: 2px;
  transition: width 0.15s ease;
}

#error-msg {
  color: rgba(255,255,255,0.4);
  font-family: monospace;
  font-size: clamp(12px, 3vw, 16px);
  text-align: center;
  padding: 0 24px;
  margin-top: 16px;
  display: none;
}

#help-info {
  margin-top: 0;
  width: min(420px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.help-block {
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.help-icon {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}
.help-text {
  font-family: monospace;
  font-size: clamp(10px, 2.5vw, 12px);
  color: rgba(255,255,255,0.45);
  line-height: 1.6;
}
.help-text b {
  color: rgba(255,255,255,0.7);
  font-weight: normal;
}

#game-wrap {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56vh;
  display: flex; align-items: flex-start; justify-content: center;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top center;
  image-rendering: pixelated;
}

@media (orientation: landscape) {
  #game-wrap {
    inset: 0;
    height: 100vh;
    align-items: center;
  }
  #game-canvas { height: 100vh; }
}

/* ── Virtual Gamepad ─────────────────────────────────── */
#gamepad {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 50;
  display: none;
}
#gamepad.visible { display: block; }

/* D-pad — --dp controla separación entre flechas (default 0 = pegadas) */
:root { --dp: 0px; }
#dpad {
  position: absolute;
  left: 20px;
  bottom: 140px;
  width: calc(132px + 2 * var(--dp));
  height: calc(132px + 2 * var(--dp));
}
.dpad-btn {
  position: absolute;
  pointer-events: all;
  touch-action: none;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.35);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.7);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.dpad-btn.pressed { background: rgba(255,255,255,0.45); }
#dpad-up    { top:0;                         left:calc(44px + var(--dp)); width:44px; height:44px; border-radius:8px; }
#dpad-down  { bottom:0;                      left:calc(44px + var(--dp)); width:44px; height:44px; border-radius:8px; }
#dpad-left  { top:calc(44px + var(--dp));    left:0;                      width:44px; height:44px; border-radius:8px; }
#dpad-right { top:calc(44px + var(--dp));    right:0;                     width:44px; height:44px; border-radius:8px; }

/* Triángulos CSS */
.dpad-btn::after {
  content: '';
  display: block;
  width: 0; height: 0;
  border: 8px solid transparent;
}
#dpad-up::after    { border-bottom: 12px solid rgba(255,255,255,0.8); margin-top: -4px; }
#dpad-down::after  { border-top:    12px solid rgba(255,255,255,0.8); margin-top:  4px; }
#dpad-left::after  { border-right:  12px solid rgba(255,255,255,0.8); margin-left: -4px; }
#dpad-right::after { border-left:   12px solid rgba(255,255,255,0.8); margin-left:  4px; }

/* Botones de acción */
.btn {
  position: absolute;
  pointer-events: all;
  touch-action: none;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.7);
  font-family: monospace;
  font-weight: bold;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn.pressed { background: rgba(255,255,255,0.45); }
.btn.hidden  { display: none !important; }

/* ── Botones de acción (portrait) ── */
:root { --sp: 56px; }
#btn-b { right: calc(16px + var(--sp));  bottom: calc(140px + var(--sp)); width: 52px; height: 52px; font-size: 15px; }
#btn-a { right: 16px;                    bottom: 140px;                   width: 52px; height: 52px; font-size: 15px; }
#btn-x { right: calc(16px + 2*var(--sp)); bottom: 140px;                  width: 52px; height: 52px; font-size: 15px; }
#btn-y { right: calc(16px + var(--sp));  bottom: calc(140px - var(--sp)); width: 52px; height: 52px; font-size: 15px; }

/* Botones extra Mega Drive (2 filas de 3: X Y Z / A B C) */
#btn-md-x { right: calc(16px + 2 * var(--sp));  bottom: calc(140px + var(--sp));  width: 46px; height: 46px; font-size: 14px; }
#btn-md-y { right: calc(16px + var(--sp));       bottom: calc(140px + var(--sp));  width: 46px; height: 46px; font-size: 14px; }
#btn-md-z { right: calc(16px);                   bottom: calc(140px + var(--sp));  width: 46px; height: 46px; font-size: 14px; }
#btn-md-a { right: calc(16px + 2 * var(--sp));  bottom: calc(140px);              width: 46px; height: 46px; font-size: 14px; }
#btn-md-b { right: calc(16px + var(--sp));       bottom: calc(140px);              width: 46px; height: 46px; font-size: 14px; }
#btn-md-c { right: calc(16px);                   bottom: calc(140px);              width: 46px; height: 46px; font-size: 14px; }

/* Shoulder buttons */
#btn-l  { left:16px;  top:24px; width:64px; height:32px; border-radius:16px; font-size:13px; }
#btn-r  { right:16px; top:24px; width:64px; height:32px; border-radius:16px; font-size:13px; }
#btn-l2 { left:16px;  top:64px; width:64px; height:32px; border-radius:16px; font-size:13px; }
#btn-r2 { right:16px; top:64px; width:64px; height:32px; border-radius:16px; font-size:13px; }

/* SELECT / START */
#btn-select { left:50%; bottom:24px; transform:translateX(-84px); width:72px; height:30px; border-radius:15px; font-size:11px; }
#btn-start  { left:50%; bottom:24px; transform:translateX(12px);  width:72px; height:30px; border-radius:15px; font-size:11px; }

/* Guardar */
#btn-save {
  position: absolute;
  pointer-events: all;
  touch-action: none;
  left: 16px; top: 104px;
  width: 64px; height: 32px;
  border-radius: 16px;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.35);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.7);
  font-family: monospace;
  font-weight: bold;
  font-size: 11px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#btn-save.pressed { background: rgba(255,255,255,0.45); }
#btn-save.saved   { border-color: rgba(100,255,100,0.7); color: rgba(100,255,100,0.9); }

/* ── Botón de configuración ── */
#btn-settings {
  position: fixed;
  bottom: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  display: none;
  align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer;
  pointer-events: all;
  z-index: 60;
  -webkit-tap-highlight-color: transparent;
}
#btn-settings.visible { display: flex; }

/* ── Panel de configuración ── */
#settings-panel {
  position: fixed;
  bottom: -100%;
  left: 0; right: 0;
  background: #1a1a1a;
  border-top: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px 40px;
  z-index: 200;
  transition: bottom 0.3s ease;
  pointer-events: all;
  max-height: 80vh;
  overflow-y: auto;
}
#settings-panel.open { bottom: 0; }

.settings-title {
  font-family: monospace;
  color: rgba(255,255,255,0.9);
  font-size: 16px;
  letter-spacing: 0.1em;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.settings-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  pointer-events: all;
}
.settings-section { margin-bottom: 20px; }
.settings-section-title {
  font-family: monospace;
  color: rgba(255,255,255,0.4);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.settings-label {
  font-family: monospace;
  color: rgba(255,255,255,0.8);
  font-size: 14px;
}
/* Toggle */
.toggle {
  position: relative;
  width: 48px; height: 26px;
  pointer-events: all;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.2);
  border-radius: 13px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: rgba(100,200,100,0.7); }
.toggle input:checked + .toggle-slider::before { transform: translateX(22px); }

/* Slider */
.settings-slider {
  width: 110px;
  accent-color: rgba(255,255,255,0.8);
  cursor: pointer;
}
.settings-value {
  font-family: monospace;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  min-width: 28px;
  text-align: right;
}

/* Botones de posición */
.pos-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.pos-group-label {
  font-family: monospace;
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  margin-bottom: 4px;
}
.pos-arrows {
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 36px);
  gap: 2px;
}
.pos-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  pointer-events: all;
  -webkit-tap-highlight-color: transparent;
}
.pos-btn:active { background: rgba(255,255,255,0.3); }
.pos-btn.empty { background: none; border: none; pointer-events: none; }
.pos-coords {
  font-family: monospace;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  text-align: center;
  margin-top: 4px;
  letter-spacing: 0.5px;
}
.pos-reset {
  margin-top: 6px;
  font-family: monospace;
  font-size: 11px;
  color: rgba(255,100,100,0.7);
  background: none;
  border: 1px solid rgba(255,100,100,0.3);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  pointer-events: all;
}

/* ── Joystick ── */
#joystick-wrap {
  position: absolute;
  display: none;
  pointer-events: all;
  touch-action: none;
}
#joystick-wrap.visible { display: block; }
#joystick-base {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.2);
  position: relative;
}
#joystick-knob {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  border: 2px solid rgba(255,255,255,0.5);
  position: absolute;
  top: 35px; left: 35px;
  pointer-events: none;
  transition: none;
}

/* ── Landscape ── */
@media (orientation: landscape) {
  #dpad {
    left: max(20px, env(safe-area-inset-left) + 8px);
    bottom: 50%;
    transform: translateY(66px);
  }
  #btn-l  { left: max(16px, env(safe-area-inset-left) + 4px); top: 10px; width:60px; height:28px; }
  #btn-l2 { left: max(16px, env(safe-area-inset-left) + 4px); top: 46px; width:60px; height:28px; }
  #btn-r  { right: max(16px, env(safe-area-inset-right) + 4px); top: 10px; width:60px; height:28px; }
  #btn-r2 { right: max(16px, env(safe-area-inset-right) + 4px); top: 46px; width:60px; height:28px; }
  #btn-b  { right: calc(max(16px, env(safe-area-inset-right) + 4px) + var(--sp));       bottom: calc(50% + var(--sp)); transform: translateY(0);  width:48px; height:48px; font-size:14px; }
  #btn-a  { right: max(16px, env(safe-area-inset-right) + 4px);                         bottom: 50%;                  transform: translateY(0);  width:48px; height:48px; font-size:14px; }
  #btn-x  { right: calc(max(16px, env(safe-area-inset-right) + 4px) + 2*var(--sp));     bottom: 50%;                  transform: translateY(0);  width:48px; height:48px; font-size:14px; }
  #btn-y  { right: calc(max(16px, env(safe-area-inset-right) + 4px) + var(--sp));       bottom: calc(50% - var(--sp)); transform: translateY(0);  width:48px; height:48px; font-size:14px; }
  #btn-select {
    left: 50%; bottom: 10px;
    transform: translateX(calc(-84px - env(safe-area-inset-left, 0px) / 4));
  }
  #btn-start {
    left: 50%; bottom: 10px;
    transform: translateX(calc(12px + env(safe-area-inset-right, 0px) / 4));
  }
  #btn-save { left: max(16px, env(safe-area-inset-left) + 4px); top: 50px; width:60px; height:28px; }
  #gamepad.two-btn #btn-b { right: calc(max(16px, env(safe-area-inset-right) + 4px) + var(--sp)); bottom: 50%; transform: translateY(0); }
  #gamepad.two-btn #btn-a { right: max(16px, env(safe-area-inset-right) + 4px);                   bottom: 50%; transform: translateY(0); }
  #btn-md-x { right: calc(max(16px, env(safe-area-inset-right) + 4px) + 2 * var(--sp));  bottom: calc(50% + var(--sp)); transform: translateY(0); width:44px; height:44px; font-size:13px; }
  #btn-md-y { right: calc(max(16px, env(safe-area-inset-right) + 4px) + var(--sp));       bottom: calc(50% + var(--sp)); transform: translateY(0); width:44px; height:44px; font-size:13px; }
  #btn-md-z { right: calc(max(16px, env(safe-area-inset-right) + 4px));                   bottom: calc(50% + var(--sp)); transform: translateY(0); width:44px; height:44px; font-size:13px; }
  #btn-md-a { right: calc(max(16px, env(safe-area-inset-right) + 4px) + 2 * var(--sp));  bottom: 50%;                   transform: translateY(0); width:44px; height:44px; font-size:13px; }
  #btn-md-b { right: calc(max(16px, env(safe-area-inset-right) + 4px) + var(--sp));       bottom: 50%;                   transform: translateY(0); width:44px; height:44px; font-size:13px; }
  #btn-md-c { right: calc(max(16px, env(safe-area-inset-right) + 4px));                   bottom: 50%;                   transform: translateY(0); width:44px; height:44px; font-size:13px; }
}

/* ── Modal confirmación final ── */
#delete-confirm-modal {
  display: none;
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
#delete-confirm-modal.open { display: flex; }
.modal-box {
  background: #1a1a1a;
  border: 1px solid rgba(255,80,80,0.5);
  border-radius: 14px;
  padding: 28px 24px 22px;
  max-width: 300px; width: 90%;
  text-align: center;
  display: flex; flex-direction: column; gap: 16px;
}
.modal-icon { font-size: 2rem; }
.modal-title {
  font-family: inherit; font-size: 0.95rem;
  color: #f87171; letter-spacing: 1px; font-weight: 700;
}
.modal-body {
  font-family: inherit; font-size: 0.78rem;
  color: rgba(255,255,255,0.55); line-height: 1.5;
}
.modal-actions { display: flex; gap: 10px; }
.modal-btn {
  flex: 1; padding: 11px 0; border-radius: 8px; border: none;
  font-family: inherit; font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.5px; cursor: pointer;
}
.modal-btn-cancel  { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.6); }
.modal-btn-confirm { background: #f87171; color: #000; }

/* ── Unlock screen ───────────────────────────────────────────────────────── */
#unlock-screen {
  position: fixed; inset: 0; z-index: 300;
  background: #050508;
  display: flex; flex-direction: column; align-items: center;
  gap: 20px; padding: 24px 24px 32px; box-sizing: border-box;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  opacity: 0; transition: opacity .6s ease;
}
/* Centra el contenido cuando entra en pantalla; si desborda, queda arriba y scrollea */
#unlock-screen::before,
#unlock-screen::after  { content: ''; flex: 1; }
#unlock-screen.visible { opacity: 1; }
#unlock-screen.hidden  { display: none; }
.unlock-title {
  font-family: monospace; font-size: 0.7rem; letter-spacing: 4px;
  color: rgba(255,255,255,0.35); text-transform: uppercase; text-align: center;
}
.unlock-level {
  font-family: monospace; font-size: 2rem; font-weight: 700;
  color: #a78bfa; letter-spacing: 2px; text-align: center;
}
.unlock-subtitle {
  font-family: monospace; font-size: 0.75rem; letter-spacing: 1px;
  color: rgba(255,255,255,0.5); text-align: center; margin-top: -16px;
}
.unlock-choices {
  display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px;
}
.unlock-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(167,139,250,0.25);
  border-radius: 12px; padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
  cursor: pointer; transition: background .2s, border-color .2s, opacity .4s, transform .4s;
  -webkit-tap-highlight-color: transparent;
}
.unlock-card:active, .unlock-card.hover { background: rgba(167,139,250,0.12); border-color: #a78bfa; }
.unlock-card.chosen  { border-color: #a78bfa; background: rgba(167,139,250,0.18); }
.unlock-card.faded   { opacity: 0.2; transform: scale(0.97); pointer-events: none; }
.unlock-card img {
  width: 52px; height: 52px; object-fit: cover;
  border-radius: 6px; background: rgba(255,255,255,0.06); flex-shrink: 0;
}
.unlock-card-img-placeholder {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 6px;
  background: rgba(167,139,250,0.12); border: 1px solid rgba(167,139,250,0.2);
  display: flex; align-items: center; justify-content: center;
  font-family: monospace; font-size: 0.45rem; color: rgba(255,255,255,0.3);
  text-align: center; padding: 2px; line-height: 1.3;
}
.unlock-card-info { flex: 1; min-width: 0; }
.unlock-card-name {
  font-family: monospace; font-size: 0.82rem; font-weight: 700;
  color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.unlock-card-meta {
  font-family: monospace; font-size: 0.68rem;
  color: rgba(255,255,255,0.35); margin-top: 3px;
}
.unlock-card-check { font-size: 1.2rem; opacity: 0; transition: opacity .3s; }
.unlock-card.chosen .unlock-card-check { opacity: 1; }

/* Árbol visual */
#unlock-tree-btn {
  font-family: monospace; font-size: 0.68rem; letter-spacing: 1px;
  color: rgba(167,139,250,0.5); background: none; border: none;
  cursor: pointer; padding: 4px 8px; text-decoration: underline;
}
#unlock-prev-btn {
  font-family: monospace; font-size: 0.68rem; letter-spacing: 1px;
  color: rgba(251,191,36,0.55); background: none; border: none;
  cursor: pointer; padding: 6px 8px; text-decoration: underline; margin-top: 4px;
}
#unlock-prev-btn.hidden { display: none; }
#unlock-rejected-wrap { width: 100%; max-width: 520px; margin-top: 8px; }
#unlock-rejected-wrap.hidden { display: none; }
.unlock-rejected-title {
  font-family: monospace; font-size: 0.6rem; letter-spacing: 2px;
  color: rgba(251,191,36,0.4); text-align: center; margin-bottom: 10px;
}
.unlock-rejected-item {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.07);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 7px;
  cursor: pointer; transition: border-color .2s, background .2s;
}
.unlock-rejected-item:hover { background: rgba(167,139,250,0.08); border-color: rgba(167,139,250,0.3); }
.unlock-rejected-item img {
  width: 42px; height: 42px; object-fit: cover; border-radius: 4px; flex-shrink: 0;
}
.unlock-rejected-img-placeholder {
  width: 42px; height: 42px; background: rgba(255,255,255,0.06); border-radius: 4px;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-family: monospace; font-size: 0.5rem; color: rgba(255,255,255,0.2); text-align: center;
}
.unlock-rejected-name {
  font-family: monospace; font-size: 0.82rem; font-weight: 700; color: #e0e0e0;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.unlock-rejected-meta { font-family: monospace; font-size: 0.62rem; color: rgba(255,255,255,0.3); margin-top: 2px; }
.unlock-rejected-pick {
  font-family: monospace; font-size: 0.62rem; letter-spacing: 1px; font-weight: 700;
  color: #fbbf24; background: rgba(251,191,36,0.1); border: 1px solid rgba(251,191,36,0.25);
  border-radius: 4px; padding: 4px 10px; cursor: pointer; flex-shrink: 0; transition: all .2s;
}
.unlock-rejected-pick:hover { background: rgba(251,191,36,0.2); }

#tree-panel {
  position: fixed; inset: 0; z-index: 310;
  background: #050508;
  display: flex; flex-direction: column; align-items: center;
  padding: 24px; box-sizing: border-box; gap: 12px; overflow-y: auto;
}
#tree-panel.hidden { display: none; }
.tree-header { text-align: center; }
.tree-title {
  font-family: monospace; font-size: 0.75rem; letter-spacing: 3px;
  color: rgba(255,255,255,0.4); text-transform: uppercase;
}
.tree-subtitle {
  font-family: monospace; font-size: 0.62rem; letter-spacing: 1px;
  color: rgba(167,139,250,0.4); margin-top: 4px;
}
#tree-canvas-wrap { width: 100%; max-width: 560px; overflow-x: auto; }
.tree-node {
  display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px;
}
.tree-node-line { display: flex; flex-direction: column; align-items: center; }
.tree-dot { width: 10px; height: 10px; border-radius: 50%; background: #a78bfa; flex-shrink: 0; margin-top: 4px; }
.tree-connector { width: 2px; flex: 1; min-height: 36px; background: rgba(167,139,250,0.18); }
.tree-body { flex: 1; min-width: 0; }
.tree-level-label {
  font-family: monospace; font-size: 0.6rem; letter-spacing: 2px;
  color: rgba(167,139,250,0.6); margin-bottom: 4px;
}
.tree-chosen {
  font-family: monospace; font-size: 0.85rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-chosen-meta { font-family: monospace; font-size: 0.65rem; color: rgba(255,255,255,0.3); margin-top: 2px; }
.tree-rejected-label {
  font-family: monospace; font-size: 0.6rem; color: rgba(255,255,255,0.18);
  margin-top: 6px; letter-spacing: 0.5px;
}
.tree-rejected-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.tree-rejected-chip {
  font-family: monospace; font-size: 0.6rem; letter-spacing: 0.5px;
  color: rgba(255,255,255,0.25); background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07); border-radius: 4px; padding: 2px 8px;
}
.tree-rejected-chip.reclaimable {
  color: rgba(251,191,36,0.6); background: rgba(251,191,36,0.06);
  border-color: rgba(251,191,36,0.2); cursor: pointer;
}
.tree-rejected-chip.reclaimable:hover { background: rgba(251,191,36,0.14); }
#tree-close {
  font-family: monospace; font-size: 0.75rem; letter-spacing: 1px;
  color: rgba(255,255,255,0.3); background: none; border: none;
  cursor: pointer; padding: 8px 16px;
}

/* ── Auth panel ──────────────────────────────────────────────────────────── */
#auth-panel {
  position: fixed; inset: 0; z-index: 200;
  background: #0a0a0a;
  display: flex; align-items: center; justify-content: center;
}
#auth-panel.hidden { display: none; }

/* ── Activation panel ────────────────────────────────────────────────────── */
#activation-panel {
  position: fixed; inset: 0; z-index: 200;
  background: #0a0a0a;
  display: flex; align-items: center; justify-content: center;
}
#activation-panel.hidden { display: none; }
.activation-game { font-family: monospace; font-size: 0.9rem; letter-spacing: 2px; color: #a78bfa; text-align: center; margin-bottom: 4px; }
.activation-hint { font-family: monospace; font-size: 0.72rem; color: rgba(255,255,255,0.3); text-align: center; line-height: 1.6; margin-bottom: 16px; }
.auth-box {
  width: min(340px, 90vw);
  display: flex; flex-direction: column; gap: 20px;
}
.auth-logo {
  font-family: monospace; font-size: 1.3rem; font-weight: 700;
  letter-spacing: 3px; color: #fff; text-align: center;
}
.auth-logo span { color: #a78bfa; }
.auth-tabs { display: flex; border-bottom: 1px solid rgba(255,255,255,0.1); }
.auth-tab {
  flex: 1; padding: 10px 0;
  background: none; border: none; cursor: pointer;
  font-family: monospace; font-size: 0.8rem; letter-spacing: 1px;
  color: rgba(255,255,255,0.35); font-weight: 700; transition: color .2s;
}
.auth-tab.active { color: #fff; border-bottom: 2px solid #a78bfa; margin-bottom: -1px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }
.auth-input {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 12px 14px;
  font-family: monospace; font-size: 0.85rem; color: #fff;
  outline: none; width: 100%; box-sizing: border-box; transition: border-color .2s;
}
.auth-input:focus { border-color: #a78bfa; }
.auth-input::placeholder { color: rgba(255,255,255,0.25); }
.auth-btn {
  background: #a78bfa; color: #000;
  border: none; border-radius: 8px; padding: 13px;
  font-family: monospace; font-size: 0.85rem; font-weight: 700;
  letter-spacing: 1px; cursor: pointer; transition: opacity .2s;
}
.auth-btn:disabled { opacity: 0.5; cursor: default; }
.auth-hint {
  font-family: monospace; font-size: 0.72rem;
  color: rgba(255,255,255,0.3); text-align: center; line-height: 1.5;
}
.auth-error {
  font-family: monospace; font-size: 0.75rem;
  color: #f87171; text-align: center; min-height: 16px;
}

/* ── Level-up screen ─────────────────────────────────────────────────────── */
#levelup-screen {
  position: fixed; inset: 0; z-index: 350;
  background: #050508;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 24px;
  opacity: 0; transition: opacity .5s ease;
}
#levelup-screen.visible { opacity: 1; }
#levelup-screen.hidden  { display: none; }
.levelup-supra {
  font-family: monospace; font-size: 0.6rem; letter-spacing: 6px;
  color: rgba(255,255,255,0.28); text-transform: uppercase;
}
.levelup-number {
  font-family: monospace; font-size: 6.5rem; font-weight: 700; line-height: 1;
  color: #a78bfa;
  text-shadow: 0 0 60px rgba(167,139,250,0.65), 0 0 120px rgba(167,139,250,0.25);
  transform: scale(0.4);
  transition: transform .75s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  letter-spacing: -4px;
}
#levelup-screen.visible .levelup-number { transform: scale(1); }
.levelup-label {
  font-family: monospace; font-size: 0.8rem; letter-spacing: 5px;
  color: rgba(255,255,255,0.65); text-transform: uppercase; margin-top: 6px;
}
.levelup-time {
  font-family: monospace; font-size: 0.68rem;
  color: rgba(255,255,255,0.22); letter-spacing: 1px; margin-top: 10px;
}
.levelup-btn {
  margin-top: 32px;
  background: #a78bfa; color: #000;
  border: none; border-radius: 8px; padding: 14px 40px;
  font-family: monospace; font-size: 0.85rem; font-weight: 700;
  letter-spacing: 2px; cursor: pointer;
  opacity: 0; transition: opacity .5s ease .65s;
  pointer-events: none;
}
#levelup-screen.visible .levelup-btn { opacity: 1; pointer-events: all; }

/* ── HUD de progreso ─────────────────────────────────────────────────────── */
#hud {
  position: fixed;
  top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 55;
  display: flex; flex-direction: row; align-items: center; gap: 7px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 20px; padding: 5px 12px;
  pointer-events: all;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
#hud.visible { opacity: 1; pointer-events: all; }
.hud-star { font-size: 11px; line-height: 1; }
.hud-level-num {
  font-family: monospace; font-size: 11px; font-weight: 700;
  color: rgba(255,255,255,0.8); letter-spacing: 1px; min-width: 10px;
}
.hud-bar-wrap {
  width: 48px; height: 3px;
  background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden;
}
.hud-bar {
  height: 100%; background: #a78bfa; border-radius: 2px;
  width: 0%; transition: width .6s ease;
}

/* ── Pantalla de perfil ───────────────────────────────────────────────────── */
#profile-screen {
  position: fixed; inset: 0; z-index: 250;
  background: #050508;
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px 20px 48px; gap: 0;
}
#profile-screen.hidden { display: none; }
.profile-close {
  align-self: flex-end;
  background: none; border: none;
  font-family: monospace; font-size: 0.78rem; letter-spacing: 1px;
  color: rgba(255,255,255,0.28); cursor: pointer; padding: 0 0 20px;
}
.profile-username {
  font-family: monospace; font-size: 1.35rem; font-weight: 700;
  color: #fff; letter-spacing: 3px; text-align: center; margin-bottom: 4px;
}
.profile-nivel-label {
  font-family: monospace; font-size: 0.63rem; letter-spacing: 4px;
  color: rgba(167,139,250,0.55); text-transform: uppercase; text-align: center;
  margin-bottom: 22px;
}
.profile-progress-wrap {
  width: 100%; max-width: 320px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px; padding: 16px; margin-bottom: 14px;
}
.profile-progress-header {
  display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px;
}
.profile-progress-level {
  font-family: monospace; font-size: 0.95rem; font-weight: 700; color: #a78bfa;
}
.profile-progress-pct {
  font-family: monospace; font-size: 0.68rem; color: rgba(255,255,255,0.28); letter-spacing: 1px;
}
.profile-bar-wrap {
  width: 100%; height: 5px;
  background: rgba(255,255,255,0.07); border-radius: 3px; overflow: hidden; margin-bottom: 8px;
}
.profile-bar {
  height: 100%; background: #a78bfa; border-radius: 3px;
  width: 0%; transition: width .7s ease;
}
.profile-bar-labels { display: flex; justify-content: space-between; }
.profile-bar-label {
  font-family: monospace; font-size: 0.62rem; color: rgba(255,255,255,0.18); letter-spacing: 0.5px;
}
.profile-stats {
  width: 100%; max-width: 320px; display: flex; gap: 10px; margin-bottom: 22px;
}
.profile-stat {
  flex: 1; background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07); border-radius: 10px;
  padding: 12px; text-align: center;
}
.profile-stat-val {
  font-family: monospace; font-size: 1.05rem; font-weight: 700;
  color: #fff; display: block; margin-bottom: 4px;
}
.profile-stat-label {
  font-family: monospace; font-size: 0.58rem; letter-spacing: 1px;
  color: rgba(255,255,255,0.22); text-transform: uppercase;
}
.profile-section-title {
  width: 100%; max-width: 320px;
  font-family: monospace; font-size: 0.62rem; letter-spacing: 3px;
  color: rgba(255,255,255,0.22); text-transform: uppercase;
  margin-bottom: 12px; margin-top: 4px;
}
.profile-games-grid {
  width: 100%; max-width: 320px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px;
}
.profile-game-card {
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.07);
  border-radius: 8px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.profile-game-img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 4px; background: rgba(255,255,255,0.06);
}
.profile-game-name {
  font-family: monospace; font-size: 0.54rem;
  color: rgba(255,255,255,0.45); text-align: center;
  line-height: 1.3; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.profile-tree-link {
  font-family: monospace; font-size: 0.68rem; letter-spacing: 1px;
  color: rgba(167,139,250,0.45); background: none; border: none;
  cursor: pointer; padding: 8px 16px; text-decoration: underline; margin-top: 4px;
}
.profile-empty {
  font-family: monospace; font-size: 0.72rem;
  color: rgba(255,255,255,0.2); text-align: center; padding: 16px 0; line-height: 1.6;
}

/* ── Botón catálogo ──────────────────────────────────────────────────────────── */
#catalog-btn {
  background: transparent;
  border: 1px solid rgba(167,139,250,0.4);
  color: rgba(167,139,250,0.7);
  font-size: clamp(13px, 3.5vw, 17px);
  font-family: monospace;
  letter-spacing: 0.15em;
  padding: 11px 36px;
  cursor: pointer;
  border-radius: 4px;
  margin-top: 14px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, color 0.2s;
}
#catalog-btn:active { background: rgba(167,139,250,0.1); color: #a78bfa; }
#catalog-btn.hidden { display: none; }

/* ── Pantalla catálogo ───────────────────────────────────────────────────────── */
#catalog-screen {
  position: fixed; inset: 0; z-index: 280;
  background: #080808;
  display: flex; flex-direction: column;
  overflow: hidden;
}
#catalog-screen.hidden { display: none; }

.catalog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.catalog-title {
  font-family: monospace; font-size: 0.75rem; letter-spacing: 3px;
  color: rgba(255,255,255,0.5);
}
.catalog-close {
  background: none; border: none; color: rgba(255,255,255,0.4);
  font-size: 1rem; cursor: pointer; padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

#catalog-grid {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.catalog-card {
  display: flex; gap: 14px; align-items: flex-start;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px; padding: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.catalog-card:active { background: rgba(167,139,250,0.08); border-color: rgba(167,139,250,0.3); }

.catalog-card-img {
  width: 72px; height: 72px; flex-shrink: 0;
  border-radius: 8px; object-fit: cover;
  background: rgba(255,255,255,0.05);
}
.catalog-card-img-placeholder {
  width: 72px; height: 72px; flex-shrink: 0;
  border-radius: 8px; background: rgba(167,139,250,0.1);
  border: 1px solid rgba(167,139,250,0.15);
  display: flex; align-items: center; justify-content: center;
  font-family: monospace; font-size: 0.5rem;
  color: rgba(255,255,255,0.25); text-align: center; padding: 4px;
  line-height: 1.4;
}
.catalog-card-body {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px;
}
.catalog-card-name {
  font-family: monospace; font-size: 0.8rem; font-weight: bold;
  color: rgba(255,255,255,0.85); letter-spacing: 0.5px;
  line-height: 1.3;
}
.catalog-card-meta {
  font-family: monospace; font-size: 0.62rem;
  color: rgba(255,255,255,0.3); letter-spacing: 0.5px;
}
.catalog-card-genre {
  font-family: monospace; font-size: 0.58rem;
  color: rgba(167,139,250,0.5); margin-top: 2px;
}
.catalog-card-play {
  display: inline-block; margin-top: 8px;
  background: none; border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7); font-family: monospace;
  font-size: 0.62rem; letter-spacing: 1px;
  padding: 5px 14px; border-radius: 4px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
  align-self: flex-start;
}
.catalog-card-play:active { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.5); }

.catalog-empty {
  text-align: center; padding: 60px 24px;
  font-family: monospace; font-size: 0.75rem;
  color: rgba(255,255,255,0.2); line-height: 2;
  letter-spacing: 0.5px;
}
