:root {
  --bg-a: #070916;
  --bg-b: #101838;
  --panel: rgba(255, 255, 255, 0.10);
  --panel-strong: rgba(255, 255, 255, 0.17);
  --text: #f8fbff;
  --muted: rgba(248, 251, 255, 0.66);
  --line: rgba(255, 255, 255, 0.20);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(circle at 18% 16%, rgba(103, 229, 255, 0.20), transparent 34%),
    radial-gradient(circle at 84% 12%, rgba(245, 111, 255, 0.20), transparent 28%),
    radial-gradient(circle at 50% 96%, rgba(255, 220, 92, 0.16), transparent 30%),
    linear-gradient(135deg, var(--bg-a), var(--bg-b));
  color: var(--text);
  touch-action: none;
  overscroll-behavior: none;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  isolation: isolate;
}

.game-shell::before,
.game-shell::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  filter: blur(2px);
  opacity: 0.65;
  pointer-events: none;
  z-index: 0;
}
.game-shell::before {
  width: 34vw;
  height: 34vw;
  min-width: 220px;
  min-height: 220px;
  left: -9vw;
  top: 15vh;
  background: radial-gradient(circle, rgba(56, 215, 255, 0.23), transparent 67%);
  animation: floatGlow 11s ease-in-out infinite;
}
.game-shell::after {
  width: 42vw;
  height: 42vw;
  min-width: 260px;
  min-height: 260px;
  right: -14vw;
  bottom: -16vh;
  background: radial-gradient(circle, rgba(255, 82, 178, 0.18), transparent 70%);
  animation: floatGlow 14s ease-in-out infinite reverse;
}
@keyframes floatGlow {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(16px, -18px, 0) scale(1.07); }
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.top-hud,
.bottom-bar,
.toast,
.modal {
  position: absolute;
  z-index: 5;
}

.top-hud {
  top: calc(12px + var(--safe-top));
  left: clamp(10px, 3vw, 26px);
  right: clamp(10px, 3vw, 26px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  pointer-events: none;
}

.brand,
.stats,
.control-btn,
.primary-btn,
.modal-card {
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 10px 13px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.10);
}
.brand strong {
  display: block;
  font-size: clamp(13px, 2.2vw, 18px);
  line-height: 1.05;
  white-space: nowrap;
}
.brand small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.brand-orb,
.big-orb {
  display: inline-block;
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 25%, #ffffff 0 6%, transparent 7%),
    conic-gradient(from 40deg, #57f4ff, #8e79ff, #ff5fd7, #ffd460, #4dffbe, #57f4ff);
  box-shadow: 0 0 28px rgba(91, 229, 255, 0.38), inset 0 0 18px rgba(255, 255, 255, 0.34);
}
.brand-orb { width: 38px; height: 38px; flex: 0 0 auto; }
.big-orb { width: 82px; height: 82px; margin: -52px auto 12px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(66px, 1fr));
  gap: 1px;
  overflow: hidden;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.09);
}
.stat {
  padding: 9px 13px;
  text-align: center;
  background: rgba(255, 255, 255, 0.07);
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.stat b {
  display: block;
  margin-top: 2px;
  font-size: clamp(16px, 2.5vw, 21px);
  line-height: 1;
}

.bottom-bar {
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(96vw, 680px);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  padding: 0 8px;
}

button {
  font-family: inherit;
  color: var(--text);
  border: 0;
  cursor: pointer;
  user-select: none;
}
.control-btn,
.primary-btn {
  min-height: 48px;
  border-radius: 17px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.01em;
  transition: transform 130ms ease, filter 130ms ease, background 130ms ease, opacity 130ms ease;
}
.control-btn {
  background: rgba(255, 255, 255, 0.12);
}
.primary-btn {
  padding: 0 22px;
  background: linear-gradient(135deg, #38e8ff, #8c6dff 42%, #ff61c8 100%);
  box-shadow: 0 18px 48px rgba(111, 115, 255, 0.38);
}
.control-btn:active,
.primary-btn:active { transform: translateY(2px) scale(0.98); }
.control-btn:disabled { opacity: 0.45; cursor: default; }
.icon-btn { width: 52px; padding: 0; }

.toast {
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  max-width: min(92vw, 520px);
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(12, 16, 36, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255,255,255,0.92);
  text-align: center;
  font-weight: 700;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(5, 7, 18, 0.36);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}
.modal.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.modal-card {
  width: min(94vw, 520px);
  padding: 36px clamp(20px, 5vw, 38px) 28px;
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.19), rgba(255, 255, 255, 0.10)),
    rgba(13, 18, 43, 0.84);
  text-align: center;
}
.modal h1,
.modal h2 {
  margin: 0 0 10px;
  font-size: clamp(30px, 7vw, 50px);
  line-height: 0.98;
  letter-spacing: -0.05em;
}
.modal h2 { font-size: clamp(28px, 6vw, 44px); }
.modal p {
  margin: 0 auto 20px;
  max-width: 420px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 16px;
  line-height: 1.45;
}
.mini-rules {
  display: grid;
  gap: 9px;
  margin: 0 auto 22px;
  max-width: 370px;
}
.mini-rules span {
  padding: 11px 13px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.11);
  color: rgba(255,255,255,0.86);
  font-weight: 750;
}
.stars {
  margin-bottom: 8px;
  font-size: clamp(26px, 7vw, 42px);
  letter-spacing: 0.12em;
  color: #ffd761;
  text-shadow: 0 0 24px rgba(255, 216, 97, 0.38);
}
.win-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 8px;
}

@media (hover: hover) {
  .control-btn:hover,
  .primary-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
}

@media (max-width: 640px) {
  .game-shell { min-height: 500px; }
  .top-hud {
    align-items: stretch;
    gap: 8px;
  }
  .brand {
    padding: 8px 10px;
    border-radius: 18px;
  }
  .brand-orb { width: 32px; height: 32px; }
  .brand small { display: none; }
  .stats { grid-template-columns: repeat(3, 1fr); border-radius: 18px; }
  .stat { padding: 8px 7px; min-width: 54px; }
  .stat span { font-size: 9px; }
  .bottom-bar {
    width: 100vw;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding-inline: 8px;
  }
  .control-btn,
  .primary-btn {
    min-height: 46px;
    border-radius: 15px;
    font-size: 12px;
  }
  .icon-btn { width: auto; }
  .modal { padding: 18px; }
  .modal-card { border-radius: 26px; }
}

@media (max-width: 390px) {
  .brand strong { font-size: 12px; }
  .brand-orb { display: none; }
  .stat { min-width: 48px; }
  .control-btn,
  .primary-btn { font-size: 11px; }
}

/* Ranking / puntajes */
.score-result {
  display: grid;
  gap: 4px;
  margin: 2px auto 16px;
  width: min(100%, 260px);
  padding: 13px 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(56, 232, 255, 0.18), rgba(255, 97, 200, 0.16));
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.score-result span,
.score-form label,
.leaderboard-title {
  color: rgba(255, 255, 255, 0.68);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.score-result b {
  font-size: clamp(30px, 8vw, 46px);
  line-height: 1;
}
.score-form {
  display: grid;
  gap: 8px;
  margin: 0 auto 14px;
  max-width: 380px;
  text-align: left;
}
.score-save-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.score-form input {
  min-width: 0;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.10);
  font: inherit;
  font-weight: 800;
}
.score-form input:focus {
  border-color: rgba(99, 234, 255, 0.78);
  box-shadow: 0 0 0 4px rgba(99, 234, 255, 0.13);
}
.small-primary {
  min-height: 46px;
  padding-inline: 16px;
}
.save-status {
  min-height: 20px;
  margin: 0 !important;
  color: rgba(255, 255, 255, 0.70) !important;
  font-size: 13px !important;
  text-align: center;
}
.leaderboard-box {
  margin: 0 auto 14px;
  max-width: 420px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.leaderboard-title {
  margin-bottom: 8px;
  text-align: center;
}
.leaderboard-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.leaderboard-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  font-weight: 800;
}
.leaderboard-list .rank {
  color: #ffd761;
  text-align: center;
}
.leaderboard-list .name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}
.leaderboard-list .meta {
  color: rgba(255, 255, 255, 0.62);
  font-size: 11px;
  font-weight: 750;
  text-align: right;
}
.big-list { margin-top: 4px; }
.records-card,
.win-card {
  max-height: calc(100dvh - 36px);
  overflow: auto;
}

@media (min-width: 641px) {
  .stats { grid-template-columns: repeat(4, minmax(66px, 1fr)); }
  .bottom-bar { grid-template-columns: 1fr 1fr 1fr 1fr auto; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .bottom-bar { grid-template-columns: repeat(5, 1fr); }
  .score-save-row { grid-template-columns: 1fr; }
  .small-primary { width: 100%; }
  .leaderboard-list li {
    grid-template-columns: 24px 1fr;
  }
  .leaderboard-list .meta {
    grid-column: 2;
    text-align: left;
  }
}

@media (max-width: 430px) {
  .bottom-bar { gap: 4px; padding-inline: 5px; }
  .control-btn,
  .primary-btn { font-size: 10px; }
  .stat { padding-inline: 4px; }
  .stat b { font-size: 14px; }
}
