/* ============================================
   SLOTHY'S 1×1 ABENTEUER — Design System
   ============================================ */

:root {
  --color-primary: #4CAF50;
  --color-primary-dark: #388E3C;
  --color-secondary: #FFC107;
  --color-secondary-dark: #FFB300;
  --color-accent: #FF5722;
  --color-danger: #F44336;
  --color-text: #FFF8E1;
  --color-text-dark: #3E2723;
  --color-bg-overlay: rgba(10, 30, 15, 0.85);

  --font-game: 'Fredoka', system-ui, sans-serif;

  --stage-height: 33vh;
  --branch-y: 55%;
  --sloth-size: 100px;
  --sloth-start: 10%;
  --sloth-end: 85%;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(76, 175, 80, 0.5);

  --anim-fast: 0.2s;
  --anim-normal: 0.4s;
  --anim-slow: 2.5s;
}

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap');

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

body {
  font-family: var(--font-game);
  color: var(--color-text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  background: #0a1e0f;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

button { font-family: var(--font-game); border: none; cursor: pointer; outline: none; }
input  { font-family: var(--font-game); border: none; outline: none; }

/* ===== STAGE ===== */
.stage {
  height: var(--stage-height);
  position: relative;
  overflow: hidden;
  border-bottom: 6px solid #5D4037;
}

.jungle-background {
  position: absolute;
  inset: 0;
  background: url('../assets/hintergrund.png') center/cover no-repeat;
  filter: saturate(0.3) brightness(0.25) contrast(1.5);
  will-change: transform;
}

.jungle-background::before,
.jungle-background::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 50%;
  pointer-events: none;
}

.jungle-background::before {
  top: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.3) 100%);
}

.jungle-background::after {
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
}

/* ===== SCENE ===== */
.scene { position: absolute; inset: 0; z-index: 10; }

/* ===== BRANCH ===== */
.branch {
  position: absolute;
  bottom: var(--branch-y);
  left: 5%; right: 5%;
  height: 28px;
  background: linear-gradient(180deg, #6D4C41 0%, #5D4037 50%, #4E342E 100%);
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.1);
  z-index: 20;
}

.branch::before {
  content: '';
  position: absolute;
  inset: 3px 10px;
  background: repeating-linear-gradient(90deg, transparent, transparent 20px, rgba(0,0,0,0.15) 20px, rgba(0,0,0,0.15) 22px);
  border-radius: 8px;
}

/* ===== SLOTH ===== */
.sloth {
  position: absolute;
  bottom: calc(var(--branch-y) + 4px);
  left: var(--sloth-start);
  transition: left var(--anim-slow) ease-in-out;
  z-index: 50;
  transform-origin: top center;
  display: block;
  background: transparent !important;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: smooth;
}

/* Hängen: Sloth hängt unter dem Ast */
.sloth.hanging {
  bottom: calc(var(--branch-y) - var(--sloth-size) + 22px);
}

/* Klettern: Sloth sitzt auf dem Ast */
.sloth.climbing {
  bottom: calc(var(--branch-y) - 16px);
}

/* ===== BANANA ===== */
.banana {
  position: absolute;
  bottom: calc(var(--branch-y) + 16px);
  right: 8%;
  width: 50px;
  height: 50px;
  z-index: 40;
  animation: bananaGlow 2s ease-in-out infinite;
}

@keyframes bananaGlow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(255,215,0,0.4)); }
  50% { filter: drop-shadow(0 0 16px rgba(255,215,0,0.8)); }
}

/* ===== SCORE ===== */
.score-container {
  position: absolute;
  top: 12px; right: 16px;
  background: var(--color-bg-overlay);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 1.2rem;
  font-weight: 600;
  z-index: 100;
  border: 2px solid rgba(255,255,255,0.1);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
}

/* ===== GAME AREA ===== */
.game-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 48px 16px 0;
  gap: 4px;
  position: relative;
  overflow: hidden;
}

.top-controls {
  position: absolute;
  top: 10px; left: 10px;
  display: flex; gap: 8px;
  z-index: 100;
}

.control-btn {
  background: var(--color-bg-overlay);
  color: var(--color-text);
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid rgba(255,255,255,0.15);
  transition: background var(--anim-fast);
}

.control-btn:hover { background: rgba(20, 40, 20, 0.9); }

.problem-container {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 700;
  color: var(--color-text);
  background: var(--color-bg-overlay);
  padding: 10px 32px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255,255,255,0.08);
  text-align: center;
  min-width: 200px;
  letter-spacing: 2px;
}

.timer-container {
  width: min(80%, 320px);
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--color-primary);
  border-radius: 6px;
  transition: width 0.1s linear, background-color 0.3s;
  will-change: width;
}

.message {
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  min-height: 24px;
}

.message.correct { color: var(--color-success); }
.message.wrong   { color: var(--color-danger); }
.message.hint    { color: var(--color-secondary); }

.input-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 360px;
}

.answer-input {
  font-size: 1.4rem;
  width: 110px;
  text-align: center;
  padding: 4px;
  color: var(--color-text);
  background: rgba(255,255,255,0.08);
  border: 3px solid var(--color-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
}

.key-btn {
  background: rgba(255,255,255,0.08);
  color: var(--color-text);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.1);
  transition: all var(--anim-fast);
}

.key-btn:hover { background: rgba(255,255,255,0.15); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.key-btn:active { transform: translateY(0); background: rgba(255,255,255,0.05); }

.submit-btn {
  background: var(--color-primary);
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 6px;
  border-radius: 12px;
  width: 100%;
  box-shadow: var(--shadow-md);
  transition: all var(--anim-fast);
  letter-spacing: 1px;
}

.submit-btn:hover { background: var(--color-primary-dark); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.submit-btn:active { transform: translateY(0); }

/* ===== SCREENS ===== */
.overlay-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  background: var(--color-bg-overlay);
  backdrop-filter: blur(16px);
}

.overlay-screen.hidden { display: none; }

.overlay-screen h1 {
  font-size: clamp(2rem, 6vw, 3.2rem);
  text-align: center;
  margin-bottom: 16px;
  color: var(--color-primary);
  text-shadow: 0 0 30px rgba(76,175,80,0.4);
}

.overlay-screen h2 {
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  text-align: center;
  margin-bottom: 12px;
  color: var(--color-secondary);
}

.overlay-screen p {
  font-size: clamp(1rem, 3vw, 1.2rem);
  text-align: center;
  margin-bottom: 16px;
  max-width: 560px;
  line-height: 1.6;
  color: rgba(255,248,225,0.85);
}

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
  max-width: 640px;
  width: 100%;
}

.mode-btn {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 14px;
  background: rgba(255,255,255,0.06);
  color: var(--color-text);
  border: 2px solid rgba(255,255,255,0.1);
  transition: all var(--anim-fast);
  flex: 1;
  min-width: 160px;
  text-align: center;
}

.mode-btn:hover { background: rgba(255,255,255,0.12); border-color: var(--color-secondary); transform: translateY(-2px); }
.mode-btn.active { background: var(--color-primary); border-color: var(--color-primary); color: white; box-shadow: var(--shadow-glow); }

.custom-mode {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding: 16px;
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  max-width: 400px;
  width: 100%;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
}

.num-select-btn {
  background: rgba(255,255,255,0.06);
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 6px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.08);
  transition: all var(--anim-fast);
}

.num-select-btn:hover { background: rgba(255,255,255,0.12); }
.num-select-btn.selected { background: var(--color-primary); border-color: var(--color-primary); }

.custom-mode-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.custom-mode-buttons button {
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  color: var(--color-text);
  border: 1px solid rgba(255,255,255,0.12);
  transition: all var(--anim-fast);
}

.custom-mode-buttons button:hover { background: rgba(255,255,255,0.14); }

.start-btn, .action-btn {
  font-size: 1.3rem;
  font-weight: 700;
  padding: 14px 36px;
  border-radius: 16px;
  background: var(--color-secondary);
  color: var(--color-text-dark);
  box-shadow: var(--shadow-md);
  transition: all var(--anim-fast);
  margin: 8px;
}

.start-btn:hover, .action-btn:hover { background: var(--color-secondary-dark); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.start-btn:active, .action-btn:active { transform: translateY(0); }

.action-btn {
  background: rgba(255,255,255,0.1);
  color: var(--color-text);
  border: 2px solid rgba(255,255,255,0.15);
}

.action-btn:hover { background: rgba(255,255,255,0.18); }

/* Sloth Animation States */
.sloth.cheering { animation: slothCheer 0.6s ease-in-out infinite alternate; }

.sloth.falling {
  animation: slothFall 1.2s ease-in forwards;
  pointer-events: none;
}

.sloth.climbing {
  animation: slothClimb 1.5s ease-out forwards;
}

.sloth.idling { animation: slothSway 3s ease-in-out infinite alternate; }

@keyframes slothCheer {
  0% { transform: rotate(-4deg) translateY(0); }
  100% { transform: rotate(4deg) translateY(-6px); }
}

@keyframes slothFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  30%  { transform: translateY(15vh) rotate(120deg); opacity: 0.8; }
  60%  { transform: translateY(30vh) rotate(240deg); opacity: 0.5; }
  100% { transform: translateY(50vh) rotate(360deg); opacity: 0; }
}

@keyframes slothClimb {
  0%   { transform: translateY(4px); }
  100% { transform: translateY(0); }
}

@keyframes slothSway {
  0% { transform: rotate(-2deg); }
  100% { transform: rotate(2deg); }
}

/* Confetti */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0;
}

.confetti.active {
  animation: confettiFall 2s ease-out forwards;
}

@keyframes confettiFall {
  0%   { opacity: 1; transform: translateY(-20px) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(60vh) rotate(720deg) scale(0.5); }
}

/* Points Popup */
.points-popup {
  position: absolute;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-secondary);
  pointer-events: none;
  animation: pointsFloat 1s ease-out forwards;
  z-index: 200;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

@keyframes pointsFloat {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}

/* Screen Shake */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.stage.shake { animation: shake 0.4s ease-out; }

/* Pause Screen */
.pause-screen { z-index: 600; }
.pause-screen h2 { color: var(--color-secondary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  :root { --sloth-size: 72px; }

  .problem-container { font-size: 1.8rem; padding: 12px 24px; }
  .key-btn { font-size: 1.2rem; padding: 14px 8px; }
  .answer-input { font-size: 1.6rem; width: 120px; }
  .mode-btn { font-size: 0.95rem; padding: 10px 16px; min-width: 130px; }
  .score-container { font-size: 1rem; padding: 6px 14px; }
  .top-controls { top: 6px; left: 6px; }
  .control-btn { font-size: 0.75rem; padding: 5px 10px; }
}

/* Höhen-basierte Anpassungen — Submit-Button immer sichtbar */
@media (max-height: 720px) {
  :root { --stage-height: 36vh; }
  .game-area { gap: 8px; padding: 12px 16px; }
  .problem-container { padding: 10px 24px; }
  .key-btn { padding: 12px 8px; }
  .submit-btn { padding: 11px; }
  .message { min-height: 28px; font-size: 1.1rem; }
}

@media (max-height: 600px) {
  :root { --stage-height: 28vh; --sloth-size: 64px; }
  .game-area { gap: 6px; padding: 8px 12px; }
  .problem-container { padding: 8px 20px; font-size: 1.6rem; }
  .key-btn { padding: 9px 8px; font-size: 1.1rem; }
  .submit-btn { padding: 9px; font-size: 1.1rem; }
  .answer-input { font-size: 1.4rem; width: 110px; padding: 7px; }
  .message { min-height: 22px; font-size: 0.95rem; }
  .timer-container { height: 9px; }
}
