:root {
  --bg1: #0e1330;
  --bg2: #1f2d6b;
  --surface: rgba(255, 255, 255, 0.08);
  --surface-hi: rgba(255, 255, 255, 0.16);
  --border: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --accent: #ffc83d;
  --accent-2: #5ad1ff;
  --good: #2fcf73;
  --bad: #ff5866;
  --radius: 16px;
  --fs: clamp(14px, 2.4vmin, 22px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg1);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--fs);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg2), var(--bg1));
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Pausa de Playables: congela todas las animaciones CSS */
body.paused *, body.paused *::before, body.paused *::after {
  animation-play-state: paused !important;
  transition: none !important;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}
button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(16px, 3vmin);
  overflow-y: auto;
}
.screen[hidden] { display: none; }

/* ---------- Loading ---------- */
.loader {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid var(--surface-hi);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Home ---------- */
.home {
  width: min(100%, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.2vmin, 18px);
  text-align: center;
  margin: auto 0;
}
.logo { display: flex; gap: 10px; height: clamp(34px, 8vmin, 64px); }
.logo img {
  height: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  animation: float 3s ease-in-out infinite;
}
.logo img:nth-child(1) { transform: rotate(-8deg); animation-delay: 0s; }
.logo img:nth-child(2) { animation-delay: 0.4s; }
.logo img:nth-child(3) { transform: rotate(8deg); animation-delay: 0.8s; }
@keyframes float { 50% { translate: 0 -6px; } }

h1 {
  margin: 0;
  font-size: clamp(34px, 8vmin, 64px);
  letter-spacing: -0.02em;
  line-height: 1;
}
h1, h2 { text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.tagline { margin: 0; color: var(--muted); }

.modes { display: grid; grid-auto-rows: 1fr; gap: 12px; width: 100%; }
.mode-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: clamp(12px, 2.4vmin, 20px) clamp(16px, 3vmin, 24px);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #ff9f43, #ff5e62);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  text-align: left;
  transition: transform 0.1s;
}
.mode-card.alt { background: linear-gradient(135deg, #36d1dc, #5b86e5); }
.mode-card.danger { background: linear-gradient(135deg, #b06ab3, #4568dc); }
.mode-card.continue { background: linear-gradient(135deg, #43e97b, #1fa2a0); }
.mode-card[hidden] { display: none; }
.mode-card:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.mode-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mode-name { font-weight: 800; font-size: 1.3em; }
.mode-desc { opacity: 0.92; }
.mode-best {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 4.2em;
  justify-content: center;
  padding: 0.35em 0.75em;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.mode-best .icon { width: 18px; height: 18px; color: #ffe27a; }

.pill {
  padding: 0.65em 1.4em;
  border-radius: 999px;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  font-weight: 700;
}
.pill.primary { background: var(--accent); color: #2a1d00; border-color: transparent; }
.pill.small { padding: 0.45em 1em; font-size: 0.9em; }
.pill:active { transform: scale(0.97); }

.toggles { display: flex; gap: 14px; justify-content: center; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn[aria-pressed="true"] { background: rgba(90, 209, 255, 0.2); border-color: var(--accent-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.small { width: 44px; height: 44px; background: var(--surface-hi); color: var(--text); }
.icon-btn.small .icon { width: 22px; height: 22px; }
.icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) {
  .mode-card:hover { filter: brightness(1.08); }
  .pill:hover,
  .icon-btn:not([aria-pressed="true"]):hover,
  .tab:not([aria-selected="true"]):hover { background-color: rgba(255, 255, 255, 0.24); }
  .icon-btn[aria-pressed="true"]:hover { background: rgba(90, 209, 255, 0.32); }
  .pill.primary:hover { background: #ffd666; }
  .option:not(:disabled):hover { background: rgba(255, 255, 255, 0.24); border-color: rgba(255, 255, 255, 0.4); }
}

@media (min-aspect-ratio: 3 / 2) and (max-height: 640px) {
  .home { width: min(100%, 860px); }
  .modes { grid-auto-flow: column; grid-auto-columns: 1fr; }
  .mode-card { flex-direction: column; align-items: flex-start; justify-content: space-between; }
}

/* ---------- Game ---------- */
.screen.game { justify-content: flex-start; gap: clamp(8px, 1.6vmin, 14px); overflow: hidden; }
.hud {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}
.hud > :first-child { justify-self: start; }
.hud-mid { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
#hud-mode { font-weight: 800; }
#hud-progress { color: var(--muted); font-size: 0.9em; }
.hud-score { justify-self: end; display: flex; align-items: baseline; gap: 4px; }
#hud-score { font-size: 1.6em; font-weight: 800; color: var(--accent); }
.hud-label { color: var(--muted); font-size: 0.85em; }

.timer {
  position: relative;
  width: 100%;
  height: clamp(16px, 2.6vmin, 22px);
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}
.timer-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--good), #a8e063);
  border-radius: 999px;
}
.timer-fill.low { background: linear-gradient(90deg, var(--bad), #ff9966); }
.timer-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.75em;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.play {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2vmin, 18px);
}
.flag-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.flag-card {
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
  transition: opacity 0.15s;
}
.flag-card.loading { opacity: 0; }
.flag-card img { display: block; width: 100%; height: 100%; }
.flag-card.pop { animation: pop 0.5s cubic-bezier(.2, 1.6, .4, 1); }
.flag-card.shake { animation: shake 0.45s; }
@keyframes pop { 40% { transform: scale(1.08) rotate(-2deg); } }
@keyframes shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

.feedback {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  padding: 0.5em 1.1em;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.1em;
  white-space: nowrap;
  max-width: 96%;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
}
.feedback.show { animation: badge-in 0.35s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.feedback.good { background: var(--good); color: #062612; }
.feedback.bad { background: var(--bad); color: #2b0005; }
@keyframes badge-in {
  from { opacity: 0; transform: translateY(12px) scale(0.8); }
  to { opacity: 1; transform: none; }
}

.streak {
  position: absolute;
  translate: 0 -50%;
  padding: 0.3em 0.8em;
  border-radius: 999px;
  background: var(--accent);
  color: #2a1d00;
  font-weight: 800;
  font-size: 0.85em;
}
.streak:empty { display: none; }

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1.6vmin, 14px);
  flex: 0 0 auto;
}
.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-height: clamp(54px, 9vmin, 76px);
  padding: 0.5em 0.9em;
  border-radius: 14px;
  background: var(--surface-hi);
  border: 2px solid var(--border);
  font-weight: 700;
  text-align: left;
  line-height: 1.15;
  transition: background 0.15s, border-color 0.15s, opacity 0.2s, transform 0.1s;
}
.option:active { transform: scale(0.98); }
.option .key {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 1.7em;
  height: 1.7em;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.8em;
  color: var(--muted);
}
.option.correct { background: var(--good); border-color: #b9ffd5; color: #062612; animation: pop 0.45s cubic-bezier(.2, 1.6, .4, 1); }
.option.wrong { background: var(--bad); border-color: #ffc2c8; color: #2b0005; animation: shake 0.4s; }
.option.dim { opacity: 0.4; }
.option:disabled { cursor: default; }

/* Pantallas anchas: bandera a la izquierda, opciones a la derecha */
@media (min-aspect-ratio: 5 / 4) {
  .play { flex-direction: row; align-items: stretch; }
  .flag-wrap { flex: 1.3 1 0; }
  .options { flex: 1 1 0; grid-template-columns: 1fr; align-content: center; }
}

/* ---------- Result & scores ---------- */
.panel {
  width: min(100%, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vmin, 16px);
  padding: clamp(18px, 4vmin, 32px);
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  margin: auto 0;
}
h2 { margin: 0; font-size: clamp(22px, 4.6vmin, 36px); }
.big-score {
  font-size: clamp(56px, 14vmin, 110px);
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
  animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1);
}
.badge {
  padding: 0.35em 1em;
  border-radius: 999px;
  background: var(--good);
  color: #062612;
  font-weight: 800;
  animation: badge-in 0.4s 0.2s both;
}
.badge[hidden] { display: none; }
.result-line { margin: 0; font-weight: 700; }
.result-note { margin: 0; color: var(--muted); }
.result-note:empty { display: none; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.tabs { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: rgba(0, 0, 0, 0.25); }
.tab { padding: 0.5em 0.9em; border-radius: 999px; font-weight: 700; font-size: 0.92em; white-space: nowrap; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--accent); color: #2a1d00; }

.board { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.board li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0.55em 0.9em;
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
}
.board li.top { background: rgba(255, 200, 61, 0.18); }
.board .rank { font-weight: 900; color: var(--accent); }
.board .meta { color: var(--muted); font-size: 0.85em; }
.board .pts { font-weight: 800; font-size: 1.15em; }
.board .empty { grid-template-columns: 1fr; text-align: center; color: var(--muted); }
.board-note { margin: 0; color: var(--muted); font-size: 0.85em; }
