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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #5c94fc;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* ===== SCREENS ===== */
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: block; }

/* ===== WIN / GAME-OVER PANELS ===== */
#screen-win, #screen-over {
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #5c94fc 0%, #3a6fd8 100%);
}
#screen-win.active, #screen-over.active {
  display: flex;
}

.panel {
  background: #fff8e6;
  border: 4px solid #d8a600;
  border-radius: 18px;
  box-shadow: 0 12px 34px rgba(0,0,0,.35);
  padding: 28px 26px;
  max-width: 380px;
  width: 88%;
  text-align: center;
}
.panel h1 { font-size: 1.7rem; color: #c0392b; margin-bottom: 6px; }
.panel h2 { font-size: 1.5rem; color: #c0392b; margin-bottom: 10px; }
.panel .sub { color: #7a5b00; margin-bottom: 14px; font-size: .95rem; }
.panel .howto { color: #5a4400; font-size: .82rem; line-height: 1.5; margin-bottom: 10px; }
.panel .big-emoji { font-size: 3.2rem; margin-bottom: 6px; }
#win-time, #win-coins { color: #333; font-size: 1rem; margin-bottom: 4px; }
#win-best { color: #2d7a2d; font-weight: 700; font-size: .9rem; margin: 8px 0 4px; }
#resume-modal-body { color: #5a4400; font-size: .9rem; line-height: 1.5; margin-bottom: 10px; }

.big-btn {
  margin-top: 10px;
  background: linear-gradient(180deg, #ff5b3a, #d8341a);
  border: none;
  border-bottom: 4px solid #9c2210;
  border-radius: 12px;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 24px;
  transition: transform .1s;
}
.big-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.big-btn.secondary {
  background: linear-gradient(180deg, #6c8ee0, #3a5cb8);
  border-bottom-color: #26408c;
}
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ===== MENÜ-BILDSCHIRM (Levelauswahl) ===== */
#screen-menu {
  height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #5c94fc 0%, #3a6fd8 100%);
  padding: 18px 16px 30px;
}
#screen-menu header { text-align: center; padding: 6px 0 4px; }
#screen-menu h1 { font-size: 1.8rem; color: #fff; text-shadow: 0 2px 0 #9c2210; }
#screen-menu .sub { color: #ffe8b0; font-size: .85rem; margin-top: 4px; }
#screen-menu .howto {
  color: #fff8e6;
  font-size: .78rem;
  line-height: 1.5;
  text-align: center;
  max-width: 480px;
  margin: 10px auto 14px;
}

.prog-wrap { max-width: 480px; margin: 0 auto 14px; text-align: center; }
.prog-bar {
  height: 10px;
  background: rgba(0,0,0,.25);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 6px;
}
.prog-bar > div {
  height: 100%;
  background: linear-gradient(90deg, #ffd447, #ff9a3c);
  transition: width .4s ease;
}
#progress-text { font-size: .8rem; color: #fff8e6; }

#diff-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 16px;
}
.df-btn {
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff8e6;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: .82rem;
  transition: all .2s;
}
.df-btn:hover, .df-btn.active {
  background: #fff8e6;
  color: #3a5cb8;
  border-color: #fff8e6;
}

#level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
}
.lvl-btn {
  background: rgba(255,255,255,.14);
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 10px;
  padding: 8px 4px 7px;
  text-align: center;
  transition: all .18s;
  color: #fff8e6;
}
.lvl-btn:not(.locked) { cursor: pointer; }
.lvl-btn:not(.locked):hover {
  border-color: #ffd447;
  background: rgba(255,255,255,.28);
  transform: translateY(-2px);
}
.lvl-btn.locked  { opacity: .35; cursor: not-allowed; }
.lvl-btn.done    { background: rgba(45,122,45,.55); border-color: #7ad44e; }
.lvl-btn .lnum   { display: block; font-size: 1.05rem; font-weight: 700; }
.lvl-btn.done .lnum { color: #d6ffcf; }
.lvl-btn .ldiff  { display: block; font-size: .66rem; margin-top: 2px; font-weight: 700; }

/* ===== GAME SCREEN ===== */
#screen-game {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#hud {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 14px;
  background: rgba(0,0,0,.35);
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  letter-spacing: .5px;
  z-index: 20;
  flex-shrink: 0;
}
.hud-item { display: flex; align-items: center; gap: 4px; }
#hud-lives { margin-left: auto; font-size: 1rem; }

#viewport {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  background: linear-gradient(180deg, #5c94fc 0%, #8fb8ff 70%, #a9c8ff 100%);
}

/* Parallax-Hintergrund (Hügel/Wolken) */
#parallax {
  position: absolute;
  top: 0; left: 0;
  width: 6000px;
  height: 100%;
  background-image:
    radial-gradient(28px 18px at 80px 60px, rgba(255,255,255,.85), rgba(255,255,255,0) 70%),
    radial-gradient(34px 20px at 180px 90px, rgba(255,255,255,.75), rgba(255,255,255,0) 70%),
    radial-gradient(26px 16px at 420px 50px, rgba(255,255,255,.8), rgba(255,255,255,0) 70%),
    radial-gradient(30px 18px at 700px 100px, rgba(255,255,255,.7), rgba(255,255,255,0) 70%),
    radial-gradient(160px 70px at 250px 340px, rgba(70,170,80,.55), rgba(70,170,80,0) 72%),
    radial-gradient(200px 90px at 700px 320px, rgba(70,170,80,.5), rgba(70,170,80,0) 72%);
  background-repeat: repeat-x;
  background-size: 900px 100%;
}

#world {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 100%;
  will-change: transform;
}

/* Böden / Lücken werden als getrennte Grasstreifen gezeichnet (siehe game.js) */
.ground-seg {
  position: absolute;
  bottom: 0;
  height: 56px;
  background: linear-gradient(180deg, #6a3d0f 0%, #4a2a08 100%);
  border-top: 6px solid #3fa93f;
}

.platform {
  position: absolute;
  height: 22px;
  background: linear-gradient(180deg, #c87a2e, #8f5117);
  border-top: 5px solid #e0a256;
  border-radius: 4px;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
}

.coin {
  position: absolute;
  width: 22px;
  height: 22px;
  font-size: 20px;
  line-height: 22px;
  text-align: center;
  animation: coinspin 1s linear infinite;
}
@keyframes coinspin {
  0%   { transform: scaleX(1); }
  50%  { transform: scaleX(.15); }
  100% { transform: scaleX(1); }
}
.coin.taken { display: none; }

.enemy {
  position: absolute;
  width: 30px;
  height: 26px;
  background: #8a4b1e;
  border-radius: 15px 15px 4px 4px;
  box-shadow: 0 3px 0 rgba(0,0,0,.3);
}
.enemy::before, .enemy::after {
  content: '';
  position: absolute;
  top: 8px;
  width: 6px; height: 6px;
  background: #fff;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px #222;
}
.enemy::before { left: 5px; }
.enemy::after  { right: 5px; }
.enemy.facing-left::before, .enemy.facing-left::after { top: 8px; }
.enemy.squished {
  transform: scaleY(.15);
  opacity: 0;
  transition: transform .18s ease-in, opacity .18s ease-in;
}
.enemy.dead { display: none; }

#flagpole { position: absolute; bottom: 56px; }
#flagpole .pole {
  position: absolute;
  bottom: 0;
  left: 14px;
  width: 6px;
  height: 200px;
  background: #ccc;
  border-radius: 3px;
}
#flagpole .flag {
  position: absolute;
  top: -4px;
  left: 4px;
  font-size: 34px;
}

/* ===== SPIELER ===== */
#player {
  position: absolute;
  width: 30px;
  height: 42px;
  transform-origin: center bottom;
  transition: filter .1s;
}
#player .cap    { position: absolute; top: 0;    left: 2px;  width: 26px; height: 10px; background: #e02020; border-radius: 8px 8px 2px 2px; }
#player .face   { position: absolute; top: 8px;  left: 5px;  width: 20px; height: 10px; background: #f4c18a; border-radius: 4px; }
#player .body   { position: absolute; top: 17px; left: 2px;  width: 26px; height: 16px; background: #2050d0; border-radius: 4px; }
#player .leg    { position: absolute; top: 33px; width: 10px; height: 9px; background: #6a3d0f; border-radius: 0 0 4px 4px; }
#player .leg-l  { left: 3px; }
#player .leg-r  { left: 17px; }

#player.facing-left { transform: scaleX(-1); }
#player.walking .leg-l { animation: walk 0.28s linear infinite; }
#player.walking .leg-r { animation: walk 0.28s linear infinite reverse; }
@keyframes walk {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-2px) rotate(18deg); }
}
#player.jumping .leg-l, #player.jumping .leg-r { transform: translateY(-1px) rotate(-10deg); }
#player.hurt { filter: brightness(2) saturate(0); animation: blink .15s steps(1) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ===== TOUCH-STEUERUNG ===== */
#touch-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 14px 22px;
  pointer-events: none;
  z-index: 30;
}
.touch-btn {
  pointer-events: auto;
  width: 88px; height: 88px;
  border-radius: 50%;
  background: rgba(255,255,255,.32);
  border: 3px solid rgba(255,255,255,.7);
  color: #fff;
  font-size: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.touch-btn:active, .touch-btn.pressed { background: rgba(255,255,255,.6); }
#btn-jump  { width: 104px; height: 104px; font-size: 2.8rem; }

.left-pad { display: flex; gap: 16px; }

/* ===== RESPONSIVE ===== */
@media (min-width: 900px) {
  .touch-btn { width: 60px; height: 60px; font-size: 1.5rem; opacity: .55; }
  #btn-jump { width: 72px; height: 72px; font-size: 1.9rem; }
}

/* ===== WEITERSPIELEN-MODAL ===== */
#resume-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.6);
  z-index: 9000;
}
#resume-modal-overlay.active { display: flex; }
