.play-btn {
  margin-top: 14px;
  padding: 14px 32px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #050505;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 50%, transparent);
  transition: transform 0.2s ease;
}
.play-btn:hover { transform: scale(1.05); }
.play-btn:active { transform: scale(0.97); }

.stop-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 68px);
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.4);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  z-index: 6;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}
.stop-btn:hover { opacity: 1; }

.dpad {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 34px);
  right: 16px;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 4px;
  z-index: 6;
}
.dpad-btn {
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.45);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.dpad-btn:active { background: color-mix(in srgb, var(--accent) 40%, rgba(0,0,0,0.45)); }
.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 2; }

.maze-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 20px;
  gap: 14px;
  z-index: 2;
  position: relative;
}

.timer-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
  flex-shrink: 0;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left;
  transition: width linear;
}

.maze-stage {
  position: relative;
  width: 300px;
  height: 380px;
  overflow: hidden;
  background: #0a0c12;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.35);
}

.maze-inner {
  position: absolute;
  display: grid;
  gap: 2px;
  padding: 6px;
  transition: left 0.15s ease, top 0.15s ease;
}

.cell {
  width: var(--cell-size, 30px);
  height: var(--cell-size, 30px);
  border-radius: 4px;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}
/* Contraste alto a propósito: pared casi negra vs. piso claro, legible a pleno sol */
.cell.wall { background: #05060a; }
.cell.floor { background: #7d8aa8; }
.cell.exit {
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
  animation: pulseExit 1.4s ease infinite;
}
@keyframes pulseExit {
  0%, 100% { box-shadow: 0 0 8px var(--accent); }
  50% { box-shadow: 0 0 22px var(--accent); }
}

.cell.door-closed {
  background: var(--accent-2);
  border: 2px solid #ffffff;
  box-shadow: 0 0 12px var(--accent-2);
}
.cell.door-open {
  background: #a9b6d3;
}
.cell.door-stone {
  background: repeating-linear-gradient(45deg, #2b2b2b, #2b2b2b 4px, #5a5a5a 4px, #5a5a5a 8px);
}

.character {
  position: absolute;
  width: var(--cell-size, 30px);
  height: var(--cell-size, 30px);
  transition: left 0.14s ease, top 0.14s ease;
  filter: drop-shadow(0 0 1.5px #000) drop-shadow(0 0 1.5px #000) drop-shadow(0 0 5px var(--accent));
  z-index: 5;
}
.character.facing-left { transform: scaleX(-1); }

.character .head {
  position: absolute;
  top: 14%;
  left: 50%;
  width: 34%;
  height: 34%;
  margin-left: -17%;
  border-radius: 50%;
  background: var(--accent);
}
.character .body {
  position: absolute;
  top: 44%;
  left: 50%;
  width: 8%;
  height: 26%;
  margin-left: -4%;
  background: var(--text);
  border-radius: 3px;
}
.character .leg {
  position: absolute;
  top: 66%;
  left: 50%;
  width: 7%;
  height: 26%;
  background: var(--text);
  border-radius: 3px;
  transform-origin: top center;
}
.character .leg.l { margin-left: -9%; }
.character .leg.r { margin-left: 2%; }
.character.walking .leg.l { animation: legSwing 0.28s ease-in-out infinite alternate; }
.character.walking .leg.r { animation: legSwing 0.28s ease-in-out infinite alternate-reverse; }
@keyframes legSwing {
  0% { transform: rotate(-22deg); }
  100% { transform: rotate(22deg); }
}
.character .arm {
  position: absolute;
  top: 46%;
  left: 50%;
  width: 6%;
  height: 20%;
  background: var(--accent-2);
  border-radius: 3px;
  transform-origin: top center;
}
.character .arm.l { margin-left: -13%; }
.character .arm.r { margin-left: 7%; }
.character.walking .arm.l { animation: legSwing 0.28s ease-in-out infinite alternate-reverse; }
.character.walking .arm.r { animation: legSwing 0.28s ease-in-out infinite alternate; }

.character.bump { animation: bump 0.2s ease; }
@keyframes bump {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-4px); }
}

.toast {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--card-border);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  animation: slideFadeIn 0.3s ease both;
}

/* ---- Quiz overlay ---- */
.quiz-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  padding: 20px;
}
.quiz-card {
  width: 100%;
  max-width: 340px;
  background: #12151c;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 22px 20px;
  animation: pop 0.3s ease;
}
.quiz-topic {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.7;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.quiz-question {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
  margin-bottom: 16px;
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.3s ease, background 0.4s ease, border-color 0.4s ease, opacity 0.4s ease;
}
.quiz-option .letter {
  width: 24px; height: 24px;
  min-width: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  font-size: 11px;
  font-weight: 800;
}
.quiz-option.correct {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  border-color: var(--accent);
  transform: scale(1.03);
}
.quiz-option.correct .letter { background: var(--accent); color: #050505; }
.quiz-option.correct .text::after { content: ' ✓'; }
.quiz-option.dim { opacity: 0.35; }
.quiz-option.wrong {
  background: color-mix(in srgb, var(--wrong) 30%, transparent);
  border-color: var(--wrong);
}
.quiz-option.wrong .letter { background: var(--wrong); color: #050505; }
.quiz-option.wrong .text::after { content: ' ✗'; }
.quiz-option:not(.correct):not(.wrong):not(.dim) { cursor: pointer; }
.quiz-option:not(.correct):not(.wrong):not(.dim):hover {
  background: rgba(255,255,255,0.1);
  transform: scale(1.02);
}

/* ---- Fin de nivel / Game over ---- */
.end-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
  padding: 20px;
}
.end-card {
  width: 100%;
  max-width: 320px;
  background: #12151c;
  border: 1px solid var(--wrong);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  animation: pop 0.35s ease;
}
.end-emoji { font-size: 56px; margin-bottom: 8px; }
.end-card h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--wrong);
  margin-bottom: 8px;
}
.end-card p { font-size: 14px; opacity: 0.8; margin-bottom: 20px; }
.end-card .pin-btn { width: 100%; }

/* ---- Versión PC: pantalla completa, todo más grande ---- */
@media (min-width: 900px) and (min-height: 560px) {
  .phone { width: 100vw; height: 100vh; box-shadow: none; }
  .topbar { padding-top: 12px; }
  .badge { font-size: 18px; padding: 10px 24px; }
  .idle-logo { font-size: 84px; }
  .idle h1 { font-size: 46px; }
  .play-btn { font-size: 22px; padding: 18px 52px; }
  .stop-btn { top: 114px; right: 32px; width: 46px; height: 46px; font-size: 18px; }
  .ad-slot { width: min(728px, calc(100% - 40px)); height: 90px; margin-top: 10px; }
  .ad-fake { font-size: 22px; gap: 16px; }
  .ad-fake small { font-size: 14px; }
  .maze-wrap { padding: 10px 40px 28px; gap: 16px; min-height: 0; }
  .timer-bar { max-width: 1200px; height: 9px; }
  .maze-stage { width: 100%; max-width: 1200px; height: auto; flex: 1; min-height: 0; }
  .toast { font-size: 17px; padding: 10px 22px; bottom: 16px; }
  .quiz-card { max-width: 620px; padding: 34px 32px; }
  .quiz-topic { font-size: 14px; }
  .quiz-question { font-size: 26px; margin-bottom: 22px; }
  .quiz-option { font-size: 18px; padding: 16px 20px; }
  .quiz-option .letter { width: 30px; height: 30px; min-width: 30px; font-size: 13px; }
  .end-card { max-width: 440px; padding: 40px 30px; }
  .end-card h2 { font-size: 30px; }
  .end-card p { font-size: 16px; }
}

/* Con mouse y teclado la cruz táctil sobra */
@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .dpad { display: none !important; }
}

/* ---- Puntaje ---- */
.topbar { gap: 10px; align-items: center; }
.score {
  font-size: 14px;
  font-weight: 800;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--accent-2);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent-2) 40%, transparent);
  white-space: nowrap;
}
.score.score-pop { animation: pop 0.35s ease; }

.score-line {
  font-size: 17px !important;
  font-weight: 800;
  opacity: 1 !important;
  color: var(--accent-2);
}

/* ---- Nivel terminado ---- */
.end-card.win { border-color: var(--accent); }
.end-card.win h2 { color: var(--accent); }
.end-card .pin-btn + .pin-btn { margin-top: 10px; }

@media (min-width: 900px) and (min-height: 560px) {
  .score { font-size: 18px; padding: 10px 22px; }
  .score-line { font-size: 20px !important; }
}

/* ---- Elegir respuesta con el teclado (PC) ---- */
.quiz-option.focus {
  background: rgba(255,255,255,0.18);
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px var(--accent-2), 0 0 16px color-mix(in srgb, var(--accent-2) 55%, transparent);
  transform: scale(1.02);
}
.quiz-hint { display: none; font-size: 12px; opacity: 0.6; margin: -6px 0 12px; }
@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .quiz-hint { display: block; }
}

/* ---- Récord ---- */
.record-line { font-size: 15px; font-weight: 800; color: var(--accent-2); margin-top: 2px; }
.end-card .score-line + .score-line { margin-top: -12px; }
@media (min-width: 900px) and (min-height: 560px) {
  .record-line { font-size: 20px; }
}

/* ---- Banner de publicidad (arriba) ---- */
.ad-slot {
  position: relative;
  z-index: 3;
  flex-shrink: 0;
  width: min(320px, calc(100% - 24px));
  height: 50px;
  margin: calc(env(safe-area-inset-top, 0px) + 8px) auto 0;
  border-radius: 6px;
  overflow: hidden;
}
.ad-fake {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(90deg, #ff7a18, #af002d 70%, #5b0a6f);
  color: #fff;
  font-size: 15px;
}
.ad-fake small { opacity: 0.85; font-size: 11px; }
.ad-tag {
  position: absolute;
  top: 0; left: 0;
  font-size: 9px;
  letter-spacing: 0.4px;
  background: rgba(0,0,0,0.55);
  padding: 1px 6px;
  border-bottom-right-radius: 6px;
}
.topbar { padding-top: 10px; }

/* Con el banner ocupando el alto de arriba, el laberinto se ajusta al alto real de la pantalla
   para que la cruz de flechas nunca lo tape */
@media (max-width: 430px) { .phone { height: 100vh; height: 100dvh; } }
@supports (height: 100dvh) {
  @media (max-width: 899px) {
    .maze-stage { height: clamp(240px, calc(100dvh - 310px), 420px); }
  }
}
@media (min-width: 900px) and (min-height: 560px) {
  .topbar { padding-top: 12px; }
}

/* ---- Botón de sonido (junto al de detener) ---- */
.sound-btn { right: 60px; font-size: 16px; opacity: 0.85; }
.stop-btn[hidden] ~ .sound-btn { right: 16px; }
@media (min-width: 900px) and (min-height: 560px) {
  .sound-btn { right: 90px; font-size: 20px; }
  .stop-btn[hidden] ~ .sound-btn { right: 32px; }
}

/* ---- Cuentas y tabla de posiciones ---- */
.end-overlay { overflow-y: auto; }
.end-card { margin: auto; }

.board-link {
  margin-top: 6px;
  background: none;
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.board-link:hover { border-color: var(--accent-2); }

.save-box {
  border: 1px dashed var(--accent-2);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}
.save-box .save-text { font-size: 14px !important; opacity: 1 !important; margin: 0 0 8px !important; font-weight: 700; }
.save-box .save-login { width: 100%; }
.save-box .save-text:only-child { margin-bottom: 0 !important; }

.board-card { max-width: 380px; }
.board-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.board-tab {
  flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.06); color: var(--text); font-weight: 700; cursor: pointer;
}
.board-tab.active { background: var(--accent-2); color: #050505; border-color: var(--accent-2); }
.board-list { list-style: none; text-align: left; margin: 0 0 12px; padding: 0; min-height: 60px; }
.board-list li {
  display: flex; gap: 10px; padding: 8px 10px; border-radius: 8px; font-size: 15px; font-weight: 700;
}
.board-list li:nth-child(odd) { background: rgba(255,255,255,0.05); }
.board-list li.me { background: color-mix(in srgb, var(--accent) 30%, transparent); outline: 1px solid var(--accent); }
.board-list .pos { width: 28px; opacity: 0.7; }
.board-list .nick { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .val { color: var(--accent-2); }
.board-status { font-size: 13px !important; opacity: 0.75 !important; margin-bottom: 12px !important; }

.nick-input {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.08); color: var(--text); font-size: 18px; text-align: center; outline: none;
  margin-bottom: 8px;
}
.nick-input:focus { border-color: var(--accent); }
.nick-error { color: var(--wrong); font-size: 13px !important; opacity: 1 !important; margin-bottom: 8px !important; }

/* ---- Inicio: Top 10, cuenta y tabla ---- */
.idle { overflow-y: auto; justify-content: flex-start; padding: 6px 0 24px; }
.idle > :first-child { margin-top: auto; }
.idle > :last-child { margin-bottom: auto; }

.home-board { width: min(340px, calc(100% - 28px)); margin-top: 12px; }
.home-board h3 { font-size: 15px; margin-bottom: 8px; }
.home-board .pin-btn { width: 100%; margin-top: 6px; }
.home-board .board-link { width: 100%; margin-top: 8px; }

.board-tabs.compact { margin-bottom: 8px; }
.board-tabs.compact .board-tab { padding: 6px; font-size: 13px; }
.board-list.compact { min-height: 40px; margin-bottom: 6px; }
.board-list.compact li { padding: 5px 8px; font-size: 13px; }
.board-list li.sep { justify-content: center; opacity: 0.5; background: none !important; padding: 0; }
.home-board .board-status { font-size: 12px !important; min-height: 16px; margin-bottom: 4px !important; }

.user-row {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 8px 10px; margin-bottom: 10px;
  border: 1px solid var(--accent); border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.user-row img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; border: 2px solid var(--accent); flex-shrink: 0; }
.user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-info b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info small { font-size: 12px; opacity: 0.85; }

.link-btn { background: none; border: none; color: var(--accent-2); font-size: 13px; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 4px; }

@media (min-width: 900px) and (min-height: 560px) {
  .home-board { width: 460px; }
  .home-board h3 { font-size: 18px; }
  .board-list.compact li { font-size: 16px; padding: 7px 10px; }
  .user-info b { font-size: 18px; }
  .user-info small { font-size: 14px; }
  .user-row img { width: 54px; height: 54px; }
}

/* ---- Foto en cada fila de la tabla ---- */
.board-list li { align-items: center; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.4); }
.avatar.ph { display: flex; align-items: center; justify-content: center; background: var(--accent-2); color: #050505; font-size: 13px; font-weight: 800; }
.board-list.compact .avatar { width: 24px; height: 24px; font-size: 11px; }
@media (min-width: 900px) and (min-height: 560px) {
  .avatar { width: 34px; height: 34px; }
  .board-list.compact .avatar { width: 30px; height: 30px; }
}

/* ---- La cuenta va aparte de la tabla ---- */
.account-box { width: min(340px, calc(100% - 28px)); margin-top: 12px; }
.account-box .pin-btn { width: 100%; }
.account-box .board-status { font-size: 12px !important; min-height: 0; margin: 0 0 4px !important; opacity: 0.8; }
.account-box .board-status:empty { display: none; }
@media (min-width: 900px) and (min-height: 560px) {
  .account-box { width: 460px; }
}

.install-hint { max-width: 300px; font-size: 12px; opacity: 0.8; text-align: center; }
