:root {
  --bg: #020106;
  --panel: rgba(14, 10, 32, 0.88);
  --line: rgba(196, 181, 253, 0.28);
  --text: #ede9fe;
  --muted: #a5a0c8;
  --accent: #a78bfa;
  --accent-2: #22d3ee;
  --danger: #f43f5e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------ HUD */

#hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  pointer-events: none;
  z-index: 5;
}
.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(260px, 52vw);
  padding: 10px;
  background: rgba(8, 6, 20, 0.55);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.bar {
  position: relative;
  height: 16px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  overflow: hidden;
}
.bar.xp { height: 10px; }
.bar .fill { height: 100%; width: 0; transition: width 0.15s; }
.bar.hp .fill { background: linear-gradient(90deg, #e11d48, #fb7185); }
.bar.xp .fill { background: linear-gradient(90deg, #7c3aed, #22d3ee); }
.bar span {
  position: absolute;
  inset: 0;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
}
.bar.xp span { line-height: 10px; font-size: 9px; }
.hud-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.hud-row.small { font-size: 11px; color: var(--muted); font-weight: 500; }
.sp-hint { color: #facc15 !important; }
.warn { color: #fb923c !important; }
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #0b0716;
}
.chip.big { font-size: 15px; padding: 5px 14px; }

.items { display: flex; gap: 5px; }
.item {
  flex: 1;
  min-width: 0;
  height: 34px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-size: 9px;
  line-height: 1.15;
  padding: 3px;
  overflow: hidden;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.item.filled { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.buffs { display: flex; gap: 6px; flex-wrap: wrap; }
.buff { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; color: #0b0716; }

#toasts {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 20;
}
.toast {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  animation: toast 3.2s forwards;
  max-width: min(92vw, 560px);
  text-align: center;
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(-8px); }
  10%, 80% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

/* ------------------------------------------------------------ Touch */

#touch-ui { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.touch-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 14, 40, 0.5);
  color: #fff;
  font-weight: 800;
  font-family: inherit;
}
.touch-btn.dash {
  width: 76px;
  height: 76px;
  right: calc(24px + var(--safe-right));
  bottom: calc(150px + var(--safe-bottom));
  font-size: 13px;
}
.touch-btn.dash:active { background: rgba(167, 139, 250, 0.6); }
.touch-btn.pause {
  width: 44px;
  height: 44px;
  right: calc(min(150px, 26vmin) + 24px + var(--safe-right));
  top: calc(12px + var(--safe-top));
  font-size: 14px;
}

/* ------------------------------------------------------------ Screens */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: rgba(2, 1, 6, 0.45);
  z-index: 10;
}
.screen.passive { pointer-events: none; background: transparent; }

.panel {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.panel.slim { width: min(380px, 100%); }
h1 { margin: 0 0 6px; font-size: clamp(24px, 5vw, 36px); letter-spacing: 0.5px; }
h2 { margin: 0 0 14px; }
.sub { margin: 0 0 12px; color: var(--muted); }
.stats { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }

.buttons { display: flex; flex-direction: column; gap: 10px; }
.buttons.row { flex-direction: row; justify-content: center; margin-top: 16px; }
button {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 13px 18px;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, #7c3aed, #0891b2); border-color: transparent; }
button.danger { color: #fda4af; }
.badge:not(:empty) {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: #facc15;
  color: #0b0716;
  font-size: 12px;
}

.help { margin-top: 20px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.help kbd {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 4px solid rgba(167, 139, 250, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card { text-align: center; animation: card 1.6s ease forwards; text-shadow: 0 2px 12px #000; }
.card-depth { font-size: clamp(36px, 9vw, 64px); font-weight: 800; }
.card-zoom { font-size: 18px; color: var(--muted); margin: 4px 0 12px; }
@keyframes card {
  0% { opacity: 0; transform: scale(1.2); }
  15%, 75% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

.summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; text-align: left; margin-bottom: 18px; font-size: 15px; }
.summary .v { font-weight: 700; text-align: right; }

.skill-list { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.skill {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}
.skill .name { font-weight: 700; }
.skill .desc { grid-column: 1; font-size: 12px; color: var(--muted); }
.skill .pips { grid-column: 1; display: flex; gap: 3px; }
.skill .pip { width: 14px; height: 6px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); }
.skill .pip.on { background: var(--accent); }
.skill button { grid-column: 2; grid-row: 1 / span 3; min-width: 52px; font-size: 20px; padding: 8px; }

/* ------------------------------------------------------------ Waffe, Perks */

.weapon { display: flex; flex-direction: column; gap: 3px; }
#weapon-name { color: #f8fafc; }
#weapon-ammo { font-variant-numeric: tabular-nums; color: var(--muted); }
.bar.ammo { height: 7px; }
.bar.ammo .fill { background: linear-gradient(90deg, #eab308, #fde047); transition: none; }
.bar.ammo.reloading .fill { background: linear-gradient(90deg, #64748b, #cbd5e1); }
.bar.run { height: 10px; }
.bar.run .fill { background: linear-gradient(90deg, #db2777, #fb923c); }
.bar.run span { line-height: 10px; font-size: 9px; }
.perks { display: flex; flex-wrap: wrap; gap: 3px; }
.perk-chip { font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 4px; background: rgba(251,146,60,0.18); border: 1px solid rgba(251,146,60,0.45); color: #fed7aa; }

.perk-btn {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  min-height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  background: linear-gradient(135deg, #db2777, #f97316);
  border: none;
  border-radius: 999px;
  box-shadow: 0 0 24px rgba(249,115,22,0.5);
  animation: perkPulse 1.2s ease-in-out infinite;
}
.perk-btn kbd, .perk-card kbd { font-family: inherit; font-size: 11px; padding: 0 5px; border-radius: 4px; background: rgba(0,0,0,0.3); }
@keyframes perkPulse { 50% { box-shadow: 0 0 36px rgba(249,115,22,0.85); } }

.panel.wide { width: min(760px, 100%); }
.perk-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.perk-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  min-height: 110px;
  padding: 14px;
  background: linear-gradient(160deg, rgba(219,39,119,0.18), rgba(249,115,22,0.08));
  border: 1px solid rgba(251,146,60,0.45);
}
.perk-card .perk-name { font-size: 15px; color: #fed7aa; }
.perk-card .perk-desc { font-size: 12px; font-weight: 500; color: var(--muted); line-height: 1.35; }
.perk-card:hover { background: linear-gradient(160deg, rgba(219,39,119,0.32), rgba(249,115,22,0.18)); }

.touch-btn.reload { width: 56px; height: 56px; right: calc(112px + var(--safe-right)); bottom: calc(170px + var(--safe-bottom)); font-size: 16px; }
.touch-btn.swap { width: 56px; height: 56px; right: calc(40px + var(--safe-right)); bottom: calc(240px + var(--safe-bottom)); font-size: 20px; }

/* ------------------------------------------------------------ Versionsanzeige */

.version {
  position: fixed;
  left: calc(8px + var(--safe-left));
  bottom: calc(6px + var(--safe-bottom));
  z-index: 30;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: rgba(196, 181, 253, 0.55);
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
