@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=Inter:wght@300;400;500;600;700;800&display=swap');

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

:root {
  --bg0: #06060f;
  --bg1: #0c0c1e;
  --bg2: #13132a;
  --bg3: #1b1b38;
  --bg4: #242448;
  --border: rgba(255,255,255,0.07);
  --purple: #7c3aed;
  --purple-l: #a78bfa;
  --red: #ef4444;
  --gold: #d9a406;
  --green: #22c55e;
  --cyan: #22d3ee;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #4b5563;
  --ff-head: 'Cinzel', serif;
  --ff-ui: 'Inter', sans-serif;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 4px 24px rgba(0,0,0,0.6);
  /* tablero */
  --cell-bg: #10101f;
  --cell-given: #1c1c33;
  --line: rgba(167,139,250,0.18);
  --line-strong: rgba(167,139,250,0.55);
}

html, body { height: 100%; }
body {
  background: var(--bg0); color: var(--text);
  font-family: var(--ff-ui); font-size: 15px; line-height: 1.5; min-height: 100vh;
}

.zen-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(34,211,238,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(124,58,237,0.12) 0%, transparent 55%);
}

.top-bar {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(6,6,15,0.75); backdrop-filter: blur(8px);
}
.top-brand { color: var(--text2); text-decoration: none; font-weight: 600; font-size: 14px; }
.top-brand:hover { color: var(--text); }
.top-title { font-family: var(--ff-head); font-weight: 900; letter-spacing: 6px; font-size: 16px; color: var(--cyan); }

#app { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; padding: 18px 12px 60px; }

.loading { text-align: center; padding: 80px 0; color: var(--text2); }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border: 2px solid var(--purple);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; color: var(--purple-l);
  animation: girar 1.6s ease-in-out infinite;
}
@keyframes girar { 50% { transform: rotate(180deg); border-color: var(--cyan); } 100% { transform: rotate(360deg); } }

#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 22px; border-radius: 30px; font-size: 14px; opacity: 0;
  transition: all .25s; z-index: 100; pointer-events: none; box-shadow: var(--shadow); max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--red); color: #fca5a5; }
#toast.xp { border-color: var(--gold); color: #fde68a; }

button {
  font-family: var(--ff-ui); font-size: 14px; font-weight: 600;
  border: none; border-radius: var(--r); cursor: pointer; transition: all .18s; color: var(--text);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  padding: 13px 26px; width: 100%; box-shadow: 0 4px 18px rgba(34,211,238,0.25);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-secondary { background: var(--bg3); border: 1px solid var(--border); padding: 11px 20px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 8px 14px; font-size: 13px; }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--cyan); }

/* ─── Landing ─── */
.landing-hero { text-align: center; padding: 30px 0 20px; }
.landing-hero h1 {
  font-family: var(--ff-head); font-size: clamp(34px, 7vw, 50px); font-weight: 900; letter-spacing: 5px;
  background: linear-gradient(100deg, var(--cyan) 20%, var(--purple-l) 80%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.landing-hero .tagline { color: var(--text2); font-size: 15.5px; margin-top: 4px; }

.nivel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-top: 18px; }
.nivel-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 16px; text-align: center; cursor: pointer;
  transition: border-color .2s, transform .2s;
}
.nivel-card:hover { border-color: var(--cyan); transform: translateY(-3px); }
.nivel-card .ni { font-size: 30px; }
.nivel-card .nn { font-family: var(--ff-head); letter-spacing: 1px; font-weight: 700; margin: 6px 0 2px; }
.nivel-card .nx { color: var(--gold); font-size: 13px; font-weight: 700; }
.nivel-card .nd { color: var(--text3); font-size: 11.5px; margin-top: 3px; }

.resume-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(34,211,238,0.07); border: 1px solid rgba(34,211,238,0.35);
  border-radius: var(--r-lg); padding: 14px 18px; margin-top: 16px;
}
.hint-note { color: var(--text3); font-size: 12.5px; text-align: center; margin-top: 16px; }

/* ─── Juego ─── */
.game-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.game-head .gh-nivel { font-family: var(--ff-head); letter-spacing: 2px; font-weight: 700; color: var(--purple-l); }
.game-head .gh-timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text2); }
.game-head .gh-right { margin-left: auto; display: flex; gap: 8px; }

.board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  width: 100%; max-width: 520px; margin: 0 auto; aspect-ratio: 1;
  border: 2px solid var(--line-strong); border-radius: 10px; overflow: hidden;
  background: var(--cell-bg);
  user-select: none; -webkit-user-select: none;
}
.sd-cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  font-size: clamp(16px, 4.2vw, 26px); font-weight: 600; cursor: pointer;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  color: var(--cyan);
}
.sd-cell:nth-child(9n) { border-right: none; }
.sd-cell.b-right { border-right: 2px solid var(--line-strong); }
.sd-cell.b-bottom { border-bottom: 2px solid var(--line-strong); }
.sd-cell.given { background: var(--cell-given); color: var(--text); font-weight: 700; }
.sd-cell.sel { background: rgba(124,58,237,0.35) !important; }
.sd-cell.peer { background: rgba(124,58,237,0.10); }
.sd-cell.same { background: rgba(34,211,238,0.16); }
.sd-cell.conflict { color: #fca5a5 !important; }
.sd-cell.conflict::after {
  content: ''; position: absolute; inset: 8%; border-radius: 50%;
  border: 2px solid rgba(239,68,68,0.45); pointer-events: none;
}
.sd-cell.hinted { color: var(--gold); }
.sd-cell.flash { animation: cell-flash .6s; }
@keyframes cell-flash { 0% { background: rgba(217,164,6,0.6); } }
.sd-cell .notes {
  position: absolute; inset: 1px; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: clamp(7px, 1.7vw, 10px); color: var(--text3); font-weight: 600;
  pointer-events: none; line-height: 1;
}
.sd-cell .notes span { display: flex; align-items: center; justify-content: center; }

/* ─── Controles ─── */
.controls { max-width: 520px; margin: 14px auto 0; }
.numpad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.numpad button {
  aspect-ratio: 1; font-size: 20px; font-weight: 700;
  background: var(--bg3); border: 1px solid var(--border);
}
.numpad button:hover:not(:disabled) { border-color: var(--cyan); background: var(--bg4); }
.numpad button .cnt { display: block; font-size: 9px; color: var(--text3); font-weight: 600; }
.numpad button.agotado { opacity: 0.3; }
.action-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.action-row button { flex: 1; padding: 10px 8px; font-size: 13px; background: var(--bg3); border: 1px solid var(--border); }
.action-row button.on { border-color: var(--cyan); background: rgba(34,211,238,0.15); }
.action-row .btn-pista { border-color: rgba(217,164,6,0.5); color: #fde68a; }
.action-row .btn-pista:hover:not(:disabled) { background: rgba(217,164,6,0.15); }

.xp-info {
  max-width: 520px; margin: 12px auto 0; text-align: center;
  color: var(--text3); font-size: 12.5px;
}
.xp-info b { color: var(--gold); }

/* ─── Fin ─── */
.win-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(6,6,15,0.8); backdrop-filter: blur(3px); animation: fade-in .3s;
}
@keyframes fade-in { from { opacity: 0; } }
.win-card {
  background: var(--bg2); border: 1px solid rgba(34,197,94,0.5); border-radius: var(--r-lg);
  padding: 28px 34px; text-align: center; box-shadow: 0 0 60px rgba(34,197,94,0.15), var(--shadow);
  animation: pop-in .35s cubic-bezier(.2, 1.5, .4, 1); max-width: 92vw;
}
@keyframes pop-in { from { transform: scale(0.75); opacity: 0; } }
.win-card h2 { font-family: var(--ff-head); letter-spacing: 2px; margin-bottom: 6px; }
.win-card .wc-tiempo { color: var(--text2); font-size: 14px; }
.win-card .wc-xp { font-size: 17px; margin: 14px 0; line-height: 1.7; }
.win-card .wc-xp .mas { color: var(--green); font-weight: 800; }
.win-card .wc-xp .menos { color: #fca5a5; font-weight: 700; }
.win-card .wc-xp .neto { color: var(--gold); font-weight: 800; font-size: 22px; }
.win-card .wc-guest { color: var(--text2); font-size: 13px; margin: 10px 0; }
.win-card .end-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 8px; }

@media (max-width: 560px) {
  #app { padding: 12px 8px 40px; }
  .top-title { letter-spacing: 3px; font-size: 14px; }
}
