/* =============================================================
   Tiger Jump & Run -- Aussehen der Seite
   Aufgebaut fuer Desktop UND Handy (Touch + App-Vollbild).
   ============================================================= */

:root {
  --ui-bg: #14203a;
  --gold: #ffd166;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;          /* kein Pull-to-Refresh im Spiel */
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  background: linear-gradient(180deg, #1b2a4a 0%, #2b3d63 100%);
  color: #fefae0;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 1px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
}

/* --- Spielfeld: behaelt immer 16:9 und passt in den Bildschirm --- */
#game-wrapper {
  position: relative;
  aspect-ratio: 800 / 450;
  width: min(100%, 1100px);
  max-height: 100%;
  /* Falls die Hoehe der Engpass ist, ueber die Breite zurueckrechnen */
  max-width: min(100%, calc((100dvh - 120px) * 800 / 450), 1100px);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #7ec0ee;
  border: 4px solid var(--ui-bg);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  touch-action: none;                  /* kein Scrollen/Zoomen auf dem Canvas */
}

/* --- Knoepfe oben rechts --- */
#topButtons {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 6;
}

#topButtons button {
  width: 38px;
  height: 38px;
  font-size: 17px;
  border: none;
  border-radius: 50%;
  background: rgba(20, 32, 58, 0.55);
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s;
  touch-action: manipulation;
}

#topButtons button:hover { transform: scale(1.1); }

/* =============================================================
   Touch-Steuerung -- normal versteckt, nur auf Touch-Geraeten an
   ============================================================= */
#touchControls { display: none; }

body.touch #touchControls {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;               /* nur die Knoepfe selbst reagieren */
}

body.touch.ui-open #touchControls { display: none; }   /* nicht ueber Menues */

.touch-left, .touch-right {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  gap: 12px;
}

.touch-left  { left: max(10px, env(safe-area-inset-left)); }
.touch-right { right: max(10px, env(safe-area-inset-right)); }

.touch-btn {
  pointer-events: auto;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 32, 58, 0.34);
  color: rgba(255, 255, 255, 0.85);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(2px);
}

.touch-btn.jump {
  width: 86px;
  height: 86px;
  font-size: 32px;
  background: rgba(255, 190, 61, 0.3);
  border-color: rgba(255, 209, 102, 0.6);
}

.touch-btn.pressed {
  background: rgba(255, 209, 102, 0.55);
  transform: scale(0.94);
}

/* =============================================================
   Overlays (Start, Pause-Menues, Game Over, ...)
   ============================================================= */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(15, 22, 40, 0.88);
  border-radius: 14px;
  text-align: center;
  padding: 18px;
  overflow-y: auto;
  z-index: 8;
}

.overlay.hidden { display: none; }

.overlay h2 {
  font-size: clamp(20px, 4.4vw, 34px);
  margin: 0;
  color: var(--gold);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
}

.overlay p {
  font-size: clamp(12px, 2.3vw, 18px);
  margin: 0;
  line-height: 1.5;
  max-width: 46em;
}

.overlay button {
  margin-top: 6px;
  padding: 12px 26px;
  font-size: clamp(14px, 2.4vw, 17px);
  font-family: inherit;
  font-weight: bold;
  color: #2b2d42;
  background: linear-gradient(180deg, #ffd97a 0%, #ffbe3d 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 #c98a1b;
  transition: transform 0.1s;
  touch-action: manipulation;
}

.overlay button:hover  { transform: translateY(-2px); }
.overlay button:active { transform: translateY(2px); box-shadow: 0 1px 0 #c98a1b; }

.overlay button.secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.overlay button.hidden { display: none; }

#rotateIcon {
  font-size: 46px;
  animation: tilt 1.6s ease-in-out infinite;
}

@keyframes tilt {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-90deg); }
}

#hint {
  margin: 0;
  font-size: 14px;
  opacity: 0.85;
  text-align: center;
  max-width: 900px;
}

/* =============================================================
   Handy / kleine Bildschirme: Spiel fuellt alles aus
   ============================================================= */
@media (max-width: 900px), (pointer: coarse) {
  body { padding: 0; gap: 0; background: #000; }
  h1, #hint { display: none; }

  #game-wrapper {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    aspect-ratio: auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #gameCanvas {
    width: auto;
    height: auto;
    max-width: 100vw;
    max-height: 100dvh;
    aspect-ratio: 800 / 450;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .overlay { border-radius: 0; }
  #topButtons { top: max(6px, env(safe-area-inset-top)); right: max(6px, env(safe-area-inset-right)); }
}

/* Im Vollbild-/App-Modus keine Raender */
@media (display-mode: fullscreen), (display-mode: standalone) {
  body { padding: 0; gap: 0; background: #000; }
  h1, #hint { display: none; }
}

/* =============================================================
   Namenseingabe und Bestenliste
   ============================================================= */
#nameBox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

#nameBox label {
  font-size: clamp(13px, 2.3vw, 17px);
  font-weight: bold;
  color: var(--gold);
}

#playerName {
  width: min(280px, 70vw);
  padding: 10px 16px;
  font-family: inherit;
  font-size: clamp(15px, 2.6vw, 19px);
  font-weight: bold;
  text-align: center;
  color: #2b2d42;
  background: #fff6e0;
  border: 3px solid #ffbe3d;
  border-radius: 999px;
  outline: none;
}

#playerName:focus { border-color: #7fe7ff; }

#playerName::placeholder { color: #b0a68d; font-weight: normal; }

#nameHint {
  font-size: clamp(10px, 1.9vw, 13px) !important;
  opacity: 0.75;
  max-width: 30em;
}

.overlay button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: 0 4px 0 #8a6a2b;
}

.overlay button:disabled:hover { transform: none; }

/* --- Tabelle der besten Spieler --- */
#scoreboardList, .miniboard {
  width: min(430px, 92%);
  max-height: 46%;
  overflow-y: auto;
  font-size: clamp(11px, 2.1vw, 15px);
}

.sb-row {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  margin-bottom: 4px;
}

.sb-row.me {
  background: rgba(255, 209, 102, 0.26);
  outline: 1px solid rgba(255, 209, 102, 0.5);
}

.sb-rank  { font-weight: bold; color: var(--gold); text-align: right; }
.sb-name  { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-score { font-weight: bold; font-variant-numeric: tabular-nums; }
.sb-empty { opacity: 0.7; padding: 10px; }

/* Im Eingabefeld muss Markieren/Tippen erlaubt sein */
#playerName {
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

/* =============================================================
   Flache Bildschirme (Handy quer): Startmenue kompakter machen,
   damit Namensfeld und alle Knoepfe ohne Scrollen sichtbar sind.
   ============================================================= */
@media (max-height: 520px) {
  .overlay { gap: 5px; padding: 10px; justify-content: center; }
  .overlay h2 { font-size: clamp(17px, 3.6vw, 24px); }

  /* Die lange Spielerklaerung ist auf dem Handy verzichtbar */
  #startScreen > p:first-of-type { display: none; }

  #nameHint { display: none; }
  #nameBox { gap: 3px; margin-top: 0; }
  #nameBox label { font-size: 13px; }

  #playerName { padding: 7px 14px; font-size: 16px; }

  .overlay button { margin-top: 2px; padding: 8px 20px; font-size: 14px; }
  .overlay button.secondary { padding: 6px 16px; font-size: 13px; }

  #startHighscore { font-size: 12px !important; }
  #scoreboardList, .miniboard { max-height: 38vh; }
  #rotateIcon { font-size: 30px; }
}
