* {
  -webkit-touch-callout: none;
    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
}

/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --bg:           #EEF6FF;
  --card:         #FFFFFF;
  --shadow:       rgba(0, 0, 0, 0.10);
  --shadow-hover: rgba(0, 0, 0, 0.18);

  --guess:        #FF6B35;
  --paint:        #8B2FC9;
  --success:      #06C98A;
  --danger:       #EF233C;
  --secondary:    #5C6BC0;

  --text:         #1A1A2E;
  --muted:        #7B8AA0;

  --r-sm: 14px;
  --r-md: 22px;
  --r-lg: 32px;

  --t: 0.18s ease;
}

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

html { font-size: 18px; }

body {
  font-family: 'Segoe UI', 'Trebuchet MS', system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(145deg, #D4EEFF 0%, #EDE7F6 50%, #FFF9E6 100%);
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: fadeUp .28s ease both;
}
.screen[hidden] { display: none !important; }

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

/* ============================================================
   HOME
   ============================================================ */
#screen-home {
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  gap: 48px;
}

.home-hero {
  text-align: center;
}

.home-globe {
  font-size: 88px;
  display: block;
  animation: bob 3s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0);   }
  50%       { transform: translateY(-10px); }
}

.home-title {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 900;
  line-height: 1.1;
  margin-top: 16px;
  color: var(--text);
  letter-spacing: -0.5px;
}

.home-sub {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--muted);
  margin-top: 10px;
}

/* Mode cards */
.mode-cards {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.mode-card {
  flex: 1;
  min-width: 220px;
  max-width: 280px;
  background: var(--card);
  border: none;
  border-radius: var(--r-lg);
  padding: 36px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 28px var(--shadow);
  transition: transform var(--t), box-shadow var(--t);
}

.mode-card:hover  { transform: translateY(-8px); box-shadow: 0 18px 48px var(--shadow-hover); }
.mode-card:active { transform: scale(0.96); }

.mode-card.guess { border-top: 7px solid var(--guess); }
.mode-card.paint { border-top: 7px solid var(--paint); }

.mode-icon  { font-size: 60px; }

.mode-label {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
}

.mode-desc {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

/* ============================================================
   SHARED HEADER
   ============================================================ */
.screen-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px 0;
  flex-shrink: 0;
}

.screen-header h2 {
  font-size: clamp(1.3rem, 3.5vw, 1.9rem);
  font-weight: 800;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-back {
  background: var(--card);
  border: none;
  border-radius: var(--r-sm);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 2px 10px var(--shadow);
  transition: transform var(--t);
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-back:hover  { transform: translateX(-4px); }
.btn-back:active { transform: scale(0.95); }

.level-badge {
  margin-left: auto;
  background: rgba(0,0,0,0.08);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ============================================================
   COUNTRY GRID
   ============================================================ */
#screen-select { padding-bottom: 40px; }

.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 18px;
  padding: 24px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.country-card {
  background: var(--card);
  border: none;
  border-radius: var(--r-md);
  padding: 22px 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 18px var(--shadow);
  transition: transform var(--t), box-shadow var(--t);
}

.country-card:hover  { transform: translateY(-5px); box-shadow: 0 12px 32px var(--shadow-hover); }
.country-card:active { transform: scale(0.95); }

.country-emoji { font-size: 52px; line-height: 1; }

.country-name {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.country-palette {
  display: flex;
  height: 10px;
  width: 85%;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
}

.palette-swatch { flex: 1; }

/* ============================================================
   SCREEN CONTENT (placeholder / game areas)
   ============================================================ */
.screen-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Coming soon placeholder */
.coming-soon {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 48px 36px;
  box-shadow: 0 6px 24px var(--shadow);
  max-width: 400px;
}

.coming-soon-icon    { font-size: 56px; }
.coming-soon-title   { font-size: 1.6rem; font-weight: 800; }
.coming-soon-sub     { font-size: 1rem; color: var(--muted); }
.coming-soon-country { font-size: 1.8rem; font-weight: 700; }

/* ============================================================
   SHARED BUTTONS
   ============================================================ */
.btn {
  border: none;
  border-radius: var(--r-md);
  padding: 16px 32px;
  font-size: 1.05rem;
  font-weight: 800;
  transition: transform var(--t), opacity var(--t);
}
.btn:hover  { transform: translateY(-2px); }
.btn:active { transform: scale(0.96); opacity: .9; }

.btn-primary   { background: var(--guess);     color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-success   { background: var(--success);   color: #fff; }
.btn-danger    { background: var(--danger);    color: #fff; }

/* ============================================================
   GUESS MODE
   ============================================================ */
.guess-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 560px;
  padding: 8px 0 24px;
}

.guess-flag-wrap {
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px var(--shadow);
  padding: 16px;
  width: 100%;
  max-width: 420px;
}

.guess-flag {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.guess-question {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
}

.guess-options {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.guess-option-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.guess-option-btn {
  flex: 1;
  background: var(--card);
  border: 3px solid transparent;
  border-radius: var(--r-md);
  padding: 16px 20px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: left;
  box-shadow: 0 3px 12px var(--shadow);
  transition: border-color var(--t), background var(--t), transform var(--t);
}
.guess-option-btn:hover:not(:disabled) {
  border-color: var(--secondary);
  transform: translateX(4px);
}
.guess-option-btn.correct {
  background: #D4EDDA;
  border-color: var(--success);
  color: #155724;
  animation: pulse-green .4s ease;
}
.guess-option-btn.wrong {
  background: #F8D7DA;
  border-color: var(--danger);
  color: #721c24;
  animation: shake .4s ease;
}

@keyframes pulse-green {
  0%  { transform: scale(1); }
  50% { transform: scale(1.03); }
  100%{ transform: scale(1); }
}

@keyframes shake {
  0%,100%{ transform: translateX(0); }
  25%    { transform: translateX(-8px); }
  75%    { transform: translateX(8px); }
}

.tts-btn {
  background: var(--card);
  border: none;
  border-radius: var(--r-sm);
  width: 52px;
  height: 52px;
  font-size: 1.4rem;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform var(--t);
  flex-shrink: 0;
}
.tts-btn:hover  { transform: scale(1.1); }
.tts-btn:active { transform: scale(0.93); }

/* ============================================================
   COUNTRY CARD (tarjeta de país)
   ============================================================ */
.card-loading {
  font-size: 1.2rem;
  color: var(--muted);
  padding: 60px;
}

.card-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 860px;
  gap: 0;
  animation: fadeUp .3s ease both;
}

.card-map-wrap {
  width: 100%;
  background: #7BAFD4;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  overflow: hidden;
  max-height: 320px;
}

.card-map-svg svg {
  width: 100%;
  height: auto;
  display: block;
  max-height: 320px;
}

.card-info {
  background: var(--card);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  padding: 28px 32px 36px;
  box-shadow: 0 6px 24px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card-flag-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.card-flag-thumb {
  width: 100px;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow);
  flex-shrink: 0;
}

.card-country-name {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 900;
  line-height: 1.1;
}

.card-continent {
  font-size: 1rem;
  color: var(--muted);
  margin-top: 4px;
}

.card-facts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-fact {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 12px 16px;
}

.fact-icon  { font-size: 1.4rem; flex-shrink: 0; }
.fact-label { font-size: 0.9rem; color: var(--muted); flex: 0 0 70px; }
.fact-value { font-size: 1rem; font-weight: 700; }

.card-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-tts     { background: var(--guess); color: #fff; }
.btn-outline  {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--muted);
}
.btn-outline:hover { background: var(--bg); }

/* Pulse animation for highlighted country on the world map */
@keyframes country-pulse {
  0%, 100% { stroke-width: 4; stroke-opacity: 1; }
  50%       { stroke-width: 12; stroke-opacity: 0.4; }
}
.country-highlighted {
  stroke: #fff !important;
  stroke-width: 4;
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.6));
  animation: country-pulse 1.6s ease-in-out infinite;
}

/* ============================================================
   PAINT MODE
   ============================================================ */
#screen-paint .screen-content {
  justify-content: flex-start;
  overflow-y: auto;
}

.paint-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 580px;
  padding: 4px 0 32px;
}

.paint-flag-wrap {
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px var(--shadow);
  padding: 12px;
  width: 100%;
  cursor: crosshair;
}

.paint-flag-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

/* Borde de separación entre regiones pintables */
.paint-flag-wrap svg [data-region] {
  stroke: #000;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.paint-hint {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

/* Palette */
.paint-palette {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.paint-color-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 3px solid transparent;
  border-radius: var(--r-md);
  padding: 12px 18px;
  box-shadow: 0 3px 12px var(--shadow);
  transition: transform var(--t), border-color var(--t), box-shadow var(--t);
  min-width: 82px;
}
.paint-color-btn:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 22px var(--shadow-hover);
}
.paint-color-btn.selected {
  border-color: var(--paint);
  transform: scale(1.1);
  box-shadow: 0 0 0 4px rgba(139, 47, 201, 0.22), 0 6px 18px var(--shadow-hover);
}

.paint-swatch {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid rgba(0,0,0,0.14);
  box-shadow: inset 0 1px 3px rgba(255,255,255,0.4);
}

.paint-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

/* Action buttons */
.paint-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.paint-btn-help { background: var(--secondary); color: #fff; }
.paint-btn-tts  { background: var(--guess);     color: #fff; }
.paint-btn-name {
  align-self: center;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.5rem 1.6rem;
  border-radius: 999px;
  margin-bottom: 0.25rem;
}

/* Shake hint when no color selected */
@keyframes shake-hint {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-8px); }
  60%     { transform: translateX(8px); }
  80%     { transform: translateX(-4px); }
}
.shake-hint { animation: shake-hint .45s ease; }

/* Help modal */
.paint-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.paint-modal[hidden] { display: none !important; }

.paint-modal-inner {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  max-width: 440px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 20px 56px rgba(0,0,0,0.35);
  animation: fadeUp .2s ease both;
}

.paint-modal-flag {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
}

.paint-modal-name {
  font-size: 1.6rem;
  font-weight: 900;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Tablet: 768px and up */
@media (min-width: 768px) {
  .card-map-wrap    { max-height: 380px; }
  .card-map-svg svg { max-height: 380px; }
  .card-info        { padding: 32px 44px 40px; }
  .card-flag-thumb  { width: 120px; }
}

/* Large desktop: 1100px and up */
@media (min-width: 1100px) {
  .card-layout      { max-width: 960px; }
  .card-map-wrap    { max-height: 440px; }
  .card-map-svg svg { max-height: 440px; }
}

/* Small mobile: 500px and below */
@media (max-width: 500px) {
  .home-globe  { font-size: 64px; }
  .mode-icon   { font-size: 48px; }
  .mode-cards  { gap: 14px; }
  .country-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    padding: 16px;
  }
  .country-emoji { font-size: 42px; }
  .paint-color-btn { padding: 10px 14px; min-width: 70px; }
  .paint-swatch    { width: 36px; height: 36px; }
  .card-info       { padding: 20px 18px 28px; }
  .card-flag-thumb { width: 76px; }
  .card-actions    { flex-direction: column; }
  .card-actions .btn { text-align: center; }
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
:focus-visible {
  outline: 3px solid var(--secondary);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Ensure minimum touch target on interactive elements */
.btn, .btn-back, .mode-card, .country-card,
.guess-option-btn, .tts-btn, .paint-color-btn {
  min-height: 44px;
}
