* {
  touch-action: manipulation;
}
:root {
  --bg: #0f1620;
  --surface: #172030;
  --surface2: #1e2a3e;
  --border: #2a3f5a;
  --text: #eef2f8;
  --text-muted: #6a8aaa;
  --accent: #f5c518;
  --accent2: #e85d30;
  --blue: #1a5fc8;
  --blue-light: #4a9eff;
  --gray-fill: #1a2535;
  --gray-border: #2a3f5a;
  --gray-text: #4a6070;
  --white: #f0f4fa;

  /* Tile state colors — overridden per theme */
  --color-correct: #f5c518;
  --color-correct-glow: rgba(245, 197, 24, 0.4);
  --color-correct-inner: rgba(245, 197, 24, 0.08);
  --color-present: #4a9eff;
  --color-present-glow: rgba(74, 158, 255, 0.35);
  --color-present-inner: rgba(74, 158, 255, 0.08);
  --color-absent-bg: #1a2535;
  --color-absent-border: rgba(192, 57, 43, 0.3);
  --color-absent-text: #4a6070;
  --color-typing-border: #8a9bb0;
  /* Background gradient colors + positions */
  --grad1: rgba(245, 197, 24, 0.31);
  --grad2: rgba(26, 95, 200, 0.34);
  --grad3: rgba(192, 57, 43, 0.2);
  --gx1: 15%;
  --gy1: 15%;
  --gx2: 85%;
  --gy2: 80%;
  --gx3: 50%;
  --gy3: 50%;
  --bg-tint: #0f1620;
  --app-shell-width: 500px;
  --grid-max-width: 380px;
  --keyboard-max-width: 520px;
  --modal-max-width: 400px;
}

/* ── COUNTRY THEMES ── */

/* Colombia / Venezuela / Ecuador — Gold correct, Blue present, Faint red absent */
:root[data-theme="colombia"] {
  --flag1: #f5c518;
  --flag2: #1a5fc8;
  --flag3: #c0392b;
  --color-correct: #f5c518;
  --color-correct-glow: rgba(245, 197, 24, 0.4);
  --color-correct-inner: rgba(245, 197, 24, 0.08);
  --color-present: #4a9eff;
  --color-present-glow: rgba(74, 158, 255, 0.35);
  --color-present-inner: rgba(74, 158, 255, 0.08);
  --color-absent-border: rgba(192, 57, 43, 0.3);
  --accent: #f5c518;
  --grad1: rgba(245, 197, 24, 0.37);
  --grad2: rgba(26, 95, 200, 0.37);
  --grad3: rgba(192, 57, 43, 0.27);
  --gx1: 10%;
  --gy1: 5%;
  --gx2: 90%;
  --gy2: 90%;
  --gx3: 50%;
  --gy3: 50%;
  --bg-tint: #0f1a10;
}

/* México — Green correct, White present, Red absent */
:root[data-theme="mexico"] {
  --flag1: #006847;
  --flag2: #ffffff;
  --flag3: #ce1126;
  --color-correct: #006847;
  --color-correct-glow: rgba(0, 104, 71, 0.4);
  --color-correct-inner: rgba(0, 104, 71, 0.1);
  --color-present: #ffffff;
  --color-present-glow: rgba(255, 255, 255, 0.25);
  --color-present-inner: rgba(255, 255, 255, 0.06);
  --color-absent-border: rgba(206, 17, 38, 0.35);
  --accent: #006847;
  --grad1: rgba(0, 104, 71, 0.42);
  --grad2: rgba(206, 17, 38, 0.37);
  --grad3: rgba(0, 104, 71, 0.24);
  --gx1: 0%;
  --gy1: 50%;
  --gx2: 100%;
  --gy2: 50%;
  --gx3: 50%;
  --gy3: 100%;
  --bg-tint: #0a1a0f;
}

/* Argentina / Uruguay — Blue correct, Sun gold present, Gray absent */
:root[data-theme="argentina"] {
  --flag1: #74acdf;
  --flag2: #ffffff;
  --flag3: #74acdf;
  --color-correct: #74acdf;
  --color-correct-glow: rgba(116, 172, 223, 0.4);
  --color-correct-inner: rgba(116, 172, 223, 0.1);
  --color-present: #f0c040;
  --color-present-glow: rgba(240, 192, 64, 0.3);
  --color-present-inner: rgba(240, 192, 64, 0.08);
  --color-absent-border: rgba(150, 150, 150, 0.25);
  --accent: #74acdf;
  --grad1: rgba(116, 172, 223, 0.44);
  --grad2: rgba(246, 180, 14, 0.34);
  --grad3: rgba(116, 172, 223, 0.24);
  --gx1: 50%;
  --gy1: 0%;
  --gx2: 50%;
  --gy2: 100%;
  --gx3: 20%;
  --gy3: 50%;
  --bg-tint: #0a1220;
}

/* Bolivia — Green correct, Yellow present, Red absent */
:root[data-theme="bolivia"] {
  --flag1: #d52b1e;
  --flag2: #f9e300;
  --flag3: #007a3d;
  --color-correct: #007a3d;
  --color-correct-glow: rgba(0, 122, 61, 0.4);
  --color-correct-inner: rgba(0, 122, 61, 0.1);
  --color-present: #f9e300;
  --color-present-glow: rgba(249, 227, 0, 0.3);
  --color-present-inner: rgba(249, 227, 0, 0.08);
  --color-absent-border: rgba(213, 43, 30, 0.35);
  --accent: #f9e300;
  --grad1: rgba(213, 43, 30, 0.41);
  --grad2: rgba(249, 227, 0, 0.41);
  --grad3: rgba(0, 122, 61, 0.37);
  --gx1: 0%;
  --gy1: 0%;
  --gx2: 50%;
  --gy2: 50%;
  --gx3: 100%;
  --gy3: 100%;
  --bg-tint: #150f08;
}

/* Chile / Dominican / Panama / Puerto Rico / Cuba / Costa Rica / USA / Nicaragua
     Blue correct, White present, Red absent */
:root[data-theme="chile"] {
  --flag1: #ffffff;
  --flag2: #d52b1e;
  --flag3: #003087;
  --color-correct: #1a6eff;
  --color-correct-glow: rgba(26, 110, 255, 0.45);
  --color-correct-inner: rgba(26, 110, 255, 0.1);
  --color-present: #ffffff;
  --color-present-glow: rgba(255, 255, 255, 0.25);
  --color-present-inner: rgba(255, 255, 255, 0.06);
  --color-absent-border: rgba(213, 43, 30, 0.35);
  --accent: #003087;
  --grad1: rgba(26, 110, 255, 0.44);
  --grad2: rgba(213, 43, 30, 0.37);
  --grad3: rgba(255, 255, 255, 0.14);
  --gx1: 0%;
  --gy1: 0%;
  --gx2: 100%;
  --gy2: 50%;
  --gx3: 50%;
  --gy3: 100%;
  --bg-tint: #0a0f1a;
}

/* Peru — Red correct, White present, Faint red absent */
:root[data-theme="peru"] {
  --flag1: #d91023;
  --flag2: #ffffff;
  --flag3: #d91023;
  --color-correct: #d91023;
  --color-correct-glow: rgba(217, 16, 35, 0.45);
  --color-correct-inner: rgba(217, 16, 35, 0.1);
  --color-present: #ffffff;
  --color-present-glow: rgba(255, 255, 255, 0.25);
  --color-present-inner: rgba(255, 255, 255, 0.06);
  --color-absent-border: rgba(217, 16, 35, 0.3);
  --accent: #d91023;
  --grad1: rgba(217, 16, 35, 0.45);
  --grad2: rgba(255, 255, 255, 0.12);
  --grad3: rgba(217, 16, 35, 0.3);
  --gx1: 0%;
  --gy1: 20%;
  --gx2: 50%;
  --gy2: 50%;
  --gx3: 100%;
  --gy3: 80%;
  --bg-tint: #1a0508;
}

/* El Salvador / Guatemala / Honduras — Blue correct, White present, Faint blue absent */
:root[data-theme="elsalvador"] {
  --flag1: #0f47af;
  --flag2: #ffffff;
  --flag3: #0f47af;
  --color-correct: #0a2a7a;
  --color-correct-glow: rgba(10, 42, 122, 0.5);
  --color-correct-inner: rgba(10, 42, 122, 0.15);
  --color-present: #7eb8f7;
  --color-present-glow: rgba(126, 184, 247, 0.3);
  --color-present-inner: rgba(126, 184, 247, 0.08);
  --color-absent-border: rgba(10, 42, 122, 0.4);
  --accent: #0f47af;
  --grad1: rgba(10, 42, 122, 0.48);
  --grad2: rgba(126, 184, 247, 0.37);
  --grad3: rgba(10, 42, 122, 0.31);
  --gx1: 50%;
  --gy1: 0%;
  --gx2: 50%;
  --gy2: 100%;
  --gx3: 100%;
  --gy3: 50%;
  --bg-tint: #080d1a;
}

/* Spain — Gold correct, White present, Red absent */
:root[data-theme="espana"] {
  --flag1: #c60b1e;
  --flag2: #ffc400;
  --flag3: #c60b1e;
  --color-correct: #ffc400;
  --color-correct-glow: rgba(255, 196, 0, 0.4);
  --color-correct-inner: rgba(255, 196, 0, 0.1);
  --color-present: #ffffff;
  --color-present-glow: rgba(255, 255, 255, 0.25);
  --color-present-inner: rgba(255, 255, 255, 0.06);
  --color-absent-border: rgba(198, 11, 30, 0.35);
  --accent: #ffc400;
  --grad1: rgba(198, 11, 30, 0.41);
  --grad2: rgba(255, 196, 0, 0.44);
  --grad3: rgba(198, 11, 30, 0.27);
  --gx1: 0%;
  --gy1: 0%;
  --gx2: 100%;
  --gy2: 0%;
  --gx3: 50%;
  --gy3: 100%;
  --bg-tint: #1a0808;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow-y: auto;
}

#site-header {
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 10;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.flag-bar {
  width: 100%;
  height: 4px;
  display: flex;
  flex-shrink: 0;
}
.flag-bar div:nth-child(1) {
  flex: 2;
  background: var(--flag1, #f5c518);
}
.flag-bar div:nth-child(2) {
  flex: 1;
  background: var(--flag2, #1a5fc8);
}
.flag-bar div:nth-child(3) {
  flex: 1;
  background: var(--flag3, #c0392b);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(
      ellipse 100% 80% at var(--gx1) var(--gy1),
      var(--grad1) 0%,
      transparent 75%
    ),
    radial-gradient(
      ellipse 100% 80% at var(--gx2) var(--gy2),
      var(--grad2) 0%,
      transparent 75%
    ),
    radial-gradient(
      ellipse 90% 70% at var(--gx3) var(--gy3),
      var(--grad3) 0%,
      transparent 75%
    ),
    var(--bg-tint);
  pointer-events: none;
  z-index: 0;
}

header {
  width: 100%;
  max-width: var(--app-shell-width);
  padding: 12px 16px 0;
  position: relative;
  z-index: 1;
}
#keyboard {
  position: relative;
  z-index: 1;
}
#grid-container {
  position: relative;
  z-index: 1;
}
.date-bar {
  position: relative;
  z-index: 1;
}
.header-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.header-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-utils {
  display: flex;
  gap: clamp(4px, 1.5vw, 8px);
  align-items: center;
}
.logo-area {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.logo {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--white);
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.logo-dot {
  color: var(--accent);
  font-size: 32px;
  line-height: 0;
  position: relative;
  top: 4px;
}
.logo-sub {
  font-size: clamp(8px, 2vw, 11px);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 400;
  white-space: nowrap;
}
.logo-sub-inline {
  font-size: clamp(10px, 2.5vw, 13px);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 400;
  white-space: nowrap;
  margin-left: 4px;
}
.logo-sub-inline span {
  color: var(--accent);
  font-weight: 700;
}
.logo-sub span {
  color: var(--accent);
  font-weight: 700;
}

.header-right {
  display: flex;
  gap: clamp(4px, 1.5vw, 8px);
  align-items: center;
}
.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 8px;
  font-size: clamp(10px, 3vw, 13px);
  color: var(--accent);
  font-weight: 700;
  cursor: default;
}
.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 8px;
  font-size: clamp(11px, 3.5vw, 14px);
  cursor: pointer;
  color: var(--text-muted);
  transition:
    color 0.2s,
    border-color 0.2s,
    box-shadow 0.2s;
  line-height: 1;
}

#theme-btn,
.flag-emoji {
  font-family:
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Noto Color Emoji",
    "Twemoji Mozilla",
    sans-serif;
  font-variant-emoji: emoji;
}

#theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
}

.flag-icon {
  display: block;
  width: 1.2em;
  height: 1.2em;
  object-fit: contain;
  flex-shrink: 0;
}
@media (hover: hover) {
  .icon-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(245, 197, 24, 0.25);
  }
  .mode-btn:hover {
    color: var(--text);
  }
  .streak-badge:hover {
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(245, 197, 24, 0.2);
  }
}
.mode-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
}
.mode-btn {
  padding: 4px 10px;
  font-size: clamp(9px, 2.5vw, 11px);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--blue);
  color: var(--white);
}

.date-bar {
  text-align: center;
  padding: 8px 0 8px;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
}

main {
  width: 100%;
  max-width: var(--app-shell-width);
  padding: 20px 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
  z-index: 1;
  flex: 1;
  margin: 0 auto;
}

#toast {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: var(--white);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 500;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── GRID ── */
#grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: min(100%, var(--grid-max-width));
}
.row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.tile {
  width: min(68px, 18vw);
  height: min(68px, 18vw);
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 6vw, 28px);
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  background: var(--surface);
  user-select: none;
  transition: box-shadow 0.15s;
  position: relative;
}

/* Letter typed in */
.tile.filled {
  border-color: rgba(240, 244, 250, 0.5);
  animation: pop 0.12s ease;
}

/* ── REVEALED STATES — ring style ── */

/* Absent: dark fill, dim border, dim text — simple fade */
.tile.absent {
  background: var(--color-absent-bg);
  border-color: var(--color-absent-border);
  color: var(--color-absent-text);
}

/* Present: gold ring (thick border + glow), keep dark bg, gold letter */
.tile.present {
  background: var(--surface);
  border: 3px solid var(--color-present);
  box-shadow:
    0 0 10px var(--color-present-glow),
    inset 0 0 6px var(--color-present-inner);
  color: var(--color-present);
}

/* Correct: blue ring + glow, keep dark bg, blue letter */
.tile.correct {
  background: var(--surface);
  border: 3px solid var(--color-correct);
  box-shadow:
    0 0 12px var(--color-correct-glow),
    inset 0 0 8px var(--color-correct-inner);
  color: var(--color-correct);
}

/* ── REVEAL ANIMATION — clean fade ── */
.tile.reveal-absent {
  animation: fadeAbsent 0.5s ease-out forwards;
}
.tile.reveal-present {
  animation: fadePresent 0.6s ease-out forwards;
}
.tile.reveal-correct {
  animation: fadeCorrect 0.6s ease-out forwards;
}

@keyframes fadeAbsent {
  0% {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
  }
  100% {
    background: var(--color-absent-bg);
    border-color: var(--color-absent-border);
    color: var(--color-absent-text);
  }
}
@keyframes fadePresent {
  0% {
    border-color: var(--border);
    border-width: 2px;
    color: var(--text);
    box-shadow: none;
  }
  100% {
    border-color: var(--color-present);
    border-width: 3px;
    color: var(--color-present);
    box-shadow:
      0 0 10px var(--color-present-glow),
      inset 0 0 6px var(--color-present-inner);
  }
}
@keyframes fadeCorrect {
  0% {
    border-color: var(--border);
    border-width: 2px;
    color: var(--text);
    box-shadow: none;
  }
  100% {
    border-color: var(--color-correct);
    border-width: 3px;
    color: var(--color-correct);
    box-shadow:
      0 0 12px var(--color-correct-glow),
      inset 0 0 8px var(--color-correct-inner);
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  15% {
    transform: translateX(-6px);
  }
  30% {
    transform: translateX(6px);
  }
  45% {
    transform: translateX(-4px);
  }
  60% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
  90% {
    transform: translateX(2px);
  }
}

@keyframes winPop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.18);
    box-shadow:
      0 0 28px rgba(74, 158, 255, 0.7),
      inset 0 0 12px rgba(74, 158, 255, 0.15);
  }
  70% {
    transform: scale(0.95);
  }
  100% {
    transform: scale(1);
  }
}

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

@keyframes heartbeat {
  0% {
    transform: scale(1);
  }
  14% {
    transform: scale(1.22);
  }
  28% {
    transform: scale(1);
  }
  42% {
    transform: scale(1.15);
  }
  56% {
    transform: scale(1);
  }
  100% {
    transform: scale(1);
  }
}
.help-btn-pulse {
  animation: heartbeat 0.75s ease infinite;
}
.help-btn-glow {
  box-shadow:
    0 0 10px rgba(245, 197, 24, 0.6),
    0 0 22px rgba(245, 197, 24, 0.25) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}
.swatch-pulse {
  animation: heartbeat 0.85s ease infinite;
}

.swatch-glow {
  animation: swatchPulse 1.8s ease-in-out infinite;
}
@keyframes swatchPulse {
  0%,
  100% {
    box-shadow: 0 0 2px 1px var(--glow, rgba(255, 255, 255, 0.2));
  }
  50% {
    box-shadow: 0 0 7px 2px var(--glow, rgba(255, 255, 255, 0.4));
  }
}

/* ── KEYBOARD ── */
#keyboard-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  transition:
    opacity 0.4s ease,
    max-height 0.45s ease;
  overflow: hidden;
  max-height: 210px;
  opacity: 1;
}
#keyboard-wrap.hidden {
  opacity: 0;
  max-height: 0;
  pointer-events: none;
}
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: var(--keyboard-max-width);
  padding: 0 4px;
  position: relative;
  z-index: 1;
  touch-action: manipulation;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 0 2px;
}
.key {
  height: 50px;
  flex: 1;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: min(3.5vw, 14px);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  user-select: none;
  letter-spacing: 0.3px;
  touch-action: manipulation;
}
.key:active {
  transform: scale(0.93);
}
.key.wide {
  flex: 1.6;
  font-size: min(3vw, 11px);
  letter-spacing: 0.8px;
}

/* Key states — ring style to match tiles */
.key.absent {
  background: var(--color-absent-bg);
  border-color: var(--color-absent-border);
  color: var(--color-absent-text);
}
.key.present {
  background: var(--surface2);
  border: 2px solid var(--color-present);
  color: var(--color-present);
  box-shadow: 0 0 6px var(--color-present-glow);
}
.key.correct {
  background: var(--surface2);
  border: 2px solid var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(245, 197, 24, 0.3);
}

/* ── RESULT PANEL ── */
#result-panel {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
  width: 90%;
  max-width: min(92vw, 460px);
  max-height: 85dvh;
  overflow-y: auto;
  text-align: center;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 150;
}
#result-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--accent),
    var(--accent2),
    var(--blue-light)
  );
  pointer-events: none;
}
#result-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 149;
  pointer-events: none;
}
#result-backdrop.show {
  display: block;
  pointer-events: all;
}
#result-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
#result-close:hover {
  color: var(--white);
}
#result-panel.show {
  display: flex;
}
.result-emoji {
  font-size: 38px;
}
.result-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 23px;
  font-weight: 900;
  color: var(--white);
}
.result-word {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 6px;
  text-transform: uppercase;
}
.result-def {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.65;
  font-style: italic;
  max-width: 320px;
}
.result-def strong {
  color: var(--text);
  font-style: normal;
  display: block;
  margin-bottom: 5px;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.ornament {
  color: var(--border);
  letter-spacing: 6px;
  font-size: 11px;
  user-select: none;
}
.result-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 2px;
}
.btn {
  padding: 10px 22px;
  border-radius: 30px;
  border: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-primary:hover {
  background: #ffd740;
}
.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-muted);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── STATS MODAL ── */
/* Modal overlays — display:none when closed, flex when open */
#stats-overlay,
#theme-overlay,
#help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 22, 0.85);
  backdrop-filter: blur(4px);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
#stats-overlay.open,
#theme-overlay.open,
#help-overlay.open {
  display: flex;
}
.modal-inner {
  background: #172030;
  border: 1px solid #2a3f5a;
  border-radius: 16px;
  padding: 20px 20px 16px;
  width: 90%;
  max-width: min(92vw, var(--modal-max-width));
  height: min(70dvh, 680px);
  display: flex;
  flex-direction: column;
  position: relative;
  pointer-events: auto;
  overflow: hidden;
}
.modal-title {
  font-family: Georgia, serif;
  font-size: 18px;
  font-weight: 900;
  color: #f0f4fa;
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.modal-scroll {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
}
#help-overlay .help-inner {
  background: #172030;
  border: 1px solid #2a3f5a;
  border-radius: 16px;
  padding: 20px 20px 16px;
  width: 90%;
  max-width: min(92vw, var(--modal-max-width));
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  pointer-events: auto;
  overflow: hidden;
}
#stats-overlay.open #stats-modal {
  transform: none;
}
#stats-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px 28px 26px;
  width: 90%;
  max-width: min(92vw, var(--modal-max-width));
  position: relative;
}
#stats-overlay.open #stats-modal {
  transform: translateY(0);
}
#stats-modal::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--accent),
    var(--accent2),
    var(--blue-light)
  );
  pointer-events: none;
}
.stats-close,
.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
  border-radius: 50%;
  transition:
    color 0.15s,
    background 0.15s;
}
.stats-close:hover,
.modal-close:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}
.stats-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  font-weight: 900;
  color: var(--white);
  text-align: center;
  margin-bottom: 20px;
  letter-spacing: 0.5px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.stat-num {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}
.stat-lbl {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.3;
}
.dist-title {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.dist-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  width: 10px;
  text-align: right;
  flex-shrink: 0;
}
.dist-bar-wrap {
  flex: 1;
  height: 22px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.dist-bar {
  height: 100%;
  background: var(--gray-border);
  border-radius: 3px;
  min-width: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  transition: width 0.6s ease;
  font-size: 12px;
  font-weight: 700;
  color: var(--white);
}
.dist-bar.highlight {
  background: var(--blue-light);
  color: var(--bg);
}
.stats-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ── MÁS MODAL & WHAT'S NEW ── */
#mas-overlay,
#whatsnew-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 22, 0.85);
  backdrop-filter: blur(4px);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
#mas-overlay.open,
#whatsnew-overlay.open {
  display: flex;
}
.mas-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-shrink: 0;
}
.mas-tab {
  flex: 1;
  padding: 7px 4px;
  border-radius: 8px;
  border: 1px solid #2a3f5a;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.mas-tab.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
}
.mas-panel {
  display: none;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}
.mas-panel.active {
  display: flex;
}
.mas-version {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mas-version-current {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--color-correct);
  border: 1px solid var(--color-correct);
  border-radius: 4px;
  padding: 1px 6px;
  text-transform: uppercase;
  font-weight: 700;
}
.mas-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mas-list li {
  font-size: 13px;
  color: #eef2f8;
  line-height: 1.5;
  padding-left: 4px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.mas-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
  background: #3a5070;
}
.mas-text {
  font-size: 13px;
  color: #eef2f8;
  line-height: 1.6;
  margin: 0;
}

/* ── RESPONSIVE SIZING ──────────────────────────────────────── */
/* Fluid tiles — always fill available width cleanly */
.tile {
  width: min(68px, calc((100vw - 24px - 24px) / 5));
  height: min(68px, calc((100vw - 24px - 24px) / 5));
}
/* Fluid keys */
.key {
  height: max(44px, min(54px, 13vw));
  font-size: max(11px, min(14px, 3.5vw));
}
.key.wide {
  flex: 1.6;
  font-size: max(9px, min(11px, 2.8vw));
}

/* Small phones ≤390px (iPhone SE, 15 non-pro, small androids) */
@media (max-width: 390px) {
  .logo {
    font-size: 22px;
  }
  main {
    padding: 12px 8px 16px;
    gap: 10px;
  }
  #grid {
    gap: 5px;
  }
  .kb-row {
    gap: 3px;
  }
  .key {
    height: 44px;
  }

  #toast {
    top: 88px;
    font-size: 13px;
    padding: 10px 16px;
    white-space: normal;
    text-align: center;
  }
}
/* Very small ≤340px */
@media (max-width: 340px) {
  main {
    padding: 8px 4px 12px;
    gap: 8px;
  }
  .key {
    height: 40px;
    font-size: 10px;
  }
  .key.wide {
    font-size: 9px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 10px;
  }

  .result-actions {
    width: 100%;
  }

  .result-actions .btn {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 10px;
  }

  .result-actions {
    width: 100%;
  }

  .result-actions .btn {
    width: 100%;
  }
}

@media (min-width: 768px) {
  :root {
    --app-shell-width: 720px;
    --grid-max-width: 410px;
    --keyboard-max-width: 640px;
    --modal-max-width: 460px;
  }

  header {
    padding: 18px 20px 0;
  }

  .header-inner {
    gap: 10px;
    padding-bottom: 14px;
  }

  .date-bar {
    padding: 10px 0 12px;
    font-size: 12px;
  }

  main {
    padding: 28px 20px 28px;
    gap: 18px;
  }

  #grid {
    gap: 8px;
  }

  .row {
    gap: 8px;
  }

  .tile {
    width: min(74px, calc((var(--grid-max-width) - 32px) / 5));
    height: min(74px, calc((var(--grid-max-width) - 32px) / 5));
    font-size: clamp(24px, 2.2vw, 32px);
  }

  #keyboard-wrap {
    max-width: var(--keyboard-max-width);
  }

  #keyboard {
    padding: 0;
  }

  .kb-row {
    gap: 7px;
    padding: 0;
  }

  .key {
    height: 56px;
    font-size: 14px;
  }

  .key.wide {
    font-size: 12px;
  }

  .icon-btn,
  .streak-badge {
    padding: 6px 10px;
  }

  .mode-btn {
    padding: 6px 12px;
    font-size: 11px;
  }

  .modal-inner,
  #help-overlay .help-inner,
  #stats-modal,
  #result-panel {
    border-radius: 18px;
  }
}
.end-wrap {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 20px 0 12px;
}

.end-wrap-column {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 20px 0 12px;
}

.end-btn {
  min-width: 200px;
}

.end-msg {
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
}

.help-title {
  font-family: Georgia, serif;
  font-size: 18px;
  font-weight: 900;
  color: #f0f4fa;
  text-align: center;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.help-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 4px;
}

.help-section-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #6a8aaa;
  margin-bottom: 10px;
}

.help-body {
  font-size: 14px;
  color: #eef2f8;
  line-height: 1.6;
}

.help-body-small {
  font-size: 13px;
  color: #eef2f8;
  line-height: 1.6;
}

.help-body-muted {
  font-size: 13px;
  color: #6a8aaa;
  line-height: 1.6;
}

.help-strong {
  color: #eef2f8;
}

.help-colors {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mas-text-accent {
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 12px;
}

.whatsnew-note {
  margin-top: 16px;
  color: #6a8aaa;
}

.whatsnew-ok {
  margin-top: 16px;
  width: 100%;
}
