:root {
  color-scheme: dark;
  --bg: #070914;
  --panel: rgba(18, 22, 43, .88);
  --panel-border: rgba(255, 255, 255, .09);
  --text: #f7f8ff;
  --muted: #9ca6c9;
  --accent: #ffd447;
  --accent-2: #65e6ff;
  --danger: #ff667d;
  --shadow: 0 24px 70px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(59, 78, 180, .28), transparent 28rem),
    radial-gradient(circle at 85% 85%, rgba(0, 210, 255, .14), transparent 30rem),
    var(--bg);
  overscroll-behavior: none;
}

button { font: inherit; }

.app {
  width: min(1180px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 36px) calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: .72rem;
  letter-spacing: .22em;
  color: var(--accent-2);
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.2rem);
  line-height: 1;
  letter-spacing: -.04em;
}

h1 span {
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .02em;
  white-space: nowrap;
}

.icon-button,
.secondary-button,
.control-button,
.primary-button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(165px, 220px) minmax(280px, 420px) minmax(165px, 220px);
  justify-content: center;
  align-items: start;
  gap: clamp(12px, 2.5vw, 28px);
  flex: 1;
}

.panel {
  display: grid;
  gap: 12px;
}

.stat-card,
.stat-grid > div,
.record-card,
.next-card,
.desktop-help {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.stat-card,
.record-card,
.next-card {
  padding: 18px;
}

.stat-card span,
.record-card span,
.next-card > span,
.stat-grid span {
  display: block;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .14em;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(2rem, 4vw, 3rem);
  color: var(--accent);
}

.record-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-grid > div {
  padding: 15px;
}

.stat-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
}

.desktop-help {
  padding: 16px 18px;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.55;
}

.desktop-help h2 {
  margin: 0 0 8px;
  font-size: .85rem;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .1em;
}

.desktop-help p { margin: 2px 0; }

.board-wrap {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 1 / 2;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  background: #060814;
  box-shadow: 0 32px 90px rgba(0, 0, 0, .55), 0 0 50px rgba(58, 113, 255, .12);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(5, 7, 16, .76);
  backdrop-filter: blur(8px);
  transition: opacity .18s ease, visibility .18s ease;
}

.overlay:not(.is-visible) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  width: min(100%, 320px);
  text-align: center;
  padding: 24px;
  border-radius: 22px;
  background: rgba(20, 25, 50, .95);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: var(--shadow);
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: .7rem;
  letter-spacing: .18em;
  font-weight: 900;
}

.overlay-card h2 {
  margin: 0;
  font-size: 1.55rem;
}

.overlay-card p:not(.overlay-kicker) {
  margin: 10px 0 20px;
  color: var(--muted);
  line-height: 1.5;
  font-size: .92rem;
}

.primary-button {
  width: 100%;
  min-height: 50px;
  border-radius: 14px;
  font-weight: 900;
  letter-spacing: .06em;
  color: #171203;
  background: linear-gradient(180deg, #ffe475, var(--accent));
  box-shadow: 0 12px 30px rgba(255, 212, 71, .22);
}

.next-card { text-align: center; }

#nextCanvas {
  display: block;
  width: 100%;
  max-width: 140px;
  aspect-ratio: 1;
  margin: 6px auto 0;
}

.secondary-button {
  min-height: 50px;
  border-radius: 15px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-weight: 850;
  letter-spacing: .05em;
}

.secondary-button.danger { color: #ff9cab; }

.mobile-controls {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  width: min(100%, 520px);
  margin: 14px auto 0;
}

.control-button {
  min-height: 54px;
  border-radius: 15px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(40, 48, 86, .96), rgba(20, 25, 48, .96));
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 8px 22px rgba(0,0,0,.26);
  font-size: 1.15rem;
  font-weight: 900;
  touch-action: manipulation;
}

.control-button:active,
.icon-button:active,
.secondary-button:active,
.primary-button:active {
  transform: translateY(1px) scale(.985);
}

.control-wide { grid-column: span 2; font-size: .85rem; letter-spacing: .08em; }

footer {
  text-align: center;
  color: #727b9b;
  font-size: .72rem;
  padding-top: 16px;
}


/* Escritorio: el juego completo se adapta al alto visible del navegador. */
@media (min-width: 821px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 0;
    padding-top: clamp(10px, 2vh, 22px);
    padding-bottom: clamp(8px, 1.5vh, 18px);
    overflow: hidden;
  }

  .topbar {
    flex: 0 0 auto;
    margin-bottom: clamp(8px, 1.5vh, 18px);
  }

  .game-shell {
    min-height: 0;
    grid-template-columns: minmax(165px, 220px) auto minmax(165px, 220px);
    align-items: center;
  }

  .board-wrap {
    width: auto;
    height: min(840px, calc(100dvh - 132px));
    max-width: 420px;
    max-height: 100%;
    justify-self: center;
  }

  footer {
    flex: 0 0 auto;
    padding-top: clamp(5px, 1vh, 12px);
  }
}

/* Escritorios o laptops con poca altura útil. */
@media (min-width: 821px) and (max-height: 760px) {
  .app { padding-inline: clamp(12px, 2vw, 28px); }
  .eyebrow { margin-bottom: 2px; font-size: .62rem; }
  h1 { font-size: clamp(1.2rem, 2.4vw, 1.75rem); }
  .icon-button { width: 40px; height: 40px; border-radius: 12px; }
  .game-shell { gap: clamp(10px, 2vw, 20px); }
  .panel { gap: 8px; }
  .stat-card, .record-card, .next-card { padding: 12px; border-radius: 14px; }
  .stat-grid { gap: 8px; }
  .stat-grid > div { padding: 10px; border-radius: 14px; }
  .stat-card strong { margin-top: 3px; font-size: 2rem; }
  .record-card strong, .stat-grid strong { margin-top: 2px; font-size: 1.1rem; }
  .desktop-help { padding: 11px 13px; border-radius: 14px; font-size: .72rem; line-height: 1.35; }
  .desktop-help h2 { margin-bottom: 4px; font-size: .72rem; }
  #nextCanvas { max-width: 104px; margin-top: 2px; }
  .secondary-button { min-height: 42px; border-radius: 12px; font-size: .75rem; }
  footer { font-size: .64rem; }
}

@media (min-width: 821px) and (max-height: 620px) {
  .desktop-help { display: none; }
  footer { display: none; }
  .board-wrap { height: calc(100dvh - 92px); }
}

@media (max-width: 820px) {
  .app { padding-top: 14px; }
  .topbar { margin-bottom: 12px; }
  .game-shell {
    grid-template-columns: 1fr minmax(250px, 390px) 1fr;
    gap: 9px;
  }
  .desktop-help { display: none; }
  .stat-card, .record-card, .next-card { padding: 12px 8px; border-radius: 14px; }
  .stat-grid { grid-template-columns: 1fr; gap: 8px; }
  .stat-grid > div { padding: 10px 7px; border-radius: 14px; }
  .stat-card span, .record-card span, .next-card > span, .stat-grid span { font-size: .54rem; letter-spacing: .07em; }
  .stat-card strong { font-size: clamp(1.2rem, 4vw, 2rem); }
  .record-card strong, .stat-grid strong { font-size: 1rem; }
  .secondary-button { min-height: 43px; font-size: .68rem; padding: 7px; }
  .mobile-controls { display: grid; }
}

@media (max-width: 560px) {
  .app { min-height: 100svh; }
  .eyebrow { font-size: .58rem; }
  h1 { font-size: 1.18rem; }
  .icon-button { width: 40px; height: 40px; }
  .game-shell {
    grid-template-columns: 48px minmax(168px, 1fr) 48px;
    align-items: start;
  }
  .panel { gap: 7px; }
  .next-card { padding: 8px 4px; }
  .record-card { word-break: break-word; }
  .stat-card, .record-card, .next-card { padding-left: 4px; padding-right: 4px; }
  .secondary-button { font-size: .58rem; padding-inline: 3px; }
  .board-wrap { border-radius: 16px; }
  .overlay { padding: 12px; }
  .overlay-card { padding: 18px 15px; border-radius: 17px; }
  .overlay-card h2 { font-size: 1.2rem; }
  .overlay-card p:not(.overlay-kicker) { font-size: .8rem; }
  .primary-button { min-height: 45px; font-size: .8rem; }
  .mobile-controls { margin-top: 10px; }
  .control-button { min-height: 48px; }
  footer { display: none; }
}

@media (max-height: 720px) and (max-width: 820px) {
  .topbar { margin-bottom: 8px; }
  .board-wrap { max-height: 67svh; width: auto; justify-self: center; }
  .game-shell { align-items: start; }
  .mobile-controls { margin-top: 8px; }
  .control-button { min-height: 42px; }
}
