:root {
  --deep-blue: #1b3a6b;
  --deep-blue-dark: #12274a;
  --amber: #f5a623;
  --amber-dark: #d98c0f;
  --on-accent: var(--deep-blue-dark);
  --white: #ffffff;
  --off-white: #f4f7fb;
  --green: #2e9e4a;
  --green-light: #e3f8e8;
  --red: #d64545;
  --red-light: #fbe4e4;
  --text-dark: #1f2733;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

/* ---------- THEMES (national colours) ---------- */
/* --green/--red/--off-white stay constant across themes so correct/wrong feedback keeps a consistent meaning. */

:root[data-theme="portugal"] {
  --deep-blue: #6e1423;
  --deep-blue-dark: #470d18;
  --amber: #2fa84f;
  --amber-dark: #1f7a38;
  --on-accent: #470d18;
}

:root[data-theme="argentina"] {
  --deep-blue: #2d6da3;
  --deep-blue-dark: #1b4870;
  --amber: #ffc72c;
  --amber-dark: #d9a61e;
  --on-accent: #1b4870;
}

:root[data-theme="spain"] {
  --deep-blue: #aa151b;
  --deep-blue-dark: #7a0000;
  --amber: #f1bf00;
  --amber-dark: #c79a00;
  --on-accent: #7a0000;
}

:root[data-theme="france"] {
  --deep-blue: #0055a4;
  --deep-blue-dark: #002654;
  --amber: #ef4135;
  --amber-dark: #c62828;
  --on-accent: #ffffff;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  background: linear-gradient(180deg, var(--deep-blue) 0%, var(--deep-blue-dark) 100%);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 720px;
  min-height: 100vh;
  background: var(--off-white);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

@media (min-width: 760px) {
  body {
    padding: 20px;
  }
  #app {
    min-height: 90vh;
    border-radius: 20px;
    margin: 20px auto;
  }
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 14px;
  font-weight: bold;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

button:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--amber);
  color: var(--on-accent);
  min-height: 56px;
  font-size: 1.2rem;
  padding: 12px 28px;
}

.btn-primary:hover {
  background: var(--amber-dark);
}

.btn-secondary {
  background: var(--deep-blue);
  color: var(--white);
  min-height: 52px;
  font-size: 1.05rem;
  padding: 10px 24px;
}

.btn-secondary:hover {
  background: var(--deep-blue-dark);
}

.btn-danger {
  background: var(--red);
  color: var(--white);
  min-height: 48px;
  padding: 10px 20px;
  font-size: 1rem;
}

/* ---------- HOME SCREEN ---------- */

.home-screen {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  flex: 1;
  justify-content: center;
}

.home-title {
  font-size: 2.6rem;
  color: var(--deep-blue);
  margin: 0;
}

.home-subtitle {
  font-size: 1.3rem;
  color: var(--amber-dark);
  margin: 0 0 10px 0;
  font-weight: bold;
}

.edit-name-btn {
  background: none;
  border: none;
  min-height: auto;
  padding: 0 0 0 4px;
  font-size: 0.9rem;
  cursor: pointer;
  vertical-align: middle;
}

.edit-name-btn:hover {
  transform: none;
  box-shadow: none;
  opacity: 0.7;
}

.theme-pill-btn {
  background: var(--white);
  border: 2px solid var(--deep-blue);
  color: var(--deep-blue);
  border-radius: 20px;
  min-height: auto;
  padding: 6px 16px;
  font-size: 0.9rem;
  margin-top: -6px;
}

/* ---------- THEME PICKER SCREEN ---------- */

.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 480px) {
  .theme-grid {
    grid-template-columns: 1fr;
  }
}

.theme-swatch {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  text-align: left;
}

.theme-swatch.active {
  border-color: var(--amber-dark);
}

.theme-swatch-colors {
  display: flex;
  flex-shrink: 0;
}

.theme-swatch-colors span {
  display: block;
  width: 20px;
  height: 36px;
  border-radius: 6px;
}

.theme-swatch-colors span:first-child {
  border-radius: 6px 0 0 6px;
}

.theme-swatch-colors span:last-child {
  border-radius: 0 6px 6px 0;
}

.theme-swatch-name {
  font-weight: bold;
  font-size: 1.05rem;
  color: var(--text-dark);
}

.theme-swatch-check {
  margin-left: auto;
  font-size: 1.3rem;
}

.stats-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.stat-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  min-width: 110px;
  flex: 1;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--deep-blue);
}

.stat-label {
  font-size: 0.95rem;
  color: #555;
  margin-top: 4px;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 360px;
  margin-top: 12px;
}

/* ---------- SESSION HEADER / TIMER ---------- */

.session-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.timer-bar {
  background: var(--deep-blue);
  color: var(--white);
  border-radius: 14px;
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.3rem;
  font-weight: bold;
  box-shadow: var(--shadow);
}

.timer-bar.low-time {
  background: var(--red);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.part-indicator {
  font-size: 1rem;
  color: var(--deep-blue);
  font-weight: bold;
  text-align: center;
}

.progress-bar-track {
  width: 100%;
  height: 12px;
  background: #dde5f0;
  border-radius: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--amber);
  transition: width 0.3s ease;
}

/* ---------- QUESTION SCREEN ---------- */

.question-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-card {
  background: var(--white);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
}

.question-text {
  font-size: 1.35rem;
  color: var(--text-dark);
  line-height: 1.4;
  margin: 0;
}

.passage-box {
  background: #fff8e8;
  border-left: 6px solid var(--amber);
  border-radius: 10px;
  padding: 16px 18px;
  font-size: 1.1rem;
  line-height: 1.5;
  margin-bottom: 10px;
}

.passage-title {
  font-weight: bold;
  color: var(--deep-blue);
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .options-grid {
    grid-template-columns: 1fr;
  }
}

.option-btn {
  background: var(--white);
  border: 3px solid var(--deep-blue);
  color: var(--deep-blue);
  min-height: 56px;
  font-size: 1.1rem;
  padding: 10px 14px;
}

.option-btn:hover {
  background: var(--deep-blue);
  color: var(--white);
}

.option-btn.selected {
  background: var(--amber);
  border-color: var(--amber-dark);
  color: var(--on-accent);
}

.text-input-row {
  display: flex;
  gap: 10px;
}

.text-input-row input {
  flex: 1;
  font-size: 1.2rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 3px solid var(--deep-blue);
  min-height: 52px;
}

.tf-row {
  display: flex;
  gap: 16px;
}

.tf-btn {
  flex: 1;
  min-height: 60px;
  font-size: 1.2rem;
  border: 3px solid var(--deep-blue);
  background: var(--white);
  color: var(--deep-blue);
}

.tf-btn:hover {
  background: var(--deep-blue);
  color: var(--white);
}

.tf-btn.selected {
  background: var(--amber);
  border-color: var(--amber-dark);
  color: var(--on-accent);
}

.odd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.odd-btn {
  min-height: 64px;
  font-size: 1.15rem;
  border: 3px solid var(--deep-blue);
  background: var(--white);
  color: var(--deep-blue);
}

.odd-btn:hover {
  background: var(--deep-blue);
  color: var(--white);
}

.odd-btn.selected {
  background: var(--amber);
  border-color: var(--amber-dark);
  color: var(--on-accent);
}

.sequence-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--deep-blue);
}

.sequence-blank-input {
  width: 70px;
  text-align: center;
  font-size: 1.3rem;
  padding: 8px;
  border-radius: 10px;
  border: 3px solid var(--amber-dark);
  min-height: 52px;
}

.submit-row {
  display: flex;
  justify-content: center;
  margin-top: 6px;
}

/* ---------- FEEDBACK ---------- */

.feedback-flash {
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  font-size: 1.15rem;
  animation: flashIn 0.25s ease;
}

.feedback-flash.correct {
  background: var(--green-light);
  border: 3px solid var(--green);
  color: #1b6b30;
}

.feedback-flash.wrong {
  background: var(--red-light);
  border: 3px solid var(--red);
  color: #9c2b2b;
}

.feedback-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

@keyframes flashIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------- PART COMPLETE / SESSION COMPLETE ---------- */

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

.big-score {
  font-size: 2.6rem;
  color: var(--deep-blue);
  font-weight: bold;
}

.stars-row {
  display: flex;
  gap: 10px;
  font-size: 3rem;
}

.star {
  opacity: 0.25;
  transform: scale(0.6);
  animation: starPop 0.5s ease forwards;
}

.star.earned {
  opacity: 1;
}

.star:nth-child(1) { animation-delay: 0.1s; }
.star:nth-child(2) { animation-delay: 0.35s; }
.star:nth-child(3) { animation-delay: 0.6s; }

@keyframes starPop {
  0% { transform: scale(0.4) rotate(-15deg); }
  60% { transform: scale(1.2) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.motivate-msg {
  font-size: 1.25rem;
  color: var(--amber-dark);
  font-weight: bold;
  max-width: 420px;
}

/* ---------- PROGRESS SCREEN ---------- */

.progress-screen {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.streak-banner {
  background: var(--deep-blue);
  color: var(--white);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  font-size: 1.6rem;
  font-weight: bold;
  box-shadow: var(--shadow);
}

.chart-box {
  background: var(--white);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.chart-title {
  font-weight: bold;
  color: var(--deep-blue);
  margin-bottom: 12px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  border-bottom: 2px solid #ccc;
  padding-bottom: 4px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.bar {
  width: 100%;
  background: var(--amber);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}

.bar-label {
  font-size: 0.65rem;
  color: #666;
  margin-top: 4px;
}

.weak-areas-box {
  background: var(--white);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.weak-area-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  font-size: 1.05rem;
}

.weak-area-item:last-child {
  border-bottom: none;
}

.backup-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.backup-actions .btn-secondary {
  min-height: 44px;
  font-size: 0.9rem;
  padding: 8px 16px;
}

.interrupted-box {
  background: var(--red-light);
  border: 3px solid var(--red);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  color: #9c2b2b;
  font-size: 1.1rem;
}

.hidden {
  display: none !important;
}

.top-nav-back {
  align-self: flex-start;
  background: none;
  color: var(--deep-blue);
  font-weight: bold;
  font-size: 1rem;
  padding: 6px 4px;
  box-shadow: none;
}

.top-nav-back:hover {
  transform: none;
  text-decoration: underline;
}

/* ---------- LEVEL / COINS / BADGES ---------- */

.level-pill {
  background: var(--deep-blue);
  color: var(--white);
  font-size: 1rem;
  font-weight: bold;
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.coin-pill {
  background: var(--amber);
  color: var(--on-accent);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 0.95rem;
  font-weight: bold;
}

.badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 420px;
}

.badge-icon {
  font-size: 1.6rem;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--shadow);
}

.badge-icon.locked {
  opacity: 0.25;
  filter: grayscale(1);
}

.combo-badge {
  align-self: center;
  background: var(--amber);
  color: var(--on-accent);
  font-weight: bold;
  border-radius: 14px;
  padding: 6px 16px;
  text-align: center;
  animation: comboPop 0.3s ease;
}

@keyframes comboPop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.coin-earned {
  font-weight: bold;
  color: var(--amber-dark);
  margin-top: 8px;
  font-size: 1.1rem;
}

.coin-total-line {
  font-weight: bold;
  color: var(--amber-dark);
}

.badge-unlock-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.badge-unlock-item {
  background: #fff8e8;
  border: 2px solid var(--amber);
  border-radius: 12px;
  padding: 8px 16px;
  font-weight: bold;
  color: var(--deep-blue-dark);
  animation: starPop 0.5s ease;
}

/* ---------- BRAIN GAMES MENU ---------- */

.games-title {
  color: var(--deep-blue);
  text-align: center;
  margin: 4px 0 0 0;
}

.games-sub {
  text-align: center;
  color: #555;
  margin: 0 0 10px 0;
}

.game-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.game-card:hover {
  border-color: var(--amber);
  transform: translateY(-2px);
}

.game-card-emoji {
  font-size: 2.4rem;
}

.game-card-name {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--deep-blue);
}

.game-card-meta {
  color: #666;
  font-size: 0.95rem;
}

/* ---------- SPEED ROUND ---------- */

.speed-timer-bar {
  background: var(--amber-dark);
}

.speed-question {
  font-size: 2rem;
  text-align: center;
  font-weight: bold;
  color: var(--deep-blue);
}

.speed-solved {
  text-align: center;
  color: var(--amber-dark);
  font-weight: bold;
}

.flash-correct-quick {
  animation: flashGreenQuick 0.35s ease;
}

.flash-wrong-quick {
  animation: flashRedQuick 0.35s ease;
}

@keyframes flashGreenQuick {
  0% { background: var(--green-light); }
  100% { background: var(--white); }
}

@keyframes flashRedQuick {
  0% { background: var(--red-light); }
  100% { background: var(--white); }
}

/* ---------- MEMORY MATCH ---------- */

.memory-stats {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  color: var(--deep-blue);
  font-size: 1.1rem;
  padding: 0 4px;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.memory-card {
  aspect-ratio: 1 / 1;
  background: var(--deep-blue);
  border-radius: 12px;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, background 0.2s ease;
}

.memory-card.flipped {
  background: var(--white);
  border: 3px solid var(--amber);
  transform: rotateY(0deg) scale(1.03);
}

.memory-card.matched {
  background: var(--green-light);
  border: 3px solid var(--green);
  opacity: 0.85;
}

/* ---------- CONFETTI ---------- */

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation-name: confettiFall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.3; }
}
