@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  --bg-1: #f3f4f7;
  --bg-2: #ffffff;
  --card: #ffffff;
  --line: #da2b2b;
  --text: #182132;
  --muted: #5f6b7d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Press Start 2P", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(60rem 35rem at 10% -10%, rgba(218, 43, 43, 0.2) 0%, transparent 55%),
    radial-gradient(55rem 30rem at 100% 0%, rgba(220, 57, 57, 0.16) 0%, transparent 58%),
    radial-gradient(65rem 40rem at 50% 120%, rgba(185, 21, 21, 0.1) 0%, transparent 62%),
    linear-gradient(180deg, var(--bg-2), var(--bg-1));
  min-height: 100vh;
}

/* Degradacion visual automatica para dispositivos lentos o bajo carga sostenida. */
body.cg-low-perf .game-card::before,
body.cg-low-perf .game-card::after {
  display: none;
}

body.cg-low-perf #game-root canvas {
  transform: none;
  filter: none;
}

body.cg-low-perf .game-card,
body.cg-low-perf .side-ranking,
body.cg-low-perf .touch-lane,
body.cg-low-perf .mobile-restart {
  box-shadow: none !important;
}

.layout {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 14px 24px;
}

.topbar h1 {
  margin: 0;
  letter-spacing: 1px;
  color: #d93025 !important;
}

.topbar p {
  margin: 6px 0 0;
  color: #111111 !important;
}

.game-card {
  position: relative;
  overflow: hidden;
  margin-top: 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in oklab, var(--card) 96%, #f0f2f7 4%);
  box-shadow: 0 18px 30px rgba(218, 43, 43, 0.13);
}

/* CRT muy sutil sobre toda la pantalla del juego (canvas + overlays). */
.game-card::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 9px;
  pointer-events: none;
  z-index: 40;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(180, 205, 255, 0.04) 0px,
      rgba(247, 233, 233, 0.05) 1px,
      rgba(10, 18, 34, 0) 2px,
      rgba(10, 18, 34, 0) 4px
    );
  mix-blend-mode: screen;
}

.game-card::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 9px;
  pointer-events: none;
  z-index: 41;
  background:
    radial-gradient(120% 90% at 50% -14%, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0) 52%),
    radial-gradient(120% 92% at 50% 114%, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 56%),
    radial-gradient(130% 110% at 50% 50%, rgba(0, 0, 0, 0) 62%, rgba(0, 0, 0, 0.2) 100%);
}

#game-root {
  width: 100%;
  line-height: 0;
  min-height: 0;
  position: relative;
}

#game-root::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid #da2b2b;
  border-radius: 8px;
  pointer-events: none;
  z-index: 6;
}

#game-root canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  image-rendering: pixelated;
  transform: perspective(1200px) scale(0.997, 0.994);
  transform-origin: center center;
  filter: saturate(1.03) contrast(1.01);
}

.touch-lane {
  display: none;
  margin-top: 6px;
  border: 2px dashed #da2b2b;
  border-radius: 10px;
  min-height: 74px;
  background: rgba(255, 255, 255, 0.94);
  color: #111111 !important;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  user-select: none;
  touch-action: none;
}

.touch-lane span {
  display: block;
  width: 100%;
  color: #111111 !important;
  text-align: center;
}

.touch-lane.is-active {
  border-color: #b41e1e;
  color: #ffffff;
  background: rgba(185, 31, 31, 0.9);
}

.side-ranking {
  display: none;
  border: 2px solid #da2b2b;
  border-radius: 10px;
  background: rgba(12, 18, 30, 0.92);
  padding: 8px;
  color: #f5f7ff;
}

.side-ranking h3 {
  margin: 0 0 8px;
  font-size: 0.72rem;
  color: #f5f7ff;
  text-align: center;
}

.side-capture-feed {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  height: 100%;
  align-content: stretch;
}

.side-capture-empty {
  margin: 0;
  font-size: 0.56rem;
  line-height: 1.35;
  color: #c9d8f0;
  text-align: center;
  display: none;
}

.side-capture-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  height: 100%;
  overflow: auto;
  align-content: start;
}

.side-capture-list li {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 7px;
  align-items: center;
  border: 2px solid #d93025;
  border-radius: 8px;
  background: #fff;
  padding: 5px;
}

.side-capture-list li img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border: 1px solid #d93025;
  image-rendering: pixelated;
}

.side-capture-list li .body {
  display: grid;
  gap: 4px;
}

.side-capture-list .title {
  font-size: 0.52rem;
  line-height: 1.28;
  color: #10233d;
  word-break: break-word;
}

.side-capture-list .price {
  font-size: 0.48rem;
  color: #f2b24b;
}

.capture-results {
  /* Capa overlay que cubre TODO el monitor jugable dentro de .game-card.
     Cualquier centrado "absoluto" del modal debe referenciar este bloque. */
  position: absolute;
  left: 10px;
  right: 10px;
  top: 10px;
  bottom: 10px;
  z-index: 20;
  overflow-x: hidden;
  overflow-y: auto;
  border: 2px solid #da2b2b;
  border-radius: 10px;
  background: rgba(12, 18, 30, 0.92);
  padding: 10px;
  text-align: center;
}

.capture-results h2 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: #f5f7ff;
}

.capture-results p {
  margin: 0;
  color: #d8deec;
  font-size: 0.65rem;
}

.capture-results.orientation-block {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border: 3px solid #bf1f1f;
  border-radius: 10px;
  background: linear-gradient(180deg, #14213a 0%, #0c1630 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 226, 226, 0.28);
  text-align: center;
}

.capture-results.orientation-block h2 {
  font-size: clamp(1rem, 3.8vw, 1.4rem);
  color: #ecf2ff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  margin: 0;
}

.capture-results.orientation-block #capture-empty {
  display: block !important;
  max-width: 92%;
  font-size: clamp(0.86rem, 3.2vw, 1.15rem);
  line-height: 1.45;
  color: #ecf2ff;
  margin: 0;
}

.capture-results.orientation-block .capture-list,
.capture-results.orientation-block .arcade-ranking,
.capture-results.orientation-block .overlay-continue {
  display: none !important;
}

.capture-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.capture-item {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  align-items: center;
  color: #eaf3ff;
  text-decoration: none;
  border: 2px solid #d93025;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
}

.capture-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  image-rendering: pixelated;
  border: 1px solid #d93025;
}

.capture-item .title {
  font-size: 0.72rem;
  line-height: 1.45;
  color: #10233d;
  word-break: break-word;
}

.capture-item .price {
  display: block;
  margin-top: 5px;
  color: #d93025;
}

.arcade-ranking {
  border-top: 2px solid #da2b2b;
  padding-top: 10px;
  padding-bottom: 8px;
  position: relative;
}

.arcade-ranking h3 {
  display: none;
}

.ranking-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  justify-content: center;
  max-width: 520px;
  margin-inline: auto;
  list-style: none;
  text-align: left;
  margin-bottom: 12px;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 78px 1fr 86px;
  gap: 12px;
  align-items: center;
  font-size: 1.02rem;
  color: #f2b24b;
  line-height: 1.2;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 #3b2104;
  background: rgba(10, 16, 34, 0.86);
  border: 1px solid rgba(130, 160, 220, 0.22);
  border-radius: 6px;
  padding: 6px 10px;
}

.ranking-list li.ranking-empty {
  display: block;
  grid-template-columns: none;
  width: fit-content;
  min-width: 0;
  margin-inline: auto;
  padding: 8px 12px 7px;
  font-size: 0.86rem;
  line-height: 1.05;
  white-space: nowrap;
  letter-spacing: 0.4px;
  text-align: center;
  color: #f2b24b;
  border-color: rgba(242, 178, 75, 0.65);
  background: rgba(14, 20, 36, 0.9);
  text-shadow: 1px 1px 0 #3b2104;
}

.ranking-list li .rank {
  text-align: left;
}

.ranking-list li .score {
  text-align: center;
}

.ranking-list li .initials {
  text-align: right;
}

.ranking-list li:first-child {
  position: relative;
  animation: top-rank-glow 2.2s ease-in-out infinite;
}

@keyframes top-rank-glow {
  0%, 100% {
    box-shadow: 0 0 0 rgba(246, 190, 82, 0);
    border-color: rgba(130, 160, 220, 0.22);
  }
  50% {
    box-shadow: 0 0 12px rgba(246, 190, 82, 0.55);
    border-color: rgba(246, 190, 82, 0.8);
  }
}

.ranking-note {
  display: block;
  margin-top: 12px;
  margin-bottom: 8px;
  line-height: 1.35;
  font-size: 0.86rem;
  color: #f2f2f2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 5;
}

.ranking-note.top-rank-note {
  color: #ffd86a;
  text-shadow: 0 0 10px rgba(255, 205, 80, 0.45);
  animation: top-rank-note-pulse 1.9s ease-in-out infinite;
}

@keyframes top-rank-note-pulse {
  0%, 100% {
    opacity: 0.92;
  }
  50% {
    opacity: 1;
  }
}

.ranking-entry {
  margin-top: 14px;
  position: relative;
  z-index: 5;
}

.capture-results.entry-modal-active {
  overflow: hidden;
  display: block;
  z-index: 46;
}

.capture-results.entry-modal-active .ranking-note {
  display: none !important;
}

.capture-results.entry-modal-active .ranking-entry {
  /* Modal de iniciales anclada al centro geometrico de .game-card (via CSS vars desde JS). */
  position: fixed;
  left: var(--entry-modal-vx, 50vw);
  top: var(--entry-modal-vy, 50vh);
  transform: translate(-50%, -50%);
  width: min(440px, var(--entry-modal-max-width, calc(100vw - 24px)));
  margin: 0;
  padding: 18px 12px 12px;
  border: 2px solid #d93025;
  border-radius: 10px;
  background: rgba(8, 16, 34, 0.96);
  box-shadow: 0 20px 38px rgba(0, 0, 0, 0.45);
  overflow: visible;
  z-index: 47;
}

.capture-results.entry-modal-side-centered {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  overflow: visible;
}

.capture-results.entry-modal-side-centered > h2,
.capture-results.entry-modal-side-centered > #capture-empty,
.capture-results.entry-modal-side-centered > #capture-list,
.capture-results.entry-modal-side-centered > .overlay-continue {
  display: none !important;
}

.capture-results.entry-modal-side-centered .arcade-ranking {
  border-top: 0;
  padding: 0;
}

.capture-results.entry-modal-side-centered .arcade-ranking > h3,
.capture-results.entry-modal-side-centered .arcade-ranking > #ranking-list,
.capture-results.entry-modal-side-centered .arcade-ranking > #ranking-note {
  display: none !important;
}

.capture-results.entry-modal-active .ranking-entry-help {
  font-size: 0.58rem;
  text-align: center;
  margin-top: 18px;
  line-height: 1.2;
  white-space: pre;
}

.ranking-entry-title {
  display: block;
  margin: 0;
  line-height: 1.1;
  color: #f2b24b;
  text-align: center;
  letter-spacing: 1.2px;
  text-shadow: 2px 2px 0 #3b2104;
}

.ranking-entry-top,
.ranking-entry-subtop,
.ranking-entry-score {
  display: block;
  color: #f2b24b;
  text-shadow: 2px 2px 0 #3b2104;
}

.ranking-entry-top {
  font-size: clamp(1.34rem, 3.2vw, 1.55rem);
}

.ranking-entry-subtop {
  margin-top: 2px;
  font-size: clamp(1.16rem, 2.8vw, 1.35rem);
}

.ranking-entry-score {
  margin-top: 8px;
  font-size: clamp(0.82rem, 2.2vw, 0.96rem);
}

.ranking-entry-help {
  margin: 18px 0 0;
  font-size: 0.56rem;
  color: #e7edf9;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;
}

.ranking-entry-slots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.ranking-entry-slots span {
  min-width: 48px;
  padding: 10px 0;
  border: 2px solid #da2b2b;
  border-radius: 8px;
  background: #fff;
  color: #10233d;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.ranking-entry-slots span.active {
  border-color: #d93025;
  color: #d93025;
  transform: translateY(-1px);
}

.ranking-entry.top-rank-entry {
  border-color: #f0bd56;
  box-shadow:
    0 0 0 2px rgba(240, 189, 86, 0.3),
    0 20px 38px rgba(0, 0, 0, 0.45),
    0 0 18px rgba(240, 189, 86, 0.28);
}

.ranking-entry.top-rank-entry .ranking-entry-title {
  color: #f2b24b;
  text-shadow: 2px 2px 0 #3b2104, 0 0 6px rgba(246, 190, 82, 0.45);
}

.ranking-entry-title.is-top-one-title {
  color: #f2b24b;
  text-shadow: 2px 2px 0 #3b2104, 0 0 18px rgba(246, 190, 82, 0.78);
  filter: drop-shadow(0 0 9px rgba(246, 190, 82, 0.55));
  animation: top-rank-title-glow 1.5s ease-in-out infinite;
}

.capture-results.entry-modal-active .ranking-entry-top {
  font-size: clamp(1.7rem, min(4.8vw, 5.4vh), 2.35rem);
  line-height: 1.12;
}

.capture-results.entry-modal-active .ranking-entry-subtop {
  margin-top: 2px;
  font-size: clamp(1rem, min(2.8vw, 3.2vh), 1.32rem);
}

.capture-results.entry-modal-active .ranking-entry-score {
  margin-top: 6px;
  font-size: clamp(0.78rem, min(2vw, 2.3vh), 0.98rem);
}

.ranking-entry.top-rank-entry .ranking-entry-help {
  margin-top: 18px;
}

.ranking-entry.top-rank-entry .ranking-entry-slots span.active {
  border-color: #f0bd56;
  color: #bd7a0a;
  box-shadow: 0 0 10px rgba(240, 189, 86, 0.4);
}

@keyframes top-rank-title-glow {
  0%, 100% {
    text-shadow: 2px 2px 0 #3b2104, 0 0 8px rgba(246, 190, 82, 0.28);
    filter: drop-shadow(0 0 4px rgba(246, 190, 82, 0.2));
  }
  50% {
    text-shadow: 2px 2px 0 #3b2104, 0 0 22px rgba(246, 190, 82, 0.95);
    filter: drop-shadow(0 0 12px rgba(246, 190, 82, 0.7));
  }
}

.overlay-continue {
  margin-top: 12px;
  border: 2px solid #d93025;
  background: #fff;
  color: #d93025;
  font-family: "Press Start 2P", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 0.62rem;
  padding: 10px 14px;
  border-radius: 8px;
}

.foot {
  margin-top: 10px;
  color: #111111;
  text-align: center;
  font-size: 0.95rem;
}

.mobile-restart {
  display: none;
  border: 2px solid #d93025;
  background: #ffffff;
  color: #d93025;
  font-family: "Press Start 2P", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 0.62rem;
  padding: 10px 12px;
  border-radius: 8px;
}

.controls-side-toggle {
  display: none;
  border: 2px solid #d93025;
  background: #ffffff;
  color: #d93025;
  font-family: "Press Start 2P", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 0.56rem;
  padding: 9px 10px;
  border-radius: 8px;
}

.offers-refresh-btn {
  display: inline-block;
  border: 2px solid #d93025;
  background: #ffffff;
  color: #d93025;
  font-family: "Press Start 2P", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: 0.56rem;
  padding: 9px 10px;
  border-radius: 8px;
}

.offers-refresh-btn:disabled {
  opacity: 0.55;
}

.offers-refresh-btn[hidden] {
  display: none !important;
}

/* Marco arcade exterior solo para PC (sin tocar overlays internos del juego). */
@media (pointer: fine) and (min-width: 900px) {
  .layout {
    max-width: 1160px;
    padding: 26px 18px 28px;
  }

  .topbar {
    max-width: 980px;
    margin: 0 auto 10px;
    padding: 16px 22px 14px;
    text-align: center;
    border: 3px solid #c91717;
    border-radius: 14px 14px 8px 8px;
    background:
      radial-gradient(85% 130% at 50% 8%, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.18) 60%, rgba(255, 255, 255, 0.04) 100%),
      linear-gradient(180deg, #fff3f3 0%, #f2bcbc 48%, #cb3030 100%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.75),
      0 16px 36px rgba(125, 14, 14, 0.26);
  }

  .topbar h1 {
    margin: 0;
    font-size: clamp(2rem, 3.8vw, 2.7rem);
    line-height: 1.04;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.38);
  }

  .topbar p {
    margin-top: 10px;
    font-size: clamp(0.82rem, 1.2vw, 1rem);
    color: #111111 !important;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  }

  .game-card {
    max-width: 980px;
    margin: 0 auto;
    padding: 14px 14px 12px;
    border: 3px solid #bf1f1f;
    border-radius: 12px;
    background:
      linear-gradient(180deg, #1f2840 0%, #101a2f 100%);
    box-shadow:
      inset 0 0 0 2px rgba(255, 226, 226, 0.55),
      0 26px 44px rgba(12, 16, 30, 0.44),
      0 0 0 1px rgba(145, 23, 23, 0.35);
  }

  .foot {
    max-width: 980px;
    margin: 8px auto 0;
    padding: 12px 16px 14px;
    border: 3px solid #bf1f1f;
    border-radius: 8px 8px 14px 14px;
    background:
      linear-gradient(180deg, #14213a 0%, #0c1630 100%);
    box-shadow:
      inset 0 0 0 2px rgba(255, 226, 226, 0.3),
      0 14px 30px rgba(9, 16, 34, 0.4);
    color: #ecf2ff;
  }

  .controls-hint {
    margin: 0;
    color: #ecf2ff;
    font-size: clamp(0.72rem, 1.1vw, 0.9rem);
    line-height: 1.35;
    text-align: center;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  }
}

@media (pointer: coarse) {
  html, body {
    height: 100dvh;
    overflow: hidden;
  }

  .layout {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .topbar h1 {
    color: #d93025 !important;
  }

  .topbar p {
    color: #111111 !important;
  }

  .game-card {
    border: 3px solid #bf1f1f;
    border-radius: 12px;
    background: linear-gradient(180deg, #1f2840 0%, #101a2f 100%);
    box-shadow:
      inset 0 0 0 2px rgba(255, 226, 226, 0.45),
      0 10px 22px rgba(9, 16, 34, 0.32);
  }

  .touch-lane {
    display: flex;
    color: #ecf2ff !important;
    width: 100%;
    flex: 1 1 auto;
    border: 3px solid #bf1f1f;
    border-radius: 10px;
    background: linear-gradient(180deg, #14213a 0%, #0c1630 100%);
    box-shadow: inset 0 0 0 2px rgba(255, 226, 226, 0.28);
  }

  .touch-lane span {
    color: #ecf2ff !important;
  }

  .controls-hint {
    display: none;
  }

  .mobile-restart {
    display: inline-block;
    width: 100%;
    margin-top: 0;
    border: 3px solid #bf1f1f;
    border-radius: 10px;
    background: linear-gradient(180deg, #14213a 0%, #0c1630 100%);
    color: #ecf2ff;
    box-shadow:
      inset 0 0 0 2px rgba(255, 226, 226, 0.28),
      0 8px 16px rgba(9, 16, 34, 0.24);
  }

  .offers-refresh-btn {
    display: inline-block;
    width: 100%;
    margin-top: 0;
    border: 3px solid #bf1f1f;
    border-radius: 10px;
    background: linear-gradient(180deg, #14213a 0%, #0c1630 100%);
    color: #ecf2ff;
    box-shadow:
      inset 0 0 0 2px rgba(255, 226, 226, 0.28),
      0 8px 16px rgba(9, 16, 34, 0.24);
    font-size: 0.56rem;
    padding: 10px 10px;
  }

  .foot {
    margin-top: 0;
    background: transparent;
  }

  .touch-lane {
    margin-top: 4px;
  }
}

body.cg-phone-landscape-blocked #game-root canvas {
  opacity: 0;
}

body.cg-phone-landscape-blocked .game-card {
  background:
    linear-gradient(180deg, #f8e1e1 0%, #f3c9c9 46%, #d14949 100%);
}

.phone-landscape-blocker {
  display: none;
  border: 3px solid #bf1f1f;
  border-radius: 10px;
  background: linear-gradient(180deg, #14213a 0%, #0c1630 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 226, 226, 0.28);
  min-height: 46svh;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px;
  user-select: none;
}

.phone-landscape-blocker p {
  margin: 0;
  color: #ecf2ff;
  font-size: clamp(1.1rem, 4.2vw, 1.7rem);
  line-height: 1.25;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.phone-landscape-blocker .hint {
  color: #ecf2ff;
  font-size: clamp(0.56rem, 2vw, 0.74rem);
  line-height: 1.4;
}

body.cg-phone-landscape-blocked .phone-landscape-blocker {
  display: flex;
  grid-area: game;
}

body.cg-phone-landscape-blocked .game-card,
body.cg-phone-landscape-blocked .side-ranking,
body.cg-phone-landscape-blocked .touch-lane,
body.cg-phone-landscape-blocked .foot {
  display: none !important;
}

@media (pointer: coarse) and (max-width: 760px) {
  .layout {
    padding-left: 8px;
    padding-right: 8px;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  .topbar h1 {
    font-size: 1.16rem;
    line-height: 1.05;
  }

  .topbar p {
    font-size: 0.7rem;
    margin-top: 4px;
  }

  .topbar {
    border: 3px solid #c91717;
    border-radius: 12px;
    padding: 8px 10px 7px;
    text-align: center;
    background:
      radial-gradient(95% 130% at 50% 8%, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.2) 60%, rgba(255, 255, 255, 0.06) 100%),
      linear-gradient(180deg, #fff3f3 0%, #f2bcbc 50%, #cb3030 100%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.7),
      0 10px 24px rgba(125, 14, 14, 0.2);
  }

  .game-card {
    padding: 9px;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    margin-top: 0;
  }

  #game-root canvas {
    aspect-ratio: 1 / 1;
  }

  .capture-results {
    padding: 6px;
  }

  .capture-results h2 {
    font-size: 0.74rem;
    margin-bottom: 6px;
  }

  .capture-results.entry-modal-active .ranking-entry {
    width: min(312px, calc(100vw - 74px));
    padding: 14px 10px 10px;
  }

  .ranking-list {
    gap: 4px;
    max-width: none;
    margin-bottom: 10px;
  }

  .ranking-list li {
    grid-template-columns: 54px 1fr 62px;
    gap: 7px;
    font-size: 0.68rem;
    line-height: 1.08;
    padding: 4px 6px;
  }

  .ranking-list li.ranking-empty {
    padding: 7px 10px 6px;
    font-size: 0.6rem;
    letter-spacing: 0.2px;
  }

  .ranking-note {
    font-size: 0.52rem;
    margin-top: 8px;
    margin-bottom: 8px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.22;
  }

  .foot {
    font-size: 0.72rem;
    padding-top: 2px;
  }

  .mobile-restart {
    min-height: 54px;
    font-size: 0.66rem;
    padding: 12px 12px;
  }
}

@media (pointer: coarse) and (min-width: 761px) and (orientation: portrait) {
  .layout {
    max-width: 880px;
    margin-inline: auto;
    gap: 10px;
  }

  .topbar {
    text-align: center;
    border: 3px solid #c91717;
    border-radius: 12px;
    padding: 12px 16px 10px;
    background:
      radial-gradient(95% 130% at 50% 8%, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.2) 60%, rgba(255, 255, 255, 0.06) 100%),
      linear-gradient(180deg, #fff3f3 0%, #f2bcbc 50%, #cb3030 100%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.7),
      0 12px 26px rgba(125, 14, 14, 0.2);
  }

  .topbar h1 {
    font-size: clamp(1.6rem, 3.8vw, 2.25rem);
  }

  .topbar p {
    font-size: clamp(0.72rem, 1.9vw, 0.95rem);
  }

  .game-card {
    width: min(96vw, 92svh);
    max-width: 980px;
    margin-inline: auto;
    aspect-ratio: 980 / 590;
    padding: 8px;
  }

  #game-root canvas {
    aspect-ratio: 980 / 590;
  }

  .touch-lane {
    min-height: 180px;
  }
}

@media (orientation: landscape) and (pointer: coarse) {
  .layout {
    max-width: 100%;
    margin: 0 auto;
    padding: calc(8px + env(safe-area-inset-top)) 10px calc(8px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: minmax(0, 2.55fr) minmax(280px, 0.68fr);
    grid-template-areas:
      "top rank"
      "game rank"
      "game lane"
      "game foot";
    gap: 8px 12px;
    align-items: start;
    min-height: 100dvh;
  }

  .layout.controls-left {
    grid-template-columns: minmax(280px, 0.68fr) minmax(0, 2.55fr);
    grid-template-areas:
      "rank top"
      "rank game"
      "lane game"
      "foot game";
  }

  .topbar {
    grid-area: top;
    text-align: center;
    align-self: end;
    border: 3px solid #c91717;
    border-radius: 12px;
    padding: 10px 14px 9px;
    background:
      radial-gradient(95% 130% at 50% 8%, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.2) 60%, rgba(255, 255, 255, 0.06) 100%),
      linear-gradient(180deg, #fff3f3 0%, #f2bcbc 50%, #cb3030 100%);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.7),
      0 10px 22px rgba(125, 14, 14, 0.22);
  }

  .topbar h1 {
    font-size: clamp(1.05rem, 2.2vw, 1.38rem);
  }

  .topbar p {
    font-size: clamp(0.56rem, 1.2vw, 0.72rem);
  }

  .game-card {
    grid-area: game;
    margin-top: 0;
    padding: 8px;
    width: 100%;
    max-width: none;
    min-height: 0;
    aspect-ratio: 980 / 590;
    justify-self: start;
    align-self: start;
  }

  #game-root {
    width: 100%;
    height: 100%;
    aspect-ratio: 980 / 590;
  }

  #game-root canvas {
    width: 100%;
    height: 100%;
    aspect-ratio: 980 / 590;
  }

  .touch-lane {
    grid-area: lane;
    min-height: 96px;
    margin-top: 0;
    font-size: 0.72rem;
  }

  .side-ranking {
    grid-area: rank;
    display: flex;
    flex-direction: column;
    min-height: clamp(300px, 58svh, 500px);
    height: clamp(300px, 58svh, 500px);
    max-height: clamp(300px, 58svh, 500px);
    overflow: hidden;
  }

  .side-ranking .ranking-list {
    gap: 4px;
    max-width: none;
    margin-bottom: 10px;
    overflow: auto;
    padding-right: 2px;
    flex: 1 1 auto;
  }

  .side-ranking .side-capture-feed {
    margin-top: 4px;
    flex: 1 1 auto;
  }

  .side-ranking .side-capture-list {
    max-height: none;
  }

  .side-ranking .ranking-list li {
    grid-template-columns: 54px 1fr 60px;
    gap: 6px;
    font-size: 0.62rem;
    line-height: 1.1;
    padding: 4px 6px;
  }

  .side-ranking .ranking-list li.ranking-empty {
    padding: 7px 9px 6px;
    font-size: 0.56rem;
    letter-spacing: 0.15px;
  }

  .side-ranking .ranking-note {
    font-size: 0.56rem;
    margin-top: 8px;
    margin-bottom: 6px;
    text-align: center;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.28;
  }

  .side-ranking .ranking-entry {
    margin-top: 10px;
    border: 2px solid #d93025;
    border-radius: 10px;
    background: rgba(8, 16, 34, 0.96);
    padding: 10px 8px 8px;
  }

  .side-ranking .ranking-entry-help {
    margin-top: 6px;
    font-size: 0.5rem;
  }

  .side-ranking .ranking-entry-title {
    margin: 0 0 8px;
    font-size: 0.82rem;
    line-height: 1.05;
    letter-spacing: 0.9px;
    text-align: center;
  }

  .side-ranking .ranking-entry-top {
    font-size: 0.9rem;
  }

  .side-ranking .ranking-entry-subtop {
    font-size: 0.72rem;
    margin-top: 2px;
  }

  .side-ranking .ranking-entry-score {
    margin-top: 5px;
    font-size: 0.58rem;
  }

  .side-ranking .ranking-note {
    margin-top: 4px;
    margin-bottom: 8px;
    font-size: 0.54rem;
  }

  .side-ranking .ranking-entry-slots span {
    min-width: 36px;
    padding: 8px 0;
    font-size: 0.72rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .foot {
    grid-area: foot;
    margin-top: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .controls-side-toggle {
    display: none;
    width: 100%;
  }

  /* Ajuste especifico iPad:
     compacta columna derecha para evitar huecos verticales excesivos sin afectar a otras tablets. */
  body.cg-ipad .layout {
    gap: 6px 8px;
    grid-template-columns: minmax(0, 2.7fr) minmax(270px, 0.74fr);
  }

  body.cg-ipad .layout.controls-left {
    grid-template-columns: minmax(270px, 0.74fr) minmax(0, 2.7fr);
  }

  body.cg-ipad .side-ranking {
    align-self: stretch;
    height: 100%;
    max-height: none;
    min-height: 0;
  }

  body.cg-ipad .touch-lane {
    min-height: 84px;
  }
}

@media (orientation: landscape) and (pointer: coarse) and (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 2.9fr) minmax(300px, 0.64fr);
    gap: 10px 12px;
  }

  .layout.controls-left {
    grid-template-columns: minmax(300px, 0.64fr) minmax(0, 2.9fr);
  }

  .game-card {
    min-height: 0;
  }

  .side-ranking {
    min-height: clamp(320px, 60svh, 560px);
    height: clamp(320px, 60svh, 560px);
    max-height: clamp(320px, 60svh, 560px);
  }

  .side-ranking .ranking-list li {
    font-size: 0.66rem;
  }

  .side-ranking .ranking-entry-title {
    font-size: 0.9rem;
  }

  .side-ranking .ranking-entry-top {
    font-size: 0.98rem;
  }
}

/* Ajuste fino iPad/tablet horizontal:
   reduce separaciones visuales y evita huecos grandes entre panel derecho y controles. */
@media (orientation: landscape) and (pointer: coarse) and (min-width: 980px) and (max-width: 1400px) {
  .layout {
    padding: calc(6px + env(safe-area-inset-top)) 8px calc(6px + env(safe-area-inset-bottom));
    gap: 8px 10px;
    grid-template-columns: minmax(0, 2.95fr) minmax(292px, 0.68fr);
  }

  .layout.controls-left {
    grid-template-columns: minmax(292px, 0.68fr) minmax(0, 2.95fr);
  }

  .topbar {
    padding: 8px 12px 7px;
  }

  .game-card {
    padding: 7px;
  }

  .side-ranking {
    min-height: clamp(320px, 60svh, 560px);
    height: clamp(320px, 60svh, 560px);
    max-height: clamp(320px, 60svh, 560px);
  }

  .touch-lane {
    min-height: 88px;
  }
}

.side-ranking.is-capture-mode .ranking-list,
.side-ranking.is-capture-mode .ranking-note,
.side-ranking.is-capture-mode .ranking-entry {
  display: none !important;
}

.side-ranking.is-capture-mode .side-capture-feed {
  display: grid !important;
}

.side-ranking:not(.is-capture-mode) .side-capture-feed {
  display: none !important;
}

@media (orientation: landscape) and (pointer: coarse) and (max-height: 500px) {
  .side-ranking {
    display: none !important;
  }

  .layout,
  .layout.controls-left {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "top"
      "game"
      "lane"
      "foot";
  }
}

@media (min-width: 761px) and (max-height: 860px) and (pointer: fine) {
  .layout {
    padding: 8px 12px 10px;
  }

  .topbar {
    margin: 0 auto 6px;
    padding: 10px 14px 9px;
    border-width: 2px;
    border-radius: 10px 10px 7px 7px;
  }

  .topbar h1 {
    font-size: clamp(1.3rem, 2.8vw, 1.8rem);
  }

  .topbar p {
    font-size: 0.6rem;
    margin-top: 3px;
  }

  .game-card {
    margin-top: 4px;
    padding: 7px;
    border-width: 2px;
    max-width: min(96vw, calc((100vh - 182px) * 16 / 9));
    margin-inline: auto;
  }

  #game-root canvas {
    max-height: calc(100vh - 210px);
  }

  .foot {
    margin-top: 6px;
    padding: 8px 12px 10px;
    border-width: 2px;
    border-radius: 7px 7px 10px 10px;
  }

  .controls-hint {
    font-size: 0.62rem;
    line-height: 1.25;
  }
}
