* { box-sizing: border-box; }

:root {
  --sky-top: #7ec8f2;
  --sky-bottom: #d8f1ff;
  --ground: #6b4a2f;
  --ground-light: #8a6640;
  --panel-bg: rgba(255, 255, 255, 0.94);
  --text-dark: #22303c;
  --accent: #ff6b6b;
  --accent2: #4ecdc4;
  --accent3: #ffd93d;
  --der-color: #4a90d9;
  --die-color: #e05c8a;
  --das-color: #4caf7d;
  --danger: #e74c3c;
  --gold: #ffd700;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 100%);
  color: var(--text-dark);
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
}
.screen.active { display: flex; }

.panel {
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 2.2rem 2.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  text-align: center;
  max-width: 520px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

h1 { margin: 0 0 0.3rem; font-size: 2.2rem; }
h2 { margin: 0 0 0.5rem; }
.subtitle { color: #5a6b78; margin-bottom: 1.2rem; }

label { display: block; margin-bottom: 0.4rem; font-weight: 600; }

#player-name {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: 1.05rem;
  border: 2px solid #cfd8e0;
  border-radius: 10px;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
#player-name:focus { border-color: var(--accent2); }

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  margin: -0.5rem 0 0.8rem;
}

.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  margin-top: 0.7rem;
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.15s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent2), #3aa89f);
  color: #fff;
  box-shadow: 0 4px 0 #2b8a82;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); }
.btn-primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #2b8a82; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  background: #e9edf1;
  color: var(--text-dark);
  box-shadow: 0 4px 0 #c7d0d8;
}
.btn-secondary:hover { transform: translateY(-2px); }
.btn-secondary:active { transform: translateY(2px); box-shadow: 0 2px 0 #c7d0d8; }

.icon-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  font-size: 1.4rem;
  background: rgba(255,255,255,0.85);
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}

.back-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-dark);
  background: rgba(255,255,255,0.85);
  border-radius: 999px;
  padding: 0.5rem 0.9rem 0.5rem 0.7rem;
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}
.back-link:hover { background: rgba(255,255,255,0.98); }

/* Character select */
.character-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}
.character-card {
  background: #f4f7f9;
  border: 3px solid transparent;
  border-radius: 14px;
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-weight: 600;
  transition: border-color 0.15s, transform 0.1s;
}
.character-card:hover { transform: translateY(-2px); }
.character-card.selected { border-color: var(--accent2); background: #eafffb; }
.char-emoji { font-size: 2.6rem; }

/* Level select */
.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.level-card {
  background: #f4f7f9;
  border: 3px solid transparent;
  border-radius: 14px;
  padding: 0.8rem 0.3rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: border-color 0.15s, transform 0.1s;
}
.level-card:hover { transform: translateY(-2px); }
.level-card.selected { border-color: var(--accent); background: #fff0f0; }
.level-code { font-size: 1.3rem; font-weight: 800; }
.level-label { font-size: 0.75rem; color: #5a6b78; }

/* GAME SCREEN */
#screen-game { flex-direction: column; }

.hud {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 1.1rem;
}
.hud-left { display: flex; align-items: center; gap: 0.6rem; }
.pause-btn {
  background: rgba(255,255,255,0.85);
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transition: transform 0.1s;
}
.pause-btn:hover { transform: scale(1.08); }
.hearts { display: flex; gap: 4px; font-size: 1.5rem; }
.heart-lost { opacity: 0.25; filter: grayscale(1); }
.badge {
  background: rgba(255,255,255,0.85);
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.9rem;
}
.hud-right { display: flex; align-items: center; gap: 0.6rem; }
.streak-badge {
  background: var(--accent3);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  animation: pop 0.25s ease;
}

.game-area {
  position: relative;
  width: 100%;
  max-width: 900px;
  height: 300px;
  background: linear-gradient(180deg, rgba(255,255,255,0.15), rgba(255,255,255,0));
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.4);
}

/* Freezes any still-running CSS animations (run-bob, cloud-drift, the
   golden obstacle's float, etc.) the instant the game is paused. */
.game-area.paused,
.game-area.paused * {
  animation-play-state: paused !important;
}

.pause-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 30, 40, 0.55);
  align-items: center;
  justify-content: center;
}
.pause-overlay.show { display: flex; }
.pause-panel {
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 2rem 2.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  text-align: center;
  width: 90%;
  max-width: 320px;
}
.pause-panel h2 { margin: 0 0 1rem; }

.clouds {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(ellipse 40px 18px at 10% 20%, rgba(255,255,255,0.8), transparent),
    radial-gradient(ellipse 55px 20px at 45% 35%, rgba(255,255,255,0.7), transparent),
    radial-gradient(ellipse 35px 16px at 75% 15%, rgba(255,255,255,0.75), transparent),
    radial-gradient(ellipse 50px 18px at 92% 40%, rgba(255,255,255,0.7), transparent);
  background-repeat: repeat-x;
  background-size: 900px 300px;
  animation: cloud-drift 40s linear infinite;
}
@keyframes cloud-drift {
  from { background-position: 0 0, 0 0, 0 0, 0 0; }
  to { background-position: -900px 0, -900px 0, -900px 0, -900px 0; }
}

.ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 34px;
  background: repeating-linear-gradient(
    90deg,
    var(--ground) 0 40px,
    var(--ground-light) 40px 80px
  );
  border-top: 4px solid #4a3320;
}

.player {
  position: absolute;
  left: 60px;
  bottom: 34px;
  font-size: 3rem;
  transform-origin: bottom center;
  transition: transform 0.05s linear;
  z-index: 5;
  filter: drop-shadow(0 4px 3px rgba(0,0,0,0.25));
}
.player-glyph { display: inline-block; }
.player-glyph.flip { transform: scaleX(-1); }

.player.running { animation: run-bob 0.3s ease-in-out infinite alternate; }
@keyframes run-bob {
  from { transform: translateY(0) rotate(-2deg); }
  to { transform: translateY(-4px) rotate(2deg); }
}
.player.jumping { animation: jump-arc 0.55s ease-out; }
@keyframes jump-arc {
  0% { transform: translateY(0); }
  40% { transform: translateY(-95px) rotate(-8deg); }
  100% { transform: translateY(0); }
}
/* Golden-heart bonus: jump + karate kick. The "contact" snap sits at 50%
   so it can be timed to coincide with the obstacle's position (see
   SUPER_JUMP_PEAK_RATIO in game.js). */
.player.super-jumping { animation: super-jump-kick 0.85s ease-out; }
@keyframes super-jump-kick {
  0%   { transform: translateY(0) rotate(0deg) scale(1); }
  28%  { transform: translateY(-165px) rotate(-14deg) scale(1.1); }
  50%  { transform: translateY(-195px) rotate(30deg) scaleX(1.35) scaleY(0.85); }
  68%  { transform: translateY(-155px) rotate(-10deg) scale(1.1); }
  100% { transform: translateY(0) rotate(0deg) scale(1); }
}
.player.hit { animation: hit-shake 0.4s ease; }
@keyframes hit-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-6deg); }
  40% { transform: translateX(8px) rotate(6deg); }
  60% { transform: translateX(-5px) rotate(-3deg); }
  80% { transform: translateX(5px) rotate(3deg); }
}

.player-glyph.heart-glow { animation: heart-glow-pulse 1s ease-out; }
@keyframes heart-glow-pulse {
  0%   { filter: drop-shadow(0 0 0 transparent); }
  25%  { filter: drop-shadow(0 0 10px #ffd700) drop-shadow(0 0 22px #fff59d); }
  60%  { filter: drop-shadow(0 0 14px #ffd700) drop-shadow(0 0 26px #fff59d); }
  100% { filter: drop-shadow(0 0 0 transparent); }
}

.kick-impact {
  position: absolute;
  left: 130px;
  bottom: 175px;
  font-size: 2rem;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}
.kick-impact.show { animation: kick-impact-burst 0.4s ease-out; }
@keyframes kick-impact-burst {
  0%   { opacity: 0; transform: scale(0.3) rotate(0deg); }
  35%  { opacity: 1; transform: scale(1.5) rotate(20deg); }
  100% { opacity: 0; transform: scale(1.9) rotate(35deg); }
}

.obstacle {
  position: absolute;
  bottom: 34px;
  display: none;
  flex-direction: column;
  align-items: center;
  z-index: 4;
  text-align: center;
}
.obstacle.active { display: flex; }
.obstacle-word {
  background: rgba(255,255,255,0.95);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 4px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.obstacle-emoji { font-size: 2.4rem; }

.obstacle.golden .obstacle-word {
  background: linear-gradient(135deg, #fff6d0, var(--gold));
  box-shadow: 0 0 14px 3px rgba(255,215,0,0.8);
}
.obstacle.golden { animation: float-heart 1.2s ease-in-out infinite; }
@keyframes float-heart {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.hit-flash {
  position: absolute;
  inset: 0;
  background: rgba(231, 76, 60, 0.45);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}
.hit-flash.flash { animation: flash-fade 0.35s ease; }
@keyframes flash-fade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.sky-heart {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 1.6rem;
  opacity: 0;
}
.sky-heart.show { animation: heart-appear 0.6s ease; opacity: 1; }
@keyframes heart-appear {
  0% { transform: scale(0) rotate(0deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(15deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.answer-row {
  display: flex;
  gap: 0.7rem;
  width: 100%;
  max-width: 900px;
  padding: 0.8rem 1rem 1rem;
}
.answer-btn {
  flex: 1;
  padding: 0.9rem 0.5rem;
  font-size: 1.15rem;
  font-weight: 800;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #fff;
  transition: transform 0.08s, opacity 0.15s;
}
.answer-btn:active { transform: translateY(2px); }
.answer-btn[data-article="der"] { background: var(--der-color); box-shadow: 0 4px 0 #2f6ba8; }
.answer-btn[data-article="die"] { background: var(--die-color); box-shadow: 0 4px 0 #a83a5e; }
.answer-btn[data-article="das"] { background: var(--das-color); box-shadow: 0 4px 0 #327d57; }
.answer-btn kbd {
  background: rgba(255,255,255,0.35);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.8rem;
  margin-left: 4px;
}
.answer-btn.correct-flash { animation: correct-pulse 0.35s ease; }
.answer-btn.wrong-flash { animation: wrong-pulse 0.35s ease; }
@keyframes correct-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 6px rgba(255,255,255,0.5); }
  100% { transform: scale(1); }
}
@keyframes wrong-pulse {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.answer-row.disabled .answer-btn { opacity: 0.5; pointer-events: none; }

@keyframes pop {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Game over */
.final-score { font-size: 1.4rem; font-weight: 800; margin: 0.3rem 0 0.6rem; }
.new-highscore {
  color: #d98c00;
  font-weight: 700;
  animation: pop 0.4s ease;
}
.mistake-review { margin-top: 1rem; text-align: left; }
.mistake-review h3 { margin-bottom: 0.4rem; font-size: 1rem; }
.mistake-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 180px; overflow-y: auto; }
.mistake-item {
  background: #f6f2f2;
  border-left: 4px solid var(--danger);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.mistake-item .word { font-weight: 700; }
.mistake-item .you { color: var(--danger); }
.mistake-item .correct { color: #2e8b57; }
.gameover-buttons { margin-top: 1rem; }
.no-mistakes { color: #5a6b78; font-size: 0.9rem; }

/* Leaderboard */
.leaderboard-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 0.8rem;
}
.lb-tab {
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: 999px;
  background: #e9edf1;
  cursor: pointer;
  font-weight: 700;
}
.lb-tab.active { background: var(--accent2); color: #fff; }
.leaderboard-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  text-align: left;
  max-height: 320px;
  overflow-y: auto;
}
.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  margin-bottom: 0.3rem;
  background: #f4f7f9;
}
.leaderboard-list li.me { background: #fff4cc; font-weight: 700; }
.lb-rank { width: 24px; font-weight: 800; color: #5a6b78; }
.lb-name { flex: 1; }
.lb-score { font-weight: 800; }
.lb-empty { color: #5a6b78; text-align: center; padding: 1rem 0; }

@media (max-width: 480px) {
  .panel { padding: 1.4rem 1.2rem; }
  .game-area { height: 240px; }
  .player { font-size: 2.3rem; }
  .obstacle-emoji { font-size: 1.8rem; }
  h1 { font-size: 1.7rem; }
}
