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

:root {
  --bg-0: #0a0a12;
  --bg-1: #14141f;
  --bg-2: #1d1d2e;
  --fg: #f2f2f7;
  --muted: #8a8aa3;
  --accent: #ff3d68;
  --accent-2: #00e5ff;
  --good: #36e07f;
  --bad: #ff4f6d;

  --c-red:    #ff4f6d;
  --c-blue:   #3da9fc;
  --c-yellow: #ffd166;
  --c-green:  #36e07f;
  --c-purple: #b06bff;
  --c-orange: #ff9143;
  --c-pink:   #ff6fae;
  --c-cyan:   #2ee5d0;
  --c-lime:   #c6ff5e;

  --radius: 18px;
  --shadow: 0 8px 24px rgba(0,0,0,0.45);
  --gap: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #1a1a2e 0%, var(--bg-0) 60%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bot) + 12px);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================== SCREENS ===================== */
.screen {
  display: none;
  width: 100%;
  max-width: 520px;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  animation: fadeIn .35s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================== MENU ===================== */
.logo { text-align: center; margin-top: 8px; }
.logo h1 {
  font-size: clamp(2.2rem, 8vw, 3rem);
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 24px rgba(255, 61, 104, 0.25);
}
.logo .accent {
  background: linear-gradient(135deg, var(--accent-2), #7af0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 4px;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.best-score {
  background: var(--bg-1);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.06);
}
.best-score strong { color: var(--fg); margin-left: 4px; }

.modes { width: 100%; text-align: center; }
.modes h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 10px;
}
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
.mode-btn {
  background: var(--bg-1);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 14px 8px;
  color: var(--fg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform .15s, border-color .15s, background .15s;
  font-family: inherit;
}
.mode-btn:active { transform: scale(0.97); }
.mode-btn.selected {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(255,61,104,0.12), rgba(0,229,255,0.08));
}
.mode-icon { font-size: 1.8rem; }
.mode-name { font-weight: 700; font-size: 1rem; }
.mode-desc { font-size: 0.72rem; color: var(--muted); }

.btn-primary {
  width: 100%;
  padding: 18px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #ff7a4e);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow), 0 0 0 0 var(--accent);
  transition: transform .15s, box-shadow .25s;
  font-family: inherit;
}
.btn-primary:active { transform: scale(0.97); }

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--fg);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.btn-ghost:active { background: rgba(255,255,255,0.05); }

.btn-icon {
  background: var(--bg-1);
  border: none;
  color: var(--fg);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}
.btn-icon.muted { opacity: 0.4; }

.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
}
.credit { font-size: 0.75rem; color: var(--muted); }

/* ===================== GAME ===================== */
.hud {
  display: flex;
  justify-content: space-around;
  width: 100%;
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: 10px;
}
.hud-item { text-align: center; }
.hud-label {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.hud-value {
  display: block;
  font-weight: 800;
  font-size: 1.1rem;
  margin-top: 2px;
}

.status {
  text-align: center;
  width: 100%;
}
#status-text {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  min-height: 24px;
}
#status-text.good { color: var(--good); }
#status-text.bad  { color: var(--bad); }

#timer-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-2);
  border-radius: 3px;
  overflow: hidden;
}
#timer-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.1s linear;
}

.board {
  display: grid;
  gap: var(--gap);
  width: min(100%, 420px);
  aspect-ratio: 1 / 1;
}
.board.grid-2 { grid-template: repeat(2, 1fr) / repeat(2, 1fr); }
.board.grid-3 { grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.board.grid-4 { grid-template: repeat(4, 1fr) / repeat(4, 1fr); }

.tile {
  border-radius: var(--radius);
  background: var(--bg-1);
  cursor: pointer;
  transition: transform .1s, filter .15s, box-shadow .15s;
  position: relative;
  overflow: hidden;
  border: none;
  font-family: inherit;
}
.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--tile-color, var(--bg-2));
  opacity: 0.35;
  transition: opacity .2s;
}
.tile.active::before,
.tile.flash::before { opacity: 1; }
.tile.flash {
  box-shadow: 0 0 30px var(--tile-color), inset 0 0 20px rgba(255,255,255,0.3);
  transform: scale(1.04);
}
.tile.correct {
  animation: pulseGood .35s ease;
}
.tile.wrong {
  animation: shake .4s ease;
  box-shadow: 0 0 24px var(--bad);
}
.tile.locked { pointer-events: none; }

@keyframes pulseGood {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); box-shadow: 0 0 30px var(--good); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ===================== GAME OVER ===================== */
.gameover-title {
  font-size: 2rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.result-card {
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
}
.result-row strong { font-size: 1.6rem; color: var(--accent-2); }
.result-row.recorde {
  justify-content: center;
  color: var(--c-yellow);
  font-weight: 800;
  letter-spacing: 2px;
  animation: pulseGood 1s ease infinite;
}

/* ===================== RESPONSIVE ===================== */
@media (max-height: 640px) {
  .logo h1 { font-size: 2rem; }
  .mode-btn { padding: 10px 6px; }
  .mode-icon { font-size: 1.4rem; }
  .mode-desc { display: none; }
  .btn-primary { padding: 14px; font-size: 1.1rem; }
}
