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

html,
body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f4efe4;
  color: #3b3228;
  /* Board + HUD: fast volle Handybreite, auf 13″-iPad groß mit Luft am Rand. */
  --play-max: 57.5rem;
  --play-chrome: 13.75rem;
}

.app {
  position: relative;
  min-height: 100%;
  min-height: 100dvh;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 200ms ease, visibility 200ms ease;
  z-index: 0;
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 1;
}

.screen-play {
  justify-content: center;
  gap: 0;
}

.play-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: min(
    100%,
    var(--play-max),
    calc(100dvh - var(--play-chrome) - env(safe-area-inset-top) - env(safe-area-inset-bottom))
  );
  max-height: 100%;
}

.logo {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.logo-dot {
  width: 52px;
  height: 52px;
  border-radius: 50%;
}

.logo-dot--red {
  background: #ff5a5f;
}

.logo-dot--blue {
  background: #3d9be9;
}

h1,
h2 {
  font-weight: 700;
  letter-spacing: 0.02em;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.4rem;
  margin-bottom: 16px;
}

.tagline {
  margin: 8px 0 28px;
  color: #7a6e62;
}

.map-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.map-inner h2 {
  margin-bottom: 24px;
}

.btn {
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.btn--primary {
  background: #3d9be9;
  color: #fff;
  min-width: 180px;
}

.btn--secondary {
  background: #2ec4b6;
  color: #fff;
}

.btn--ghost {
  background: transparent;
  color: #7a6e62;
  margin-top: 16px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn--icon {
  min-width: 48px;
  width: 48px;
  padding: 0;
  background: #efe6d6;
  color: #3b3228;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.game-hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.5fr) 48px 48px;
  gap: 6px;
  width: 100%;
  align-items: center;
}

.hud-cell {
  background: #efe6d6;
  border-radius: 14px;
  padding: 8px 10px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-label {
  font-size: 0.7rem;
  color: #7a6e62;
}

.hud-cell strong {
  font-size: 1.05rem;
  line-height: 1.2;
}

.hud-cell--objective strong {
  font-size: 0.85rem;
}

.hud-cell.is-flash {
  animation: hud-flash 160ms ease-in-out 3;
}

@keyframes hud-flash {
  50% {
    background: #ff5a5f;
    color: #fff;
  }
}

.start-actions {
  width: min(100%, 280px);
}

.start-actions .btn--ghost {
  margin-top: 0;
}

.world-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 360px);
}

.world-btn {
  min-height: 72px;
  border: 0;
  border-radius: 18px;
  background: var(--accent, #3d9be9);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  padding: 14px 18px;
}

.world-btn:disabled {
  background: #cfc6b8;
  color: #8a8175;
}

.world-btn__name {
  display: block;
  font-size: 1.2rem;
}

.world-btn__meta {
  font-size: 0.85rem;
  opacity: 0.9;
}

.lives-bar,
.powerup-bar,
.powerup-hint {
  width: 100%;
}

.lives-bar {
  min-height: 28px;
  font-size: 0.85rem;
  color: #7a6e62;
  text-align: center;
}

.lives-bar.is-hidden {
  display: none;
}

.powerup-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.powerup-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  flex: 1;
  max-width: 120px;
  border: 0;
  border-radius: 16px;
  padding: 4px 8px 6px;
  background: #efe6d6;
  color: #3b3228;
  font: inherit;
  cursor: pointer;
}

.powerup-btn__icon {
  width: 44px;
  height: 44px;
  object-fit: contain;
  pointer-events: none;
}

.powerup-btn__count {
  position: absolute;
  top: 4px;
  right: 8px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #3b3228;
  color: #fffaf2;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
}

.powerup-btn.is-on {
  background: #d7ecfb;
  box-shadow: 0 0 0 2px #3d9be9;
}

.powerup-btn.is-on .powerup-btn__count {
  background: #3d9be9;
}

.powerup-btn:disabled {
  opacity: 0.45;
}

.powerup-hint {
  font-size: 0.85rem;
  color: #7a6e62;
  min-height: 1.2em;
}

.toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  margin: 8px 0 16px;
  color: #5c5349;
  font-size: 0.95rem;
}

.toggle input {
  margin-top: 4px;
  width: 18px;
  height: 18px;
}

.settings-lives,
.intro-lives,
.win-charges {
  font-size: 0.9rem;
  color: #7a6e62;
}

.board {
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
  overscroll-behavior: none;
  border-radius: 18px;
  background: #efe6d6;
  box-shadow: 0 10px 28px rgba(80, 60, 30, 0.12);
  overflow: hidden;
}

.board canvas {
  display: block;
  touch-action: none;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 520px);
  max-height: calc(100dvh - 160px);
  overflow: auto;
  touch-action: pan-y;
  padding: 4px;
}

.level-btn {
  position: relative;
  min-height: 88px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.level-btn--1 {
  background: #ff5a5f;
}

.level-btn--2 {
  background: #3d9be9;
}

.level-btn--3 {
  background: #ffc145;
  color: #3b3228;
}

.level-btn--4 {
  background: #2ec4b6;
}

.level-btn:disabled {
  background: #cfc6b8;
  color: #8a8175;
  cursor: default;
}

.level-btn__num {
  font-size: 1.5rem;
}

.level-btn__lock {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 1rem;
}

.level-btn__stars {
  display: block;
  margin-top: 6px;
  letter-spacing: 2px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: rgba(59, 50, 40, 0.35);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 200ms ease, visibility 200ms ease;
  z-index: 5;
}

.overlay.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.panel {
  width: min(100%, 360px);
  background: #fffaf2;
  border-radius: 22px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(60, 40, 20, 0.18);
}

.panel p {
  margin: 10px 0 20px;
  color: #5c5349;
  line-height: 1.4;
}

.win-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 2rem;
  color: #ffc145;
  min-height: 40px;
}

.win-star {
  display: inline-block;
  opacity: 0;
  transform: scale(0.4);
  animation: star-pop 280ms ease forwards;
}

.win-score {
  font-weight: 700;
  color: #3b3228;
}

@keyframes star-pop {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (min-width: 768px) {
  body {
    --play-max: 58.5rem;
  }

  .screen {
    padding-top: max(20px, env(safe-area-inset-top));
    padding-right: max(28px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(28px, env(safe-area-inset-left));
  }

  .logo-dot {
    width: 64px;
    height: 64px;
  }

  h1 {
    font-size: 2.55rem;
  }

  h2 {
    font-size: 1.7rem;
  }

  .tagline {
    font-size: 1.15rem;
    margin-bottom: 36px;
  }

  .btn--primary,
  .btn--secondary {
    min-height: 56px;
    min-width: 220px;
    font-size: 1.05rem;
  }

  .start-actions {
    width: min(100%, 340px);
  }

  .world-grid {
    width: min(100%, 520px);
    gap: 16px;
  }

  .world-btn {
    min-height: 92px;
    padding: 18px 22px;
    border-radius: 22px;
  }

  .world-btn__name {
    font-size: 1.45rem;
  }

  .level-grid {
    width: min(100%, 760px);
    gap: 14px;
    max-height: calc(100dvh - 180px);
  }

  .level-btn {
    min-height: 108px;
    border-radius: 22px;
  }

  .level-btn__num {
    font-size: 1.75rem;
  }

  .hud-cell {
    min-height: 54px;
    padding: 10px 14px;
    border-radius: 16px;
  }

  .hud-label {
    font-size: 0.78rem;
  }

  .hud-cell strong {
    font-size: 1.2rem;
  }

  .hud-cell--objective strong {
    font-size: 0.95rem;
  }

  .powerup-btn {
    min-height: 64px;
    max-width: 148px;
    border-radius: 18px;
  }

  .powerup-btn__icon {
    width: 52px;
    height: 52px;
  }

  .panel {
    width: min(100%, 420px);
    padding: 32px 28px;
    border-radius: 26px;
  }

  .board {
    border-radius: 24px;
    box-shadow: 0 16px 40px rgba(80, 60, 30, 0.14);
  }
}

@media (min-width: 1024px) {
  body {
    --play-max: 60rem;
  }

  .world-grid {
    width: min(100%, 560px);
  }

  .level-grid {
    width: min(100%, 840px);
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 1.6rem;
  }

  .hud-cell {
    padding: 6px;
    min-height: 44px;
  }

  .hud-cell strong {
    font-size: 0.95rem;
  }

  .hud-cell--objective strong {
    font-size: 0.72rem;
  }

  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
  }
}
