:root {
  color-scheme: dark;
  --background: #050818;
  --surface: rgba(12, 18, 48, 0.96);
  --surface-soft: rgba(18, 27, 68, 0.82);
  --border: rgba(94, 119, 255, 0.34);
  --text: #f7f8ff;
  --muted: #a8b1d8;
  --cyan: #33e7ff;
  --blue: #5576ff;
  --purple: #a553ff;
  --pink: #ff4fd8;
  --green: #48e37e;
  --yellow: #ffd54a;
  --danger: #ff5975;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -20%, rgba(78, 70, 255, 0.42), transparent 42%),
    radial-gradient(circle at 100% 20%, rgba(212, 52, 255, 0.18), transparent 34%),
    linear-gradient(180deg, #090d28 0%, #050818 70%);
}
body.game-active {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(51, 231, 255, 0.62);
  outline-offset: 2px;
}

.app-shell { width: min(1180px, 100%); margin: 0 auto; padding: 14px; }

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(320px, 1.45fr) auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(8, 13, 37, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 900;
  font-style: italic;
  text-decoration: none;
  letter-spacing: -0.06em;
}
.brand strong { color: var(--cyan); text-shadow: 0 0 24px rgba(51, 231, 255, 0.7); }
.brand-mark { color: var(--pink); transform: skewX(-14deg); }

.player-card { display: flex; gap: 12px; align-items: center; min-width: 0; }
.avatar {
  display: grid;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(51, 231, 255, 0.5);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(51, 231, 255, 0.22), rgba(165, 83, 255, 0.3));
}
.nickname-form { display: grid; gap: 5px; min-width: 0; width: 100%; }
.nickname-form label { color: var(--muted); font-size: 0.74rem; font-weight: 750; }
.nickname-row { display: flex; gap: 7px; min-width: 0; }
.nickname-row input {
  min-width: 0;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: rgba(5, 9, 28, 0.84);
}
.nickname-form small { color: var(--muted); }
.nickname-status { min-height: 1em; color: var(--green); font-size: 0.75rem; }
.nickname-status.is-error { color: var(--danger); }

.topbar-actions { display: grid; gap: 8px; justify-items: end; }
.currencies { display: flex; gap: 7px; }
.currencies span {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  white-space: nowrap;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(15, 23, 60, 0.96), rgba(7, 12, 34, 0.97));
  box-shadow: var(--shadow);
  overflow: hidden;
}
.levels-panel, .community-panel { padding: 20px; }
.panel-heading { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.panel-heading.compact { align-items: center; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { margin-bottom: 10px; font-size: 1.3rem; }
.eyebrow { color: var(--cyan); font-size: 0.72rem; font-weight: 850; letter-spacing: 0.1em; text-transform: uppercase; }
.panel-copy { color: var(--muted); line-height: 1.55; }
.star-total { color: var(--yellow); font-weight: 850; white-space: nowrap; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(84px, 1fr));
  gap: 9px;
  margin: 20px 0;
}
.level-card {
  position: relative;
  display: grid;
  min-height: 112px;
  padding: 10px;
  align-content: center;
  justify-items: center;
  gap: 4px;
  border: 1px solid rgba(85, 118, 255, 0.45);
  border-radius: 14px;
  color: var(--text);
  background: linear-gradient(160deg, rgba(48, 65, 151, 0.82), rgba(18, 29, 81, 0.88));
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.level-card:hover:not(:disabled), .level-card.is-selected {
  transform: translateY(-3px);
  border-color: var(--cyan);
  box-shadow: 0 0 22px rgba(51, 231, 255, 0.22);
}
.level-card:disabled { opacity: 0.46; filter: grayscale(0.5); }
.level-number { font-size: 1.6rem; font-weight: 950; }
.level-card-name { max-width: 100%; overflow: hidden; color: var(--muted); font-size: 0.72rem; text-overflow: ellipsis; white-space: nowrap; }
.level-stars { color: var(--yellow); font-size: 0.8rem; letter-spacing: 0.04em; }
.level-lock { position: absolute; top: 6px; right: 7px; }

.selected-level-card {
  display: grid;
  gap: 15px;
  padding: 18px;
  border: 1px solid rgba(51, 231, 255, 0.28);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(51, 231, 255, 0.09), rgba(165, 83, 255, 0.13)),
    rgba(7, 12, 34, 0.74);
}
.selected-level-card h2 { margin: 3px 0 7px; font-size: 1.55rem; }
.selected-level-card p { margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.selected-level-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}
.selected-level-stats div {
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(6, 11, 32, 0.72);
}
.selected-level-stats dt { color: var(--muted); font-size: 0.72rem; }
.selected-level-stats dd { margin: 3px 0 0; font-weight: 850; }
.play-button { width: 100%; min-height: 54px; font-size: 1.05rem; }

.feature-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 15px;
}
.feature-strip article {
  display: grid;
  gap: 4px;
  min-height: 102px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(15, 24, 63, 0.64);
}
.feature-strip article > span { font-size: 1.3rem; }
.feature-strip small { color: var(--muted); line-height: 1.35; }

.tab-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 18px; }
.tab-button {
  padding: 10px 7px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--muted);
  background: rgba(17, 26, 68, 0.74);
}
.tab-button.is-active { border-color: var(--cyan); color: var(--text); background: rgba(51, 231, 255, 0.1); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.leaderboard-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.leaderboard-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(13, 21, 57, 0.76);
}
.leaderboard-item.is-me { border-color: var(--cyan); box-shadow: 0 0 18px rgba(51, 231, 255, 0.14); }
.rank { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: rgba(85, 118, 255, 0.22); font-weight: 900; }
.runner-name { display: grid; min-width: 0; }
.runner-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runner-name small { color: var(--muted); }
.runner-score { color: var(--yellow); font-weight: 900; }
.empty-state { padding: 24px 12px; color: var(--muted); text-align: center; }

.store-list { display: grid; gap: 9px; }
.store-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(13, 21, 57, 0.76);
}
.store-card div { display: grid; }
.store-card small { color: var(--muted); }
.store-card button { padding: 7px; border: 0; border-radius: 8px; color: var(--muted); background: rgba(255,255,255,0.07); }
.store-icon { font-size: 1.45rem; }

.creator-form { display: grid; gap: 12px; }
.creator-form label { display: grid; gap: 6px; color: var(--muted); font-size: 0.82rem; font-weight: 750; }
.creator-form input, .creator-form textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: rgba(5, 9, 28, 0.86);
}
.creator-form textarea { min-height: 245px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.76rem; }
.form-output { color: var(--green); font-size: 0.82rem; }
.form-output.is-error { color: var(--danger); }

.button, .icon-button {
  border: 1px solid transparent;
  color: var(--text);
  font-weight: 850;
}
.button { padding: 10px 14px; border-radius: 11px; }
.button-small { padding: 8px 10px; }
.button-primary { background: linear-gradient(135deg, var(--cyan), var(--purple)); color: #050818; }
.button-secondary { border-color: var(--border); background: rgba(17, 28, 74, 0.9); }
.button:disabled { opacity: 0.48; }
.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-color: var(--border);
  border-radius: 11px;
  background: rgba(11, 18, 52, 0.9);
}
.danger-button { border-color: rgba(255, 89, 117, 0.42); color: var(--danger); }
.is-hidden { display: none !important; }

.game-stage {
  position: fixed;
  inset: 0;
  z-index: 1000;
  visibility: hidden;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  background: #050818;
  transition: opacity 150ms ease, visibility 150ms ease;
  touch-action: none;
  overscroll-behavior: none;
}
.game-stage.is-active { visibility: visible; opacity: 1; pointer-events: auto; }
.game-container { position: absolute; inset: 0; display: grid; place-items: center; touch-action: none; }
.game-container canvas { display: block; max-width: 100%; max-height: 100%; touch-action: none; }
.game-toolbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  left: max(8px, env(safe-area-inset-left));
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(94, 119, 255, 0.38);
  border-radius: 13px;
  background: rgba(5, 8, 24, 0.74);
  backdrop-filter: blur(10px);
}
.game-level-title { display: grid; min-width: 0; }
.game-level-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-inline { display: flex; gap: 7px; }
.hud-inline span { padding: 7px 9px; border-radius: 9px; background: rgba(18, 27, 68, 0.82); white-space: nowrap; }
.game-actions { display: flex; gap: 6px; }
.gesture-guide {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  z-index: 4;
  display: flex;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}
.gesture-guide span { padding: 7px 10px; border-radius: 999px; color: rgba(247,248,255,0.88); background: rgba(5, 8, 24, 0.66); font-size: 0.72rem; }
.rotate-hint { display: none; }

.result-dialog {
  width: min(440px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  background: linear-gradient(180deg, #111b4b, #070b22);
  box-shadow: var(--shadow);
}
.result-dialog::backdrop { background: rgba(3, 5, 17, 0.82); backdrop-filter: blur(6px); }
.result-dialog form { position: relative; display: grid; gap: 12px; padding: 24px; text-align: center; }
.dialog-close { position: absolute; top: 9px; right: 10px; border: 0; color: var(--muted); background: transparent; font-size: 1.4rem; }
.result-icon { font-size: 2.4rem; }
.result-stars { color: var(--yellow); font-size: 1.8rem; letter-spacing: 0.1em; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.result-stats div { padding: 10px; border: 1px solid var(--border); border-radius: 11px; background: rgba(7, 12, 34, 0.7); }
.result-stats dt { color: var(--muted); font-size: 0.72rem; }
.result-stats dd { margin: 4px 0 0; font-weight: 900; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (max-width: 920px) {
  .topbar { grid-template-columns: 1fr auto; }
  .player-card { grid-column: 1 / -1; grid-row: 2; }
  .topbar-actions { grid-column: 2; grid-row: 1; }
  .dashboard { grid-template-columns: 1fr; }
  .community-panel { min-height: auto; }
}

@media (max-width: 680px) {
  .app-shell { padding: 9px; }
  .topbar { gap: 11px; padding: 12px; border-radius: 16px; }
  .brand { font-size: 1.4rem; }
  .topbar-actions { gap: 6px; }
  .currencies span { padding: 7px 8px; font-size: 0.82rem; }
  .levels-panel, .community-panel { padding: 14px; border-radius: 17px; }
  .level-grid { grid-template-columns: repeat(2, 1fr); }
  .level-card { min-height: 96px; }
  .selected-level-stats { grid-template-columns: 1fr; }
  .feature-strip { grid-template-columns: repeat(2, 1fr); }
  .nickname-row { flex-wrap: wrap; }
  .nickname-row .button { width: 100%; }
  .result-stats { grid-template-columns: 1fr; }
}

@media (orientation: portrait) and (max-width: 820px) {
  .game-stage.is-active .rotate-hint {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    place-content: center;
    gap: 8px;
    padding: 30px;
    text-align: center;
    background: rgba(5, 8, 24, 0.96);
  }
  .rotate-hint span { font-size: 3rem; color: var(--cyan); }
  .rotate-hint small { color: var(--muted); }
}

@media (max-height: 500px) {
  .game-toolbar { top: 5px; padding: 5px 7px; }
  .game-toolbar .eyebrow { display: none; }
  .icon-button { width: 36px; height: 36px; }
  .hud-inline span { padding: 5px 7px; font-size: 0.82rem; }
  .gesture-guide { bottom: 5px; }
  .gesture-guide span { padding: 5px 8px; font-size: 0.65rem; }
}

/* Neo Runner v1.3: progreso, modo automático y fondo inmersivo */
.game-stage {
  isolation: isolate;
  background:
    radial-gradient(circle at 76% 18%, rgba(190, 183, 255, 0.28) 0 7%, transparent 7.4%),
    linear-gradient(180deg, #11194d 0%, #090d2c 47%, #050818 100%);
}
.game-stage::before,
.game-stage::after {
  position: absolute;
  inset: 0;
  z-index: -2;
  content: "";
  pointer-events: none;
}
.game-stage::before {
  opacity: 0.42;
  background-image:
    linear-gradient(rgba(85, 118, 255, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(85, 118, 255, 0.15) 1px, transparent 1px);
  background-size: 32px 32px;
  transform: perspective(420px) rotateX(58deg) scale(1.35) translateY(22%);
  transform-origin: center bottom;
}
.game-stage::after {
  inset: auto 0 0;
  height: 44%;
  z-index: -1;
  opacity: 0.88;
  background:
    linear-gradient(90deg,
      transparent 0 2%, #17245d 2% 8%, transparent 8% 10%,
      #1d2e71 10% 16%, transparent 16% 18%, #131f52 18% 25%,
      transparent 25% 29%, #22357d 29% 36%, transparent 36% 39%,
      #17245d 39% 48%, transparent 48% 52%, #243a88 52% 60%,
      transparent 60% 64%, #17245d 64% 73%, transparent 73% 76%,
      #203477 76% 85%, transparent 85% 89%, #17245d 89% 97%, transparent 97%);
  clip-path: polygon(0 58%, 7% 58%, 7% 28%, 13% 28%, 13% 48%, 20% 48%, 20% 12%, 29% 12%, 29% 61%, 37% 61%, 37% 34%, 45% 34%, 45% 50%, 53% 50%, 53% 18%, 62% 18%, 62% 62%, 70% 62%, 70% 38%, 78% 38%, 78% 8%, 88% 8%, 88% 55%, 100% 55%, 100% 100%, 0 100%);
  box-shadow: 0 -30px 90px rgba(51, 231, 255, 0.08) inset;
}
.game-container { z-index: 1; }
.game-container canvas {
  position: relative;
  z-index: 1;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.38);
}

.game-toolbar {
  grid-template-columns: minmax(145px, 1fr) auto auto;
  grid-template-areas:
    "title hud actions"
    "progress progress progress";
}
.game-level-title { grid-area: title; }
.hud-inline { grid-area: hud; }
.game-actions { grid-area: actions; }
.game-progress {
  grid-area: progress;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 9px;
  align-items: center;
  min-width: 0;
}
.game-progress-track {
  position: relative;
  display: block;
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(247, 248, 255, 0.22);
  border-radius: 999px;
  background: rgba(5, 8, 24, 0.76);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.45);
}
.game-progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--pink));
  box-shadow: 0 0 16px rgba(51, 231, 255, 0.75);
  transition: width 90ms linear;
}
.game-progress > strong {
  color: var(--cyan);
  font-size: 0.76rem;
  text-align: right;
}
.auto-mode-badge {
  margin-top: 2px;
  color: var(--yellow);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}
.auto-button {
  width: auto;
  min-width: 58px;
  padding: 0 8px;
  color: var(--yellow);
  font-size: 0.64rem;
  letter-spacing: 0.04em;
}
.auto-button.is-active {
  border-color: var(--yellow);
  background: rgba(255, 213, 74, 0.16);
  box-shadow: 0 0 18px rgba(255, 213, 74, 0.24);
}
.button-auto {
  border-color: rgba(255, 213, 74, 0.55);
  color: #11152f;
  background: linear-gradient(135deg, #fff4b5, var(--yellow));
}
.result-stats { grid-template-columns: repeat(4, 1fr); }
.dialog-actions { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 680px) {
  .result-stats { grid-template-columns: repeat(2, 1fr); }
  .dialog-actions { grid-template-columns: 1fr; }
}

@media (max-height: 500px) {
  .game-toolbar {
    grid-template-columns: minmax(120px, 1fr) auto auto;
    gap: 5px 7px;
  }
  .game-progress-track { height: 6px; }
  .auto-mode-badge { font-size: 0.5rem; }
  .auto-button { min-width: 50px; padding: 0 5px; font-size: 0.56rem; }
}
