:root {
  --bg: #1b1b2e;
  --bg2: #24243e;
  --ink: #e8e8f0;
  --accent: #ffcf3f;
  --accent2: #6fd66f;
  --red: #ff5b5b;
  --panel: #2c2c4a;
  --line: #46466e;
  --pixel-font: 'Press Start 2P', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--pixel-font);
  image-rendering: pixelated;
}

body {
  background:
    radial-gradient(circle at 20% 10%, #2a2a4a 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, #22223d 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
  padding: 24px 12px 60px;
}

.app {
  max-width: 920px;
  margin: 0 auto;
  text-align: center;
}

.title {
  font-size: 34px;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 3px 3px 0 #b8860b, 6px 6px 0 rgba(0,0,0,0.35);
  margin: 8px 0 6px;
}

.subtitle {
  font-size: 10px;
  color: var(--accent2);
  margin: 0 0 20px;
  line-height: 1.6;
}

.game-wrap { margin: 0 auto; }

.hud {
  display: flex;
  justify-content: space-between;
  max-width: 900px;
  margin: 0 auto 8px;
  font-size: 12px;
  color: var(--accent);
}

.canvas-frame {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
  border: 4px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 0 rgba(0,0,0,0.35);
  background: #f7f4e9;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 40, 0.55);
  transition: opacity 0.15s;
}
.overlay.hidden { display: none; }

.overlay-box {
  background: var(--panel);
  border: 4px solid var(--line);
  border-radius: 6px;
  padding: 22px 26px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4);
}

.big { font-size: 22px; margin: 0 0 12px; color: var(--accent); }
.key {
  color: #222;
  background: var(--accent);
  padding: 2px 6px;
  border-radius: 3px;
  border-bottom: 2px solid #b8860b;
}
.big.red { color: var(--red); text-shadow: 2px 2px 0 #7a0000; }
.small { font-size: 10px; line-height: 1.8; margin: 6px 0; }
.muted { color: #9a9ac0; }
.red { color: var(--red); }
.hidden { display: none; }

.name-entry {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

#nameInput {
  font-family: var(--pixel-font);
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
  padding: 8px 10px;
  width: 180px;
  background: #f7f4e9;
  color: #222;
  border: 3px solid var(--line);
  border-radius: 4px;
  outline: none;
}

.btn {
  font-family: var(--pixel-font);
  font-size: 10px;
  padding: 9px 14px;
  color: #222;
  background: var(--accent);
  border: none;
  border-bottom: 4px solid #b8860b;
  border-radius: 4px;
  cursor: pointer;
}
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }

.hint {
  font-size: 8px;
  color: #9a9ac0;
  margin: 12px auto 0;
  line-height: 1.9;
  max-width: 900px;
}
.hint b { color: var(--accent); }

/* Touch-Steuerung (mobil) */
.touch-controls {
  display: flex;
  gap: 12px;
  max-width: 900px;
  margin: 14px auto 0;
}
.touch-controls.hidden { display: none; }
.touch-btn {
  flex: 1;
  font-family: var(--pixel-font);
  font-size: 22px;
  padding: 20px 8px;
  color: #222;
  background: var(--accent);
  border: none;
  border-bottom: 6px solid #b8860b;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.touch-btn span { font-size: 11px; }
.touch-btn:active { transform: translateY(3px); border-bottom-width: 2px; }
.touch-jump { background: var(--accent); border-bottom-color: #b8860b; }
.touch-jump:active { background: #ffd95a; }
.touch-duck { background: var(--accent2); border-bottom-color: #3a8a3a; }
.touch-duck:active { background: #8ee68e; }

/* Scores */
.scores {
  max-width: 620px;
  margin: 40px auto 0;
  background: var(--panel);
  border: 4px solid var(--line);
  border-radius: 6px;
  padding: 18px 20px 22px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.35);
}
.scores h2 {
  font-size: 16px;
  color: var(--accent);
  margin: 0 0 16px;
}
#scoreTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
#scoreTable th, #scoreTable td {
  padding: 9px 6px;
  border-bottom: 2px solid var(--line);
}
#scoreTable th {
  color: var(--accent2);
  font-size: 9px;
  text-align: left;
}
#scoreTable td { color: var(--ink); text-align: left; }
#scoreTable td:first-child, #scoreTable th:first-child { text-align: center; width: 36px; }
#scoreTable td:nth-child(3), #scoreTable th:nth-child(3) { text-align: right; }
#scoreTable td:nth-child(4), #scoreTable th:nth-child(4) { text-align: right; color: #9a9ac0; font-size: 8px; }
#scoreTable tbody tr:first-child td { color: var(--accent); }

/* ============ Mobile-Optimierungen (Desktop bleibt unberührt) ============ */

/* Quer-Halten-Tipp: standardmäßig aus, nur auf echten Handys im Hochformat an */
.rotate-hint { display: none; }

/* Schmale Viewports (Handys, auch schmale Desktop-Fenster): Layout straffen */
@media (max-width: 600px) {
  .title { font-size: 22px; }
  .subtitle { font-size: 9px; margin-bottom: 12px; }
  .big { font-size: 16px; }
  .hud { font-size: 11px; }
  .scores { margin-top: 22px; padding: 14px 14px 18px; }
  .scores h2 { font-size: 14px; }
  #scoreTable td:nth-child(4), #scoreTable th:nth-child(4) { display: none; }
}

/* Echte Touch-Geräte (Handy/Tablet) — greift NICHT auf Maus-/Touch-Laptops */
@media (pointer: coarse) {
  body { padding: 12px 8px 32px; }
  /* Tastatur-Hinweis ist am Handy irrelevant */
  .hint { display: none; }
  /* Kein Doppeltipp-Zoom / Tap-Verzögerung beim Spielen */
  .canvas-frame { touch-action: manipulation; }
  /* Buttons näher am Spielfeld, daumenfreundlich */
  .touch-controls { margin-top: 10px; gap: 10px; }
  .touch-btn { padding: 22px 8px; }
}

/* Tipp "quer halten" NUR auf erkannten Mobilgeräten (body.is-mobile via JS)
   und ausschließlich im Hochformat. Desktop/Touch-Laptops bekommen ihn nie. */
@media (orientation: portrait) {
  body.is-mobile .rotate-hint {
    display: block;
    font-size: 9px;
    color: var(--accent2);
    margin: 0 auto 8px;
    line-height: 1.6;
  }
}

/* Handy im Querformat: Kopfbereich minimieren, Spielfläche maximieren */
@media (pointer: coarse) and (orientation: landscape) {
  .title { font-size: 16px; margin: 2px 0; }
  .subtitle { display: none; }
  body { padding: 8px 8px 24px; }
}
