/* Sofa Jump'n Run — kindfreundliche Farben (klarer Himmel / Boden) */
:root {
  --sky-top: #5EC8F0;
  --sky-bottom: #B8E8F8;
  --grass: #3D9B4A;
  --dirt: #8B5A2B;
  --ui-bg: rgba(20, 40, 60, 0.82);
  --ui-text: #fff8e7;
  --accent: #E9C46A;
  --danger: #E76F51;
  --ok: #2A9D8F;
  --font: "Trebuchet MS", "Segoe UI", sans-serif;
  --chrome-pad: 0.5rem;
  --chrome-est: 7.5rem; /* Kopfzeile + HUD grob */
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  background: #1a2a3a;
  font-family: var(--font);
  color: var(--ui-text);
}

body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  margin: 0;
  background:
    radial-gradient(ellipse at 20% 0%, #2a4a5a 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, #1a3040 0%, transparent 45%),
    #152535;
}

.wrap {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: var(--chrome-pad) clamp(0.35rem, 1.2vw, 0.85rem);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-sizing: border-box;
}

header.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  padding: 0.15rem 0.1rem;
  flex: 0 0 auto;
}

.brand {
  font-size: clamp(1.25rem, 3.2vw, 2.2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-shadow: 0 2px 0 #8a6a20;
}

.hint {
  font-size: clamp(0.8rem, 1.6vw, 0.95rem);
  opacity: 0.92;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-frame {
  position: relative;
  /* Volle Fensterbreite; Höhe auf Viewport begrenzen (Letterbox bei Bedarf) */
  width: min(
    100%,
    calc((100dvh - var(--chrome-est) - 2 * var(--chrome-pad)) * 16 / 9)
  );
  max-width: 100%;
  max-height: calc(100dvh - var(--chrome-est) - 2 * var(--chrome-pad));
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

@supports not (height: 100dvh) {
  .stage-frame {
    width: min(
      100%,
      calc((100vh - var(--chrome-est) - 2 * var(--chrome-pad)) * 16 / 9)
    );
    max-height: calc(100vh - var(--chrome-est) - 2 * var(--chrome-pad));
  }
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  border: 3px solid #0e1a24;
  background: var(--sky-top);
  image-rendering: auto;
  cursor: pointer;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* On-Screen-Steuerung: unter dem Menü-Overlay (z-index 10), über dem Canvas */
.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0.55rem 0.65rem 0.7rem;
  pointer-events: none;
  border-radius: 10px;
}

.touch-controls[hidden] {
  display: none !important;
}

.touch-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: flex-end;
  pointer-events: auto;
  max-width: 46%;
}

.touch-cluster-right {
  justify-content: flex-end;
}

.touch-btn {
  appearance: none;
  border: 2px solid rgba(255, 248, 231, 0.35);
  background: rgba(20, 40, 60, 0.55);
  color: var(--ui-text);
  font: inherit;
  font-weight: 800;
  font-size: 1.15rem;
  min-width: 3.1rem;
  min-height: 3.1rem;
  padding: 0.35rem 0.55rem;
  border-radius: 14px;
  cursor: pointer;
  /* Cluster hat pointer-events:auto — Button explizit, damit nichts durchrutscht */
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  /* Kein :active-Transform hier — verschiebt Hitbox unter dem Finger und
     feuerte früher pointerleave → Release im selben Tap (Buttons wirkten tot).
     Visuelles Feedback nur über .active aus JS. */
}

.touch-btn-jump {
  min-width: 4.6rem;
  min-height: 3.4rem;
  background: rgba(233, 196, 106, 0.72);
  color: #1a2a1a;
  border-color: rgba(138, 106, 32, 0.55);
}

.touch-btn-down {
  opacity: 0.92;
  font-size: 1rem;
}

.touch-btn.active {
  /* Nur Filter/Schatten — kein translate (Hitbox bleibt unter dem Finger) */
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  filter: brightness(1.08);
}

@media (max-width: 520px) {
  .touch-btn {
    min-width: 2.75rem;
    min-height: 2.75rem;
    font-size: 1rem;
  }
  .touch-btn-jump {
    min-width: 4rem;
    min-height: 3rem;
  }
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: clamp(0.75rem, 1.5vw, 0.9rem);
  opacity: 0.9;
  padding: 0.1rem 0.15rem 0.25rem;
  flex: 0 0 auto;
}

@media (max-height: 480px), (orientation: landscape) and (max-width: 900px) {
  :root {
    --chrome-est: 4.2rem;
    --chrome-pad: 0.25rem;
  }
  header.bar .hint {
    display: none;
  }
  .hud {
    gap: 0.35rem 0.75rem;
  }
  .brand {
    font-size: 1.1rem;
  }
}

.hud kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  font-family: inherit;
  font-size: 0.85em;
}

/* Overlay: Start / Gewonnen / Verloren */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 30, 0.55);
  z-index: 10;
  padding: 1rem;
}

.overlay[hidden] {
  display: none !important;
}

.panel {
  background: var(--ui-bg);
  color: var(--ui-text);
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 248, 231, 0.15);
  max-height: min(92vh, 900px);
  overflow-y: auto;
}

.panel h1 {
  font-size: 1.85rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.panel h1.win {
  color: #7ee0c8;
}

.panel h1.lose {
  color: #ffb4a2;
}

.panel p {
  line-height: 1.45;
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  align-items: center;
}

.panel button {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #1a2a1a;
  font: inherit;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 0.65rem 1.4rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 #8a6a20;
}

.panel button#btn-level2 {
  background: #7ee0c8;
  box-shadow: 0 4px 0 #2a7a6a;
  color: #0f2a24;
}

.panel button#btn-level3 {
  background: #9bb7e8;
  box-shadow: 0 4px 0 #4a628a;
  color: #142238;
}

.panel button#btn-level2.locked,
.panel button#btn-level3.locked,
.panel button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.25);
}

.panel button:hover:not(:disabled),
.panel button:focus-visible:not(:disabled) {
  filter: brightness(1.06);
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.panel button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8a6a20;
}

.panel button#btn-level2:active:not(:disabled) {
  box-shadow: 0 2px 0 #2a7a6a;
}

.panel button#btn-level3:active:not(:disabled) {
  box-shadow: 0 2px 0 #4a628a;
}

.btn-row.has-three {
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.steuer-liste {
  text-align: left;
  margin: 0.75rem auto 1rem;
  max-width: 320px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.steuer-liste li {
  margin: 0.2rem 0;
}

.panel .version {
  margin: 1rem 0 0;
  font-size: 0.8rem;
  opacity: 0.65;
  letter-spacing: 0.04em;
}

.panel button.btn-secondary,
.panel button#btn-scores {
  background: transparent;
  color: var(--ui-text);
  border: 2px solid rgba(255, 248, 231, 0.35);
  box-shadow: none;
  font-size: 1rem;
  padding: 0.55rem 1.1rem;
}

.panel button.btn-secondary:active:not(:disabled),
.panel button#btn-scores:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

.name-block {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  margin: 0 auto 1rem;
  max-width: 280px;
  text-align: left;
}

.name-block[hidden] {
  display: none !important;
}

.name-block label {
  font-size: 0.95rem;
  font-weight: 700;
}

.name-block input {
  font: inherit;
  font-size: 1.1rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 2px solid rgba(255, 248, 231, 0.25);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ui-text);
}

.name-block input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.name-block input.invalid {
  border-color: var(--danger);
}

.scores-panel {
  margin: 0.25rem 0 1rem;
  text-align: left;
}

.scores-panel[hidden] {
  display: none !important;
}

.score-heading {
  font-size: 1rem;
  margin: 0.75rem 0 0.35rem;
  color: var(--accent);
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin-bottom: 0.5rem;
}

.score-table th,
.score-table td {
  padding: 0.28rem 0.4rem;
  border-bottom: 1px solid rgba(255, 248, 231, 0.12);
  text-align: left;
}

.score-table th {
  opacity: 0.75;
  font-weight: 700;
}

.score-table td:first-child,
.score-table th:first-child {
  width: 3rem;
  text-align: center;
}

.score-empty,
.score-hint,
.score-source,
.score-stats {
  font-size: 0.9rem;
  opacity: 0.9;
  margin: 0.4rem 0;
}

.score-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.score-tab {
  appearance: none;
  border: 1px solid rgba(255, 248, 231, 0.3);
  background: rgba(0, 0, 0, 0.2);
  color: var(--ui-text);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
}

.score-tab.active {
  background: var(--accent);
  color: #1a2a1a;
  border-color: transparent;
  font-weight: 700;
}
