*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --cell-size: 28px;
  --cyan: #00dbe9;
  --purple: #d05bff;
  --green: #a2ef00;
  --surface: #14141f;
  --surface-2: #1d1f2e;
  --border: rgba(255, 255, 255, 0.08);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Sora', system-ui, sans-serif;
  background: radial-gradient(ellipse at 30% 15%, #1a1040 0%, #0a0a14 55%, #050508 100%);
  color: #e8e8f0;
}

#scale-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game-stage {
  transform-origin: center center;
  will-change: transform;
}

#game-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  flex-shrink: 0;
}

.game-shell {
  background: rgba(20, 20, 31, 0.92);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow:
    0 0 0 1px rgba(0, 219, 233, 0.06),
    0 12px 40px rgba(0, 0, 0, 0.45),
    0 0 48px rgba(208, 91, 255, 0.08);
  overflow: hidden;
  max-width: calc(100vw - 1.5rem);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0, 219, 233, 0.08) 0%, transparent 100%);
}

.game-header h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.game-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-item-wrap {
  position: relative;
}

.nav-btn {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.nav-btn:hover,
.nav-btn.active {
  color: var(--cyan);
  border-color: rgba(0, 219, 233, 0.35);
  background: rgba(0, 219, 233, 0.08);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 220px;
  padding: 0.35rem;
  background: var(--surface-2);
  border: 1px solid rgba(0, 219, 233, 0.2);
  border-radius: 0.65rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.menu-dropdown.hidden {
  display: none;
}

.menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.78rem;
  color: #d1d5db;
  background: transparent;
  border: none;
  border-radius: 0.45rem;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.menu-dropdown button:hover {
  background: rgba(0, 219, 233, 0.12);
  color: #fff;
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 4.5rem;
}

.stat-label {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.stat-digits {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0, 219, 233, 0.45);
  line-height: 1;
}

.reset-btn {
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  border: 1px solid rgba(0, 219, 233, 0.35);
  background: linear-gradient(145deg, rgba(0, 219, 233, 0.15), rgba(208, 91, 255, 0.12));
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s;
  box-shadow: 0 0 16px rgba(0, 219, 233, 0.15);
}

.reset-btn:hover {
  box-shadow: 0 0 22px rgba(0, 219, 233, 0.3);
}

.reset-btn:active {
  transform: scale(0.94);
}

.status-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
  position: relative;
  border-radius: 50%;
}

.status-icon .face-glyph {
  display: none;
  position: absolute;
  inset: 0;
  width: 0.92rem;
  height: 0.92rem;
  margin: auto;
  color: #fff;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55));
}

.status-normal {
  background: radial-gradient(circle at 35% 30%, #e8fcff 0%, var(--cyan) 52%, #007a99 100%);
  box-shadow: 0 0 10px rgba(0, 219, 233, 0.5);
}

.status-normal .face-glyph {
  display: block;
}

.status-wow {
  background: radial-gradient(circle at 35% 30%, #fff 0%, var(--purple) 55%, #8020cc 100%);
  box-shadow: 0 0 12px rgba(208, 91, 255, 0.55);
  transform: scale(1.08);
}

.status-wow::before,
.status-wow::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 5px;
  background: #0a0a14;
  border-radius: 50%;
  top: 2px;
}

.status-wow::before { left: 2px; }
.status-wow::after { right: 2px; }

.status-dead {
  background: radial-gradient(circle at 50% 50%, #ff6b6b 0%, #c92a2a 100%);
  box-shadow: 0 0 12px rgba(255, 80, 80, 0.5);
}

.status-dead::before,
.status-dead::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 10px;
  background: #fff;
  top: 50%;
  left: 50%;
  border-radius: 1px;
}

.status-dead::before { transform: translate(-50%, -50%) rotate(45deg); }
.status-dead::after { transform: translate(-50%, -50%) rotate(-45deg); }

.status-cool {
  background: radial-gradient(circle at 35% 30%, #fff 0%, var(--green) 50%, #6aaa00 100%);
  box-shadow: 0 0 12px rgba(162, 239, 0, 0.45);
}

.status-cool::before {
  content: '★';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #0a0a14;
  line-height: 1;
}

.board-scroll-shell {
  position: relative;
  width: 100%;
  margin: 0 0 1rem;
}

.board-frame {
  margin: 0 1rem;
  padding: 1.1rem 0.85rem;
  border-radius: 0.75rem;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    inset 0 0 0 1px rgba(0, 219, 233, 0.06),
    0 0 20px rgba(0, 219, 233, 0.06);
  overflow: auto;
  max-width: calc(100vw - 2.5rem);
}

/* ── Experto móvil: scroll + controles direccionales ── */
body.level-expert.expert-mobile-scroll #scale-viewport {
  height: 100dvh;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

body.level-expert.expert-mobile-scroll #game-stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

body.level-expert.expert-mobile-scroll #game-root {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem;
  gap: 0.35rem;
}

body.level-expert.expert-mobile-scroll .game-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
}

body.level-expert.expert-mobile-scroll .game-header,
body.level-expert.expert-mobile-scroll .stats-bar {
  flex-shrink: 0;
}

body.level-expert.expert-mobile-scroll .board-scroll-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  margin: 0;
  padding: 0;
}

body.level-expert.expert-mobile-scroll .board-frame {
  flex: 1 1 auto;
  min-height: 0;
  max-width: 100%;
  width: calc(100% - 2rem);
  max-height: none;
  height: auto;
  margin: 0 1rem;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 219, 233, 0.55) rgba(255, 255, 255, 0.08);
}

body.level-expert.expert-mobile-scroll .board-frame::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

body.level-expert.expert-mobile-scroll .board-frame::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
}

body.level-expert.expert-mobile-scroll .board-frame::-webkit-scrollbar-thumb {
  background: rgba(0, 219, 233, 0.5);
  border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.2);
}

body.level-expert.expert-mobile-scroll .board-frame::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 219, 233, 0.72);
}

body.level-expert.expert-mobile-scroll .board-scroll-controls {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-shrink: 0;
  width: 100%;
  margin: 0;
  padding: 0.45rem 1rem 0.55rem;
}

/* ── Experto PC: tablero completo, sin scroll ni controles ── */
@media (min-width: 768px) {
  body.level-expert.expert-desktop-expand,
  body.level-expert.expert-desktop-expand html {
    height: auto;
    overflow: visible;
  }

  body.level-expert.expert-desktop-expand #scale-viewport {
    height: auto;
    min-height: 0;
    overflow: visible;
    align-items: center;
    justify-content: flex-start;
  }

  body.level-expert.expert-desktop-expand #game-root {
    width: 100%;
    max-width: 100%;
    padding: 0.75rem;
    gap: 0.5rem;
  }

  body.level-expert.expert-desktop-expand .game-shell {
    flex: none;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
  }

  body.level-expert.expert-desktop-expand .board-scroll-shell {
    flex: none;
    width: auto;
  }

  body.level-expert.expert-desktop-expand .board-frame {
    flex: none;
    overflow: visible;
    max-height: none;
    width: auto;
    margin: 0 1rem 1rem;
    scrollbar-width: none;
  }

  body.level-expert.expert-desktop-expand .board-frame::-webkit-scrollbar {
    display: none;
  }

  body.level-expert.expert-desktop-expand .board-scroll-controls {
    display: none !important;
  }
}

body.level-expert .board,
body.level-expert #board {
  width: max-content !important;
  max-width: none !important;
  height: auto !important;
}

.board-scroll-controls {
  display: none;
}

.board-scroll-btn {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(0, 219, 233, 0.35);
  border-radius: 0.45rem;
  background: rgba(8, 10, 18, 0.88);
  color: var(--cyan);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  transition: background 0.15s, transform 0.1s;
}

.board-scroll-btn svg {
  width: 0.85rem;
  height: 0.85rem;
  display: block;
}

.board-scroll-btn:hover {
  background: rgba(0, 219, 233, 0.18);
}

.board-scroll-btn:active {
  transform: scale(0.94);
}

body.level-expert.expert-mobile-scroll .hint-bar {
  flex-shrink: 0;
  margin-top: 0;
  padding-bottom: 0.25rem;
}

.board-frame.board-locked .cell {
  pointer-events: none;
  cursor: default;
}

.board-frame.board-locked .cell.hidden:hover {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 2px 6px rgba(0, 0, 0, 0.35);
}

.board-frame.board-locked .cell.hidden:active {
  transform: none;
}

body.level-beginner {
  --cell-size: 32px;
}

.board {
  display: grid;
  gap: 3px;
  line-height: 0;
}

body.level-beginner .board {
  gap: 4px;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: none;
  padding: 0;
  font-family: 'Sora', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: var(--cell-size);
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 0.35rem;
  transition: transform 0.08s, box-shadow 0.12s;
}

.cell.hidden {
  background: linear-gradient(145deg, #2a2a42 0%, #1a1a2e 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 2px 6px rgba(0, 0, 0, 0.35);
}

.cell.hidden:hover {
  border-color: rgba(0, 219, 233, 0.35);
  box-shadow: 0 0 10px rgba(0, 219, 233, 0.15);
}

.cell.hidden:active {
  transform: scale(0.92);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
}

.cell.revealed {
  background: #12121c;
  border: 1px solid rgba(255, 255, 255, 0.05);
  cursor: default;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.cell.flagged {
  background: linear-gradient(145deg, #2a2548 0%, #1e1a36 100%);
  border: 1px solid rgba(208, 91, 255, 0.35);
}

.cell.mine-hit {
  background: radial-gradient(circle at 50% 40%, #ff7070 0%, #b91c1c 70%);
  border: 1px solid #ff9999;
  box-shadow: 0 0 14px rgba(255, 80, 80, 0.55);
  animation: pulse-mine 0.5s ease-out;
}

@keyframes pulse-mine {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.cell.mine-wrong {
  background: #1a1020;
  border: 1px solid rgba(255, 80, 80, 0.5);
}

.cell .mine-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  position: relative;
  vertical-align: middle;
}

.cell .mine-icon::before {
  content: '';
  position: absolute;
  top: 0;
  left: 6px;
  width: 2px;
  height: 6px;
  background: var(--purple);
  border-radius: 1px;
  transform: rotate(25deg);
  transform-origin: bottom center;
  z-index: 2;
  box-shadow: 0 0 4px var(--purple);
}

.cell .mine-icon::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: radial-gradient(circle at 32% 28%, #6060a0 0%, #1a1a2e 55%, #000 100%);
  border-radius: 50%;
  box-shadow:
    0 0 6px rgba(208, 91, 255, 0.5),
    -1px 0 0 0 rgba(208, 91, 255, 0.4),
    1px 0 0 0 rgba(208, 91, 255, 0.4),
    0 -1px 0 0 rgba(208, 91, 255, 0.4),
    0 1px 0 0 rgba(208, 91, 255, 0.4);
}

.cell.mine-hit .mine-icon::after {
  background: radial-gradient(circle at 32% 28%, #ffaaaa 0%, #cc2222 55%, #660000 100%);
}

.cell .flag-icon {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
}

.cell .flag-icon::before {
  content: '';
  position: absolute;
  left: 42%;
  top: 18%;
  width: 2px;
  height: 65%;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 1px;
}

.cell .flag-icon::after {
  content: '';
  position: absolute;
  left: 48%;
  top: 22%;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 9px solid var(--purple);
  filter: drop-shadow(0 0 4px rgba(208, 91, 255, 0.6));
}

.cell .flag-wrong::after {
  content: '✕';
  color: #ff6b6b;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: var(--cell-size);
  text-shadow: 0 0 8px rgba(255, 80, 80, 0.6);
}

.n1 { color: #5eb3ff; text-shadow: 0 0 6px rgba(94, 179, 255, 0.4); }
.n2 { color: var(--green); text-shadow: 0 0 6px rgba(162, 239, 0, 0.35); }
.n3 { color: #ff6b8a; text-shadow: 0 0 6px rgba(255, 107, 138, 0.35); }
.n4 { color: #9b7bff; text-shadow: 0 0 6px rgba(155, 123, 255, 0.35); }
.n5 { color: #ffb347; text-shadow: 0 0 6px rgba(255, 179, 71, 0.35); }
.n6 { color: var(--cyan); text-shadow: 0 0 6px rgba(0, 219, 233, 0.35); }
.n7 { color: #f0f0f5; }
.n8 { color: rgba(255, 255, 255, 0.45); }

.hint-bar {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.45);
  text-align: center;
  max-width: 36rem;
  line-height: 1.45;
  padding: 0 0.5rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 12, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--surface-2);
  border: 1px solid rgba(0, 219, 233, 0.25);
  border-radius: 1rem;
  padding: 1.5rem 1.75rem;
  min-width: 260px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 0 40px rgba(0, 219, 233, 0.12);
}

.modal-win {
  border-color: rgba(162, 239, 0, 0.35);
  box-shadow: 0 0 40px rgba(162, 239, 0, 0.12);
}

.modal-lose {
  border-color: rgba(255, 107, 138, 0.4);
  box-shadow: 0 0 40px rgba(255, 80, 80, 0.15);
}

.modal-card h2 {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 0.65rem;
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-win h2 {
  background: linear-gradient(90deg, var(--green), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
}

.modal-lose h2 {
  background: linear-gradient(90deg, #ff6b8a, #ff3355);
  -webkit-background-clip: text;
  background-clip: text;
}

.modal-card p {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.btn-primary {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #0a0a14;
  background: linear-gradient(90deg, var(--cyan), #00b8d4);
  border: none;
  border-radius: 0.55rem;
  padding: 0.55rem 1.25rem;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s;
  box-shadow: 0 0 18px rgba(0, 219, 233, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 0 24px rgba(0, 219, 233, 0.5);
}

.btn-primary:active {
  transform: scale(0.97);
}

body.level-beginner .cell {
  font-size: 0.9rem;
}

@media (max-width: 520px) {
  :root {
    --cell-size: 24px;
  }

  body.level-beginner {
    --cell-size: 28px;
  }

  .board-frame {
    padding: 1rem 0.7rem;
  }

  body.level-expert.expert-mobile-scroll .board-frame {
    width: calc(100% - 1.5rem);
    margin: 0 0.75rem;
  }

  body.level-expert.expert-mobile-scroll .board-scroll-controls {
    gap: 0.4rem;
    padding: 0.4rem 0.75rem 0.45rem;
  }

  .game-header h1 {
    font-size: 1rem;
  }

  .stat-digits {
    font-size: 1.1rem;
  }
}