/* ================================================================
   BUSCA-RITMES · Game — AAA Edition
   ================================================================ */

:root {
  --bg:          #04040b;
  --surface:     rgba(255,255,255,0.036);
  --border:      rgba(255,255,255,0.075);
  --cell-off:    #111120;
  --cell-hov:    #1a1a2e;
  --cell-on:     #08080e;
  --cell-emp:    #050508;
  --n1: #d4a017; --n2: #3d8ef0; --n3: #28c87a; --n4: #c0334d;
  --mine: #ff4444; --flag: #f5c542;
  --txt:  #eeeef8; --dim:  #4a4a72; --acc:  #6650f0;
  --lvl-accent:  #6650f0;  /* sobreescrit per game.js */
  --cell: 54px; --cols: 8; --rows: 8; --gap: 3px;
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 55% at 10% 10%, rgba(102,80,240,.14) 0%, transparent 52%),
    radial-gradient(ellipse 55% 45% at 90% 90%, rgba(61,142,240,.10) 0%, transparent 52%);
  display: flex; align-items: center; justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  color: var(--txt);
  user-select: none; -webkit-user-select: none;
  padding: 24px 12px;
}

body::before {
  content: ''; position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.016) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.016) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none; z-index: 0;
}

.container { position:relative; z-index:1; display:flex; flex-direction:column; align-items:center; gap:14px; }

/* ── Header ──────────────────────────────────────────────── */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  width: calc(var(--cell) * var(--cols) + var(--gap) * (var(--cols) - 1) + 16px);
}
.game-header-center { text-align: center; }
.game-header h1 {
  font-size: clamp(1.2rem, 3vw, 1.6rem); font-weight: 800; letter-spacing: -.03em;
  background: linear-gradient(135deg, #fff 0%, var(--lvl-accent, #a8b8ff) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.level-tempo {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: .6rem; font-weight: 600; color: var(--dim); letter-spacing: .1em; margin-top: 2px;
}
.back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--txt); text-decoration: none; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s; flex-shrink: 0;
}
.back-btn:hover { background: rgba(255,255,255,.10); transform: scale(1.08); }

/* ── HUD ─────────────────────────────────────────────────── */
.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: calc(var(--cell) * var(--cols) + var(--gap) * (var(--cols) - 1) + 16px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 10px 20px;
  backdrop-filter: blur(28px); -webkit-backdrop-filter: blur(28px);
  box-shadow: 0 4px 28px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.025) inset;
}
.counter { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 68px; }
.counter-label { font-size: .55rem; text-transform: uppercase; letter-spacing: .16em; color: var(--dim); }
.counter-value {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 1.55rem; font-weight: 700;
  color: #ff6060; text-shadow: 0 0 14px rgba(255,80,80,.5); letter-spacing: .04em;
  transition: transform .1s;
}
.counter-value.counter-flash { animation: counterFlash .25s ease-out; }
@keyframes counterFlash {
  0%   { transform: scale(1.25); color: #fff; }
  100% { transform: scale(1); }
}
.timer-val { color: #4ea8f5; text-shadow: 0 0 14px rgba(78,168,245,.5); }

.hud-btns { display: flex; gap: 8px; }
#reset-btn, #mute-btn, #flag-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 50%;
  width: 40px; height: 40px; font-size: 1.1rem; color: var(--txt);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .22s, border-color .15s, box-shadow .15s; flex-shrink: 0;
}
#reset-btn:hover  { background: rgba(255,255,255,.10); transform: rotate(160deg) scale(1.1); }
#reset-btn:active { transform: rotate(160deg) scale(.93); }
#mute-btn:hover   { background: rgba(255,255,255,.10); transform: scale(1.1); }
#mute-btn:active  { transform: scale(.92); }
#flag-btn:hover   { background: rgba(255,255,255,.10); transform: scale(1.1); }
#flag-btn:active  { transform: scale(.92); }
/* Mode batuta actiu: el botó s'il·lumina amb l'accent del nivell */
#flag-btn.active {
  border-color: var(--lvl-accent, #d4a017);
  background: color-mix(in srgb, var(--lvl-accent, #d4a017) 22%, transparent);
  box-shadow: 0 0 0 2px var(--lvl-accent, #d4a017) inset, 0 0 14px var(--glow, rgba(212,160,23,.45));
}
/* En mode batuta, el cursor sobre les caselles insinua "marcar" */
body.flag-mode .cell.c-hidden { cursor: cell; }

/* ── Board ───────────────────────────────────────────────── */
#board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows:    repeat(var(--rows), var(--cell));
  gap: var(--gap);
  padding: 8px;
  background: rgba(0,0,0,.4);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.025) inset,
    0 16px 70px rgba(0,0,0,.6),
    0 0 60px rgba(102,80,240,.04);
  transition: box-shadow .5s ease;
}

/* Entrada en cada reset */
.board-enter {
  animation: boardEnter .42s cubic-bezier(.16,1,.3,1);
}
@keyframes boardEnter {
  from { opacity:.2; transform: scale(.93) translateY(8px); }
  to   { opacity:1;  transform: scale(1)   translateY(0); }
}

/* Estats de joc */
#board.state-won {
  box-shadow:
    0 0 0 2px #28c87a,
    0 0 0 1px rgba(255,255,255,.025) inset,
    0 0 60px rgba(40,200,122,.3),
    0 16px 70px rgba(0,0,0,.6);
  animation: boardWinGlow 1.2s ease-in-out infinite alternate;
}
@keyframes boardWinGlow {
  from { box-shadow: 0 0 0 2px #28c87a, 0 0 40px rgba(40,200,122,.2), 0 16px 70px rgba(0,0,0,.6); }
  to   { box-shadow: 0 0 0 2px #28c87a, 0 0 80px rgba(40,200,122,.4), 0 16px 70px rgba(0,0,0,.6); }
}

#board.state-lost {
  box-shadow:
    0 0 0 2px #ff4444,
    0 0 0 1px rgba(255,255,255,.025) inset,
    0 0 60px rgba(255,68,68,.25),
    0 16px 70px rgba(0,0,0,.6);
}

/* Screen shake */
#board.shake { animation: boardShake .55s cubic-bezier(.36,.07,.19,.97); }
@keyframes boardShake {
  0%,100% { transform: translateX(0) rotate(0); }
  10%     { transform: translateX(-9px) rotate(-.8deg); }
  20%     { transform: translateX(9px)  rotate(.8deg); }
  30%     { transform: translateX(-7px) rotate(-.5deg); }
  40%     { transform: translateX(7px)  rotate(.5deg); }
  55%     { transform: translateX(-4px); }
  70%     { transform: translateX(4px); }
  85%     { transform: translateX(-2px); }
}

/* ── Cell ────────────────────────────────────────────────── */
.cell {
  width: var(--cell); height: var(--cell);
  background: linear-gradient(160deg, #151524 0%, #0e0e1c 100%);
  border: 1px solid rgba(255,255,255,.06);
  border-bottom-color: rgba(0,0,0,.4);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .08s, border-color .08s;
  will-change: transform;
  position: relative;
}

/* Hidden: efecte 3D lleugero (bordes lluminosos dalt i esquerra) */
.cell.c-hidden {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.07),
    inset -1px 0 0 rgba(0,0,0,.2);
}
.cell.c-hidden:hover {
  background: linear-gradient(160deg, #1e1e34 0%, #16162a 100%);
  border-color: rgba(255,255,255,.14);
  border-bottom-color: rgba(0,0,0,.5);
  transform: scale(1.08) translateY(-1px);
  box-shadow:
    0 4px 16px rgba(0,0,0,.5),
    inset 0 1px 0 rgba(255,255,255,.12),
    0 0 10px rgba(102,80,240,.12);
  z-index: 2;
}
.cell.c-hidden:active { transform: scale(.92) translateY(1px); box-shadow: none; }

/* Revealed empty (sunken look) */
.cell.c-empty {
  background: var(--cell-emp);
  border-color: rgba(255,255,255,.025);
  border-top-color: rgba(0,0,0,.4);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.5);
  cursor: default;
  animation: revealEmpty .18s ease-out;
}
@keyframes revealEmpty {
  from { opacity:.4; transform: scale(.85); }
  to   { opacity:1;  transform: scale(1); }
}

/* Revealed with note */
.cell.c-note {
  background: var(--cell-on);
  border-color: rgba(255,255,255,.04);
  border-top-color: transparent;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.4);
  cursor: default;
  animation: revealNote .24s cubic-bezier(.16,1,.3,1);
}
@keyframes revealNote {
  from { opacity:.15; transform: scale(.6) rotate(-3deg); }
  to   { opacity:1;   transform: scale(1)  rotate(0); }
}

/* Colored top accent per nota */
.cell.l1 { color: var(--n1); border-top: 2px solid rgba(212,160,23,.5); text-shadow: 0 0 12px rgba(212,160,23,.4); }
.cell.l2 { color: var(--n2); border-top: 2px solid rgba(61,142,240,.5); text-shadow: 0 0 12px rgba(61,142,240,.4); }
.cell.l3 { color: var(--n3); border-top: 2px solid rgba(40,200,122,.5); text-shadow: 0 0 12px rgba(40,200,122,.4); }
.cell.l4 { color: var(--n4); border-top: 2px solid rgba(192,51,77,.6); text-shadow: 0 0 12px rgba(192,51,77,.45); }

/* Flag */
.cell.c-flag {
  background: rgba(245,197,66,.07);
  border-color: rgba(245,197,66,.2);
  font-size: 1.1rem;
  animation: flagDrop .2s cubic-bezier(.16,1,.3,1);
  box-shadow: 0 0 12px rgba(245,197,66,.15) inset;
}
@keyframes flagDrop {
  from { transform: scale(.5) rotate(-20deg); opacity:.3; }
  to   { transform: scale(1)  rotate(0);      opacity:1; }
}

/* Mine */
.cell.c-mine {
  background: rgba(255,68,68,.1);
  border-color: rgba(255,68,68,.25);
  color: var(--mine); cursor: default;
  animation: mineReveal .25s cubic-bezier(.16,1,.3,1);
}
@keyframes mineReveal {
  from { transform: scale(.7); opacity:.2; }
  to   { transform: scale(1);  opacity:1; }
}
.cell.mine-pop {
  animation: minePop .35s cubic-bezier(.36,.07,.19,.97) !important;
  border-color: rgba(255,68,68,.6) !important;
}
@keyframes minePop {
  0%  { transform: scale(1); box-shadow: none; }
  30% { transform: scale(1.4); box-shadow: 0 0 20px rgba(255,50,50,.7); border-color: #ff4444; }
  60% { transform: scale(.95); }
  100%{ transform: scale(1); }
}

/* Mina clicada */
.cell.c-exploded {
  background: #1a0000 !important;
  border-color: rgba(255,50,50,.9) !important;
  color: var(--mine) !important;
  box-shadow: 0 0 30px rgba(255,50,50,.7) !important;
  animation: explode .45s cubic-bezier(.36,.07,.19,.97);
  cursor: default; z-index: 3;
}
@keyframes explode {
  0%  { transform: scale(1); }
  15% { transform: scale(1.6) rotate(-6deg); box-shadow: 0 0 50px rgba(255,50,50,.9) !important; }
  40% { transform: scale(1.3) rotate(4deg); }
  70% { transform: scale(1.05); }
  100%{ transform: scale(1); }
}

/* Bandera incorrecta */
.cell.c-wrong {
  background: rgba(192,51,77,.14);
  border-color: rgba(192,51,77,.3);
  color: var(--n4); cursor: default; font-size: .8rem;
}

/* Win pulse (onada de victòria) */
.cell.win-pulse {
  animation: winPulse .55s ease-out !important;
}
@keyframes winPulse {
  0%   { filter: brightness(1); }
  35%  { filter: brightness(2.2); }
  100% { filter: brightness(1); }
}

/* ── Legend ──────────────────────────────────────────────── */
.legend { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; }
.leg {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem; padding: 4px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
}
.leg.l1 { color: var(--n1); } .leg.l2 { color: var(--n2); }
.leg.l3 { color: var(--n3); } .leg.l4 { color: var(--n4); }
.leg.lflag { color: var(--flag); }

.hint { font-size: .62rem; color: var(--dim); letter-spacing: .04em; }

/* ── Modal ───────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: flex; align-items: center; justify-content: center;
  z-index: 800; animation: fadeIn .3s ease;
}
.modal.hidden { display: none; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-card {
  background: rgba(10,10,20,.98);
  border: 1px solid rgba(255,255,255,.08);
  border-top-color: rgba(255,255,255,.12);
  border-radius: 28px; padding: 46px 40px 36px;
  max-width: 400px; width: 92%; text-align: center;
  box-shadow: 0 0 0 1px rgba(255,255,255,.04) inset, 0 40px 120px rgba(0,0,0,.8);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  animation: modalIn .35s cubic-bezier(.16,1,.3,1);
}
@keyframes modalIn {
  from { transform: translateY(36px) scale(.95); opacity:0; }
  to   { transform: translateY(0) scale(1); opacity:1; }
}
.modal-icon { font-size: 3.2rem; line-height:1; animation: iconBounce .6s cubic-bezier(.16,1,.3,1); }
@keyframes iconBounce {
  from { transform: scale(0) rotate(-20deg); opacity:0; }
  60%  { transform: scale(1.3) rotate(5deg); }
  to   { transform: scale(1) rotate(0); opacity:1; }
}
.modal-card h2 {
  font-size: 1.8rem; font-weight: 800; letter-spacing: -.03em;
  background: linear-gradient(135deg, #fff 0%, #a8b8ff 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.modal-card p { color: var(--dim); font-size: .88rem; line-height: 1.65; }
.modal-time { font-family:"SF Mono",monospace; color:#4ea8f5 !important; font-size:.82rem !important; }
.modal-stars { display:flex; gap:5px; }
.modal-stars .star { font-size: 1.5rem; color: rgba(255,255,255,.12); }
.modal-stars .star.lit { color: #f5c542; filter: drop-shadow(0 0 8px rgba(245,197,66,.65)); animation: starPop .4s cubic-bezier(.16,1,.3,1) backwards; }
.modal-stars .star:nth-child(1).lit { animation-delay: .05s; }
.modal-stars .star:nth-child(2).lit { animation-delay: .15s; }
.modal-stars .star:nth-child(3).lit { animation-delay: .25s; }
@keyframes starPop {
  from { transform: scale(0) rotate(-30deg); }
  60%  { transform: scale(1.4) rotate(10deg); }
  to   { transform: scale(1) rotate(0); }
}

#modal-btn {
  background: linear-gradient(135deg, var(--acc), #3d8ef0);
  border: none; border-radius: 12px; padding: 13px 36px;
  color: #fff; font-size: 1rem; font-weight: 700; cursor: pointer;
  letter-spacing: .02em; width: 100%; margin-top: 4px;
  transition: transform .14s, box-shadow .14s;
}
#modal-btn:hover  { transform: scale(1.04); box-shadow: 0 8px 28px rgba(102,80,240,.5); }
#modal-btn:active { transform: scale(.96); }
.modal-back { font-size: .78rem; color: var(--dim); text-decoration: none; letter-spacing: .04em; }
.modal-back:hover { color: var(--txt); }

/* ── Tutorial ────────────────────────────────────────────── */
.tut-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.78);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 900;
}
.tut-overlay.hidden { display: none; }
.tut-hl {
  position: relative; z-index: 901; border-radius: 14px;
  box-shadow: 0 0 0 3px rgba(102,80,240,.9), 0 0 40px rgba(102,80,240,.35);
}
.tut-card {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  width: min(460px, 94vw);
  background: rgba(10,10,22,.98);
  border: 1px solid rgba(102,80,240,.35);
  border-top-color: rgba(102,80,240,.6);
  border-radius: 22px; padding: 26px 26px 20px; z-index: 902;
  box-shadow: 0 20px 80px rgba(0,0,0,.8), 0 0 0 1px rgba(102,80,240,.15);
  animation: modalIn .3s cubic-bezier(.16,1,.3,1);
}
.tut-card.hidden { display: none; }
.tut-step-dots { display:flex; justify-content:center; gap:6px; margin-bottom:14px; }
.tut-dot { width:6px; height:6px; border-radius:50%; background:rgba(255,255,255,.14); transition:background .25s,transform .25s; }
.tut-dot.active { background: var(--acc); transform: scale(1.4); }
.tut-dot.done   { background: rgba(102,80,240,.4); }
.tut-card h3 { font-size:1.05rem; font-weight:700; margin-bottom:8px;
  background:linear-gradient(135deg,#fff 0%,#c0c8ff 100%);
  -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }
.tut-body { font-size:.86rem; line-height:1.7; color:#7878a8; margin-bottom:12px; }
.tut-body strong { color: var(--txt); }
.tut-body ul { padding-left:18px; margin-top:5px; }
.tut-body li  { margin-bottom:3px; }
.tut-demo { display:flex; gap:8px; justify-content:center; align-items:center; flex-wrap:wrap; }
.tut-demo:not(:empty) { min-height:56px; margin-bottom:12px; }
.tut-demo-cell { width:48px; height:48px; border-radius:7px; display:flex; align-items:center; justify-content:center; border:1px solid rgba(255,255,255,.08); flex-direction:column; gap:2px; }
.tut-dc-hidden { background:#111120; } .tut-dc-note { background:#08080e; }
.tut-dc-empty  { background:#05050a; } .tut-dc-flag  { background:rgba(245,197,66,.09); color:var(--flag); border-color:rgba(245,197,66,.25); font-size:1.1rem; }
.tut-dc-mine   { background:rgba(255,68,68,.1); color:var(--mine); border-color:rgba(255,68,68,.25); }
.tut-demo-cell .note-label { font-size:.52rem; color:var(--dim); }
.tut-demo-cell.pulse { animation:tutPulse 1.2s ease-in-out infinite; }
@keyframes tutPulse { 0%,100%{box-shadow:0 0 0 0 rgba(102,80,240,0);} 50%{box-shadow:0 0 0 4px rgba(102,80,240,.55);} }
.tut-nav { display:flex; gap:8px; justify-content:flex-end; align-items:center; }
.tut-btn-sec,.tut-btn-pri { padding:9px 18px; border-radius:10px; font-size:.82rem; font-weight:600; cursor:pointer; transition:transform .12s,box-shadow .12s; border:none; }
.tut-btn-sec { background:transparent; color:var(--dim); border:1px solid var(--border); }
.tut-btn-sec:hover { color:var(--txt); border-color:rgba(255,255,255,.2); }
.tut-btn-pri { background:linear-gradient(135deg,var(--acc),#3d8ef0); color:#fff; }
.tut-btn-pri:hover  { transform:scale(1.04); box-shadow:0 4px 18px rgba(102,80,240,.4); }
.tut-btn-pri:active { transform:scale(.96); }
