/* ============================================================
   RESET & VARIABLES
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #0a0a1a;
  --bg2:           #0f0f23;
  --bg-card:       #131326;
  --bg-cell:       #1c1c32;
  --bg-revealed:   #0b0b1e;
  --border:        rgba(255,255,255,0.07);
  --border-hi:     rgba(255,255,255,0.16);
  --text:          #e2e2f5;
  --text-dim:      #7070a0;
  --blue:          #00bfff;
  --green:         #00ff88;
  --red:           #ff3366;
  --gold:          #ffd700;
  --orange:        #ff8800;
  /* number neon colours */
  --n1: #00c8ff;
  --n2: #00ff88;
  --n3: #ff4466;
  --n4: #8855ff;
  --n5: #ff8800;
  --n6: #00ffee;
  --n7: #ff44ff;
  --n8: #ffffff;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ============================================================
   BACKGROUND DOT PATTERN
   ============================================================ */
.bg-pattern {
  position: fixed; inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

/* ============================================================
   CONFETTI CANVAS
   ============================================================ */
#confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 9999;
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: sticky; top: 0;
  background: rgba(10,10,26,0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  padding: 0 1rem;
}

.header-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  height: 58px; gap: 0.75rem;
}

.logo {
  display: flex; align-items: center; gap: 0.55rem;
  font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em;
  white-space: nowrap;
}
.logo-icon { width: 26px; height: 26px; flex-shrink: 0; }

/* ---- HUD ---- */
.hud { display: flex; align-items: center; gap: 0.4rem; flex-wrap: nowrap; }

.hud-item {
  display: flex; align-items: center; gap: 0.35rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
}
.hud-item svg { width: 15px; height: 15px; flex-shrink: 0; }

.hud-value {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.06em;
  min-width: 3ch;
}

.restart-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
}
.restart-btn:hover { border-color: var(--blue); color: var(--blue); transform: rotate(-30deg); }
.restart-btn svg { width: 17px; height: 17px; }

.icon-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-dim);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-hi); }
.icon-btn svg { width: 17px; height: 17px; }

/* ============================================================
   DIFFICULTY BAR
   ============================================================ */
.difficulty-bar {
  display: flex; justify-content: center; gap: 0.45rem;
  padding: 0.7rem 1rem; flex-wrap: wrap;
  position: relative; z-index: 1;
}

.diff-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-dim);
  padding: 0.38rem 0.85rem;
  cursor: pointer; font-size: 0.82rem; font-weight: 500;
  display: flex; flex-direction: column; align-items: center;
  transition: all 0.2s; line-height: 1.2;
}
.diff-btn small { font-size: 0.62rem; opacity: 0.55; margin-top: 1px; }
.diff-btn:hover { color: var(--text); border-color: var(--border-hi); }
.diff-btn.active {
  background: rgba(0,191,255,0.09);
  border-color: var(--blue); color: var(--blue);
}

/* ---- Custom panel ---- */
.custom-panel {
  display: flex; justify-content: center; gap: 0.75rem;
  padding: 0 1rem 0.75rem; flex-wrap: wrap;
  position: relative; z-index: 1;
}
.custom-panel label {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.8rem; color: var(--text-dim);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.28rem 0.65rem;
}
.custom-panel input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 0.82rem; width: 46px; text-align: center;
}
.btn-accent {
  background: rgba(0,191,255,0.12); border: 1px solid var(--blue);
  border-radius: 8px; color: var(--blue);
  padding: 0.28rem 0.9rem; cursor: pointer; font-size: 0.82rem; font-weight: 600;
  transition: all 0.2s;
}
.btn-accent:hover { background: rgba(0,191,255,0.22); }

/* ============================================================
   MAIN / BOARD
   ============================================================ */
.main {
  display: flex; justify-content: center; align-items: flex-start;
  padding: 0.75rem 1rem 1.5rem;
  position: relative; z-index: 1;
}

#board-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: auto;            /* scroll for very wide boards */
  max-width: 100%;
  box-shadow: 0 0 60px rgba(0,0,40,0.6), 0 0 0 1px var(--border);
}

/* Shake animation on lose */
#board-wrapper.shake {
  animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  10%,30%,50%,70%,90% { transform: translateX(-5px) rotate(-0.3deg); }
  20%,40%,60%,80%     { transform: translateX( 5px) rotate( 0.3deg); }
}

#tablero {
  display: grid;
  grid-template-columns: repeat(var(--columnas, 9), var(--cell-size, 36px));
  grid-template-rows:    repeat(var(--filas,    9), var(--cell-size, 36px));
  gap: 2px;
  padding: 8px;
  background: var(--bg2);
  user-select: none; -webkit-user-select: none;
}

/* ============================================================
   CELLS — BASE
   ============================================================ */
.celda {
  width:  var(--cell-size, 36px);
  height: var(--cell-size, 36px);
  display: flex; justify-content: center; align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: calc(var(--cell-size, 36px) * 0.44);
  font-weight: 700;
  cursor: pointer;
  border-radius: 4px;
  background: var(--bg-cell);
  border: 1px solid rgba(255,255,255,0.09);
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
  position: relative; overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Frost shimmer */
.celda::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.07) 0%, transparent 55%);
  opacity: 1; pointer-events: none;
}

.celda:hover { transform: scale(1.08); border-color: rgba(255,255,255,0.22); box-shadow: 0 0 8px rgba(0,191,255,0.15); }
.celda:active { transform: scale(0.93); }

/* ---- REVEALED ---- */
.celda.revealed {
  background: var(--bg-revealed);
  border-color: rgba(255,255,255,0.04);
  cursor: default;
  animation: cellReveal 0.16s ease-out both;
}
.celda.revealed::before { display: none; }
.celda.revealed:hover   { transform: none; box-shadow: none; border-color: rgba(255,255,255,0.04); }
.celda.revealed:active  { transform: none; }

@keyframes cellReveal {
  from { transform: scale(0.82); opacity: 0.5; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ---- EMPTY (0) ---- */
.celda-cero {
  background: rgba(5, 5, 18, 0.95) !important;
  border-color: rgba(255,255,255,0.03) !important;
}

/* ---- NUMBERS ---- */
.celda-uno    { color: var(--n1); text-shadow: 0 0 10px var(--n1); }
.celda-dos    { color: var(--n2); text-shadow: 0 0 10px var(--n2); }
.celda-tres   { color: var(--n3); text-shadow: 0 0 10px var(--n3); }
.celda-cuatro { color: var(--n4); text-shadow: 0 0 10px var(--n4); }
.celda-cinco  { color: var(--n5); text-shadow: 0 0 10px var(--n5); }
.celda-seis   { color: var(--n6); text-shadow: 0 0 10px var(--n6); }
.celda-siete  { color: var(--n7); text-shadow: 0 0 10px var(--n7); }
.celda-ocho   { color: var(--n8); text-shadow: 0 0 10px var(--n8); }

/* ---- FLAGGED ---- */
.celda.flagged {
  background: rgba(255,100,0,0.1) !important;
  border-color: rgba(255,140,0,0.45) !important;
  animation: flagPlace 0.22s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes flagPlace {
  from { transform: scale(0.75) rotate(-12deg); }
  to   { transform: scale(1) rotate(0); }
}
.celda.flagged::before { display: none; }
.celda.flagged::after {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14.4 6L14 4H5v17h2v-7h5.6l.4 2h7V6z' fill='%23ff8800'/%3E%3C/svg%3E") center/55% no-repeat;
  filter: drop-shadow(0 0 5px #ff8800);
}

/* ---- QUESTION MARK ---- */
.celda.question {
  background: rgba(110,70,255,0.12) !important;
  border-color: rgba(136,85,255,0.5) !important;
  color: #9966ff;
  font-size: calc(var(--cell-size, 36px) * 0.52);
  text-shadow: 0 0 8px #9966ff;
}
.celda.question::before { display: none; }
.celda.question::after { content: '?'; }

/* ---- MINE — EXPLODED ---- */
.celda.mina-exploded {
  background: rgba(255,30,30,0.25) !important;
  border-color: #ff3344 !important;
  animation: explode 0.35s ease-out both;
}
@keyframes explode {
  0%  { transform: scale(1); }
  35% { transform: scale(1.35); background: rgba(255,80,0,0.55); }
  100%{ transform: scale(1); }
}

/* ---- MINE — REVEALED (others) ---- */
.celda.mina-revealed {
  background: rgba(255,30,30,0.1) !important;
  border-color: rgba(255,50,50,0.35) !important;
}

/* shared mine SVG via pseudo */
.celda.mina-exploded::after,
.celda.mina-revealed::after {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='14' r='6' fill='%23ff3344'/%3E%3Ccircle cx='12' cy='14' r='4' fill='%23ff6655'/%3E%3Ccircle cx='12' cy='14' r='2' fill='%23ff9977'/%3E%3Cline x1='12' y1='8' x2='12' y2='5' stroke='%23ff3344' stroke-width='2' stroke-linecap='round'/%3E%3Cline x1='6' y1='14' x2='3' y2='14' stroke='%23ff3344' stroke-width='2' stroke-linecap='round'/%3E%3Cline x1='18' y1='14' x2='21' y2='14' stroke='%23ff3344' stroke-width='2' stroke-linecap='round'/%3E%3Cline x1='8.12' y1='10.12' x2='5.93' y2='7.93' stroke='%23ff3344' stroke-width='2' stroke-linecap='round'/%3E%3Cline x1='15.88' y1='10.12' x2='18.07' y2='7.93' stroke='%23ff3344' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='12.5' cy='6' r='1.1' fill='%23ffaa00'/%3E%3C/svg%3E") center/65% no-repeat;
  filter: drop-shadow(0 0 7px #ff3344);
}
.celda.mina-exploded::after { filter: drop-shadow(0 0 12px #ff3344) brightness(1.4); }

/* ---- WRONG FLAG (mine was elsewhere) ---- */
.celda.wrong-flag {
  background: rgba(255,0,0,0.18) !important;
  border-color: #ff3344 !important;
}

/* ---- CHORD HIGHLIGHT (when hovering a revealed number) ---- */
.celda.revealed.chord-hover {
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15);
  cursor: pointer;
}

/* ============================================================
   WIN / LOSE OVERLAY
   ============================================================ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,20,0.82);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  animation: fadeIn 0.3s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem 3rem;
  text-align: center;
  max-width: 360px; width: 92%;
  animation: slideUp 0.32s cubic-bezier(.34,1.56,.64,1) both;
  position: relative; overflow: hidden;
}
@keyframes slideUp {
  from { transform: translateY(28px) scale(0.94); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.overlay.win  .overlay-content { border-color: rgba(0,255,136,0.4); box-shadow: 0 0 50px rgba(0,255,136,0.12); }
.overlay.lose .overlay-content { border-color: rgba(255,50,50,0.4);  box-shadow: 0 0 50px rgba(255,50,50,0.12);  }

.overlay-icon { font-size: 3.2rem; margin-bottom: 0.4rem; line-height: 1; }

#overlay-title {
  font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}
.overlay.win  #overlay-title { color: var(--green); text-shadow: 0 0 24px var(--green); }
.overlay.lose #overlay-title { color: var(--red);   text-shadow: 0 0 24px var(--red);   }

#overlay-message { color: var(--text-dim); margin-bottom: 0.5rem; font-size: 0.9rem; }

.overlay-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.6rem; font-weight: 700;
  color: var(--blue);
  margin-bottom: 0.75rem;
}

.new-record {
  display: inline-block;
  background: rgba(255,215,0,0.12);
  border: 1px solid rgba(255,215,0,0.4);
  border-radius: 20px; padding: 0.2rem 0.9rem;
  font-size: 0.82rem; color: var(--gold);
  margin-bottom: 1.2rem;
  animation: pulse 1.1s ease infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0   rgba(255,215,0,0.4); }
  50%      { box-shadow: 0 0 0 7px rgba(255,215,0,0);   }
}

.btn-primary {
  display: inline-block;
  background: linear-gradient(135deg, #0055ff, #00aaff);
  color: #fff; border: none; border-radius: 10px;
  padding: 0.72rem 2rem; font-size: 0.95rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 18px rgba(0,100,255,0.28);
  font-family: inherit;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 7px 22px rgba(0,100,255,0.4); }
.btn-primary:active { transform: translateY(0); }

/* ============================================================
   REGISTRATION MODAL
   ============================================================ */
.modal {
  position: fixed; inset: 0; z-index: 600;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,20,0.78);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-hi);
  border-radius: 20px; padding: 2rem 2.2rem;
  max-width: 400px; width: 92%;
  animation: slideUp 0.28s cubic-bezier(.34,1.56,.64,1) both;
}
.modal-close {
  position: absolute; top: 1rem; right: 1.1rem;
  background: none; border: none;
  color: var(--text-dim); font-size: 1.4rem;
  line-height: 1; cursor: pointer; transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }
.modal-content h2 { font-size: 1.35rem; font-weight: 700; margin-bottom: 0.2rem; }
.modal-subtitle { color: var(--text-dim); font-size: 0.82rem; margin-bottom: 1.4rem; }

.form-group { margin-bottom: 0.95rem; }
.form-group label {
  display: block; font-size: 0.73rem; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 0.38rem;
}
.form-group input {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 0.62rem 0.88rem;
  color: var(--text); font-size: 0.92rem; font-family: inherit;
  outline: none; transition: border-color 0.18s;
}
.form-group input:focus { border-color: var(--blue); }
.form-group input::placeholder { color: var(--text-dim); opacity: 0.45; }
.form-error {
  display: block; color: var(--red); font-size: 0.74rem;
  margin-top: 0.28rem; min-height: 1em;
}

.form-actions { display: flex; gap: 0.7rem; margin-top: 1.4rem; }
.form-actions .btn-primary { flex: 1; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-dim);
  padding: 0.72rem 1rem; font-size: 0.92rem; font-weight: 500;
  cursor: pointer; transition: all 0.18s; font-family: inherit;
}
.btn-ghost:hover { border-color: var(--border-hi); color: var(--text); }

/* ============================================================
   LEADERBOARD
   ============================================================ */
.leaderboard {
  padding: 1.5rem 1rem 2rem; max-width: 480px; margin: 0 auto;
  position: relative; z-index: 1;
}
.leaderboard-inner {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.4rem 1.6rem;
}
.leaderboard-inner h3 {
  font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); margin-bottom: 0.9rem;
}

.lb-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.lb-tab {
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-dim);
  padding: 0.26rem 0.75rem; font-size: 0.77rem; cursor: pointer;
  transition: all 0.18s; font-family: inherit;
}
.lb-tab.active { background: rgba(0,191,255,0.1); border-color: var(--blue); color: var(--blue); }
.lb-tab:hover:not(.active) { color: var(--text); }

.lb-list { list-style: none; }
.lb-list li {
  display: flex; align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border); gap: 0.7rem;
}
.lb-list li:last-child { border-bottom: none; }
.lb-rank {
  width: 22px; height: 22px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px; font-size: 0.72rem; font-weight: 700;
  background: var(--bg2); color: var(--text-dim);
}
.lb-rank.rank-1 { background: rgba(255,215,0,0.15);   color: var(--gold);    }
.lb-rank.rank-2 { background: rgba(192,192,192,0.12); color: #c0c0c0;        }
.lb-rank.rank-3 { background: rgba(205,127,50,0.12);  color: #cd7f32;        }
.lb-name { flex: 1; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { font-family: 'JetBrains Mono', monospace; font-size: 0.88rem; color: var(--blue); }
.lb-empty { color: var(--text-dim); font-size: 0.84rem; text-align: center; padding: 1rem 0; }

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  text-align: center; padding: 1.2rem 1rem;
  color: var(--text-dim); font-size: 0.82rem;
  border-top: 1px solid var(--border);
  position: relative; z-index: 1;
}
.footer a { color: var(--blue); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ============================================================
   UTILITY
   ============================================================ */
.hidden { display: none !important; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  .header-inner { height: 50px; }
  .logo span { display: none; }
  .hud-best { display: none; }   /* hide best-time on small screens */
  .hud { gap: 0.3rem; }
  .hud-item { padding: 0.22rem 0.48rem; gap: 0.28rem; }
  .hud-value { font-size: 0.82rem; }
  .difficulty-bar { gap: 0.3rem; padding: 0.5rem 0.6rem; }
  .diff-btn { padding: 0.32rem 0.55rem; font-size: 0.75rem; }
  .main { padding: 0.5rem 0.5rem 1rem; }
  .overlay-content { padding: 2rem 1.5rem; }
}

@media (max-width: 380px) {
  .hud-item:last-of-type { display: none; }
}
