:root {
  --green-dark: #1f3d24;
  --green: #2f5d34;
  --wood: #c9a876;
  --gold: #d99a2b;
  --cream: #f4ecdd;
  --ink: #1b1712;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #10160f;
  color: var(--cream);
  font-family: 'Segoe UI', Verdana, Arial, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 100dvh;
  aspect-ratio: 1163 / 1352;
  margin: auto;
  overflow: hidden;
  background: #0a0f0a url('assets/board.jpg') center / cover no-repeat;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
  touch-action: none;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  display: block;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px;
}

.hud-row { display: flex; gap: 8px; }
.hud-top { justify-content: space-between; }
.hud-second { justify-content: center; flex-wrap: wrap; }

.hud-chip {
  background: rgba(15, 20, 12, 0.74);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: clamp(13px, 3.6vw, 16px);
  font-weight: 700;
  backdrop-filter: blur(2px);
  white-space: nowrap;
}
.hud-chip.lock { color: #e2a23a; }
.hud-chip.unlocked { color: #7ee081; border-color: #7ee081; }

.reload-bar-wrap {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: 55%;
  max-width: 260px;
  height: 9px;
  background: rgba(0,0,0,0.5);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.22);
}
.reload-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #e2a23a, #d99a2b);
  transform-origin: left;
}
.reload-bar.charging { background: linear-gradient(90deg, #b85c3a, #d97a2b); }

#toast {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font-size: clamp(16px, 4.6vw, 22px);
  font-weight: 800;
  color: #ffe9b8;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  text-align: center;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 8, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

/* Frisch eingeblendeter End-Screen ignoriert Taps kurz, damit schnelle
   Folge-Schüsse nicht versehentlich einen Button auslösen. */
.overlay.arming { pointer-events: none; }

.panel {
  background: linear-gradient(180deg, #1a2417, #10160f);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: clamp(18px, 5vw, 26px) clamp(16px, 5vw, 24px);
  max-width: 440px;
  width: 100%;
  max-height: 94%;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.panel h1 {
  margin: 0 0 4px;
  font-size: clamp(26px, 8vw, 34px);
  color: var(--gold);
  letter-spacing: 0.5px;
}
.panel h2 { margin: 0 0 8px; color: var(--gold); font-size: clamp(19px, 5.5vw, 24px); }
.subtitle { margin: 0 0 14px; opacity: 0.85; font-size: clamp(12px, 3.4vw, 14px); }
.rules {
  font-size: clamp(13px, 3.6vw, 14.5px);
  line-height: 1.55;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  margin: 0 0 16px;
}

.btn-primary, .btn-secondary, .btn-link {
  font-family: inherit;
  font-weight: 700;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn-primary:active, .btn-secondary:active { transform: scale(0.98); }

.btn-primary {
  width: 100%;
  min-height: 52px;
  padding: 14px;
  font-size: clamp(15px, 4.4vw, 17px);
  background: var(--gold);
  color: #221a08;
}
.btn-primary:hover { background: #f0b649; }

.btn-secondary {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  font-size: clamp(14px, 4vw, 15px);
  background: rgba(255,255,255,0.1);
  color: var(--cream);
  margin-top: 10px;
  border: 1px solid rgba(255,255,255,0.2);
}
.btn-secondary:hover { background: rgba(255,255,255,0.18); }

.btn-link {
  display: block;
  margin: 14px auto 0;
  min-height: 40px;
  background: none;
  color: var(--cream);
  opacity: 0.75;
  font-size: clamp(12px, 3.4vw, 13px);
  text-decoration: underline;
  padding: 6px;
}
.btn-link:hover { opacity: 1; }

.stats-line {
  font-size: clamp(14px, 4vw, 16px);
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 12px;
  margin: 0 0 12px;
}

#scoreForm { display: flex; flex-direction: column; gap: 9px; }
#scoreForm label { font-size: clamp(12px, 3.4vw, 13px); text-align: left; opacity: 0.85; }
#nameInput {
  padding: 13px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: var(--cream);
  font-size: 16px; /* >=16px verhindert Auto-Zoom auf iOS */
  font-family: inherit;
}
#scoreFeedback { min-height: 20px; margin: 8px 0 0; font-size: 13px; color: #9ed69b; }

.board-hint { font-size: 12px; opacity: 0.75; margin: 0 0 12px; }

#boardTable { width: 100%; border-collapse: collapse; font-size: clamp(13px, 3.8vw, 15px); }
#boardTable th, #boardTable td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-align: left;
}
#boardTable th:first-child, #boardTable td:first-child { width: 26px; opacity: 0.7; }
#boardTable th:nth-child(3), #boardTable td:nth-child(3),
#boardTable th:nth-child(4), #boardTable td:nth-child(4) { text-align: right; }
#boardTable tr:first-child td { color: var(--gold); font-weight: 800; }

/* Auf sehr breiten Screens (Desktop) Spielfeld etwas kompakter zentrieren */
@media (min-aspect-ratio: 1/1) {
  #stage { max-height: 96dvh; }
}
