/* minigames-v2 – MineDemon Cells / Tanks and the Minigames page (Minecraft pixel style).
   Loaded after v2.css; everything is scoped to the minigames section. */

body.v2 .minigame-panel {
  --mg-slot: inset 0 0 0 2px #2a2138, inset 3px 3px 0 rgba(0, 0, 0, 0.5), inset -2px -2px 0 rgba(255, 255, 255, 0.05);
  --mg-text-shadow: 2px 2px 0 #3f3f3f;
  --mg-planks: url("../img/minecraft/block/dark_oak_planks.png");
  --mg-stone: url("../img/minecraft/block/stone.png");
}

/* ---------- page: lead + game cards ---------- */
body.v2 .minigame-lead {
  margin: -6px 0 18px;
  color: var(--v2-muted);
  font-weight: 700;
}

body.v2 .minigame-hub {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

body.v2 .minigame-card {
  min-height: 0;
}

body.v2 .minigame-card button {
  min-height: 92px;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px 16px;
}

body.v2 .minigame-card-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
  box-shadow: var(--mg-slot);
}

body.v2 .minigame-card-icon img {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.55));
}

body.v2 .minigame-card-copy b {
  font-size: 1.25rem;
  text-shadow: var(--mg-text-shadow);
}

body.v2 .minigame-card-copy em {
  color: var(--v2-muted);
  font-weight: 700;
}

body.v2 .minigame-card-online {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 0;
  background: rgba(0, 0, 0, 0.5);
  box-shadow: var(--mg-slot);
  color: #86efac;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}

body.v2 .minigame-card-online::before {
  content: "";
  width: 8px;
  height: 8px;
  background: #4ade80;
  box-shadow: 0 0 0 2px #14532d;
}

body.v2 .minigame-card.is-active {
  box-shadow: inset 0 0 0 3px #f3eefc, inset 3px 3px 0 3px rgba(255, 255, 255, 0.1) !important;
}

body.v2 .minigame-card:hover {
  filter: brightness(1.12);
}

/* ---------- game head + start panel ---------- */
body.v2 .minigame-head {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: 12px;
}

body.v2 .minigame-mode,
body.v2 .minigame-live {
  min-height: 64px;
  padding: 10px 14px;
  border: 0;
  background: rgba(0, 0, 0, 0.42);
  box-shadow: var(--mg-slot);
}

body.v2 .minigame-mode > span {
  width: 40px;
  height: 40px;
  font-size: 18px;
}

body.v2 .minigame-mode strong,
body.v2 .minigame-live strong {
  font-size: 1rem;
  text-shadow: var(--mg-text-shadow);
}

body.v2 .minigame-start {
  grid-template-columns: 96px minmax(0, 1fr) minmax(240px, 340px);
  padding: 16px 18px;
  border: 0;
  background: linear-gradient(180deg, rgba(30, 21, 44, 0.86), rgba(17, 12, 26, 0.92)), var(--tex-bricks) 0 0 / 64px 64px;
  image-rendering: pixelated;
  box-shadow: inset 0 0 0 3px var(--v2-edge), var(--px-bevel);
  clip-path: var(--px-clip);
}

body.v2 .minigame-start h2 {
  margin-bottom: 6px;
  font-size: 1.4rem;
}

body.v2 .agario-preview,
body.v2 .tank-preview {
  width: 84px;
  height: 84px;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  box-shadow: var(--mg-slot);
}

body.v2 .agario-preview img {
  width: 64px;
  height: 64px;
}

body.v2 .tank-preview img {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
}

body.v2 .minigame-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  color: var(--v2-muted);
  font-size: 0.85rem;
  font-weight: 700;
}

body.v2 .minigame-keys li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

body.v2 .minigame-keys-touch {
  display: none !important;
}

@media (pointer: coarse) {
  body.v2 .minigame-keys-touch {
    display: inline-flex !important;
  }
}

body.v2 .minigame-panel kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 7px 4px;
  background: linear-gradient(rgba(60, 60, 66, 0.92), rgba(40, 40, 46, 0.95)), var(--mg-stone) 0 0 / 32px 32px;
  color: #fff;
  font: 800 0.75rem/1.1 ui-monospace, Consolas, monospace;
  text-align: center;
  text-shadow: 1px 1px 0 #3f3f3f;
  box-shadow: inset 0 0 0 2px #000, inset 2px 2px 0 2px rgba(255, 255, 255, 0.18), inset -2px -2px 0 2px rgba(0, 0, 0, 0.45);
  image-rendering: pixelated;
}

/* ---------- canvas ---------- */
body.v2 #agario-canvas,
body.v2 #tank-canvas {
  height: clamp(520px, 62vw, 780px);
  border: 0;
  background: #07040b;
  box-shadow: inset 0 0 0 3px #050308, 0 0 0 3px #2a2138, 0 12px 0 rgba(0, 0, 0, 0.35);
  image-rendering: pixelated;
}

body.v2 #agario-canvas:focus-visible,
body.v2 #tank-canvas:focus-visible {
  outline: 3px solid #c084fc;
  outline-offset: 2px;
}

/* ---------- HUD (inventory-slot boxes) ---------- */
body.v2 .agario-hud {
  gap: 6px;
}

body.v2 .agario-hud > div {
  min-width: 82px;
  padding: 6px 10px;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: none;
  box-shadow: var(--mg-slot);
}

body.v2 .agario-hud span {
  color: #b3a9c9;
  font-size: 10px;
  text-shadow: 1px 1px 0 #000;
}

body.v2 .agario-hud b {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-size: 15px;
  text-shadow: var(--mg-text-shadow);
}

body.v2 .agario-net em {
  color: #e9e4f3;
  font-size: 12px;
  font-style: normal;
}

.agario-net-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.agario-net-bars i {
  display: block;
  width: 3px;
  background: #3a3344;
  box-shadow: 1px 1px 0 #000;
}

.agario-net-bars i:nth-child(1) { height: 4px; }
.agario-net-bars i:nth-child(2) { height: 6px; }
.agario-net-bars i:nth-child(3) { height: 9px; }
.agario-net-bars i:nth-child(4) { height: 11px; }
.agario-net-bars i:nth-child(5) { height: 14px; }

.agario-net[data-bars="1"] .agario-net-bars i:nth-child(-n + 1),
.agario-net[data-bars="2"] .agario-net-bars i:nth-child(-n + 2) { background: #ef4444; }
.agario-net[data-bars="3"] .agario-net-bars i:nth-child(-n + 3) { background: #facc15; }
.agario-net[data-bars="4"] .agario-net-bars i:nth-child(-n + 4),
.agario-net[data-bars="5"] .agario-net-bars i:nth-child(-n + 5) { background: #4ade80; }
.agario-net[data-state="offline"] em { color: #fb7185 !important; }
.agario-net[data-state="connecting"] em { color: #facc15 !important; }

/* ---------- boss bar round timer ---------- */
.agario-bossbar {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 4px;
  width: min(420px, 44%);
  transform: translateX(-50%);
  pointer-events: none;
}

.agario-bossbar[hidden] {
  display: none;
}

.agario-bossbar span {
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  text-shadow: 2px 2px 0 #3f3f3f;
}

.agario-bossbar-track {
  position: relative;
  width: 100%;
  height: 10px;
  background: #2b0f3d;
  box-shadow: 0 0 0 2px #000;
}

.agario-bossbar-track i {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  width: 100%;
  background: linear-gradient(#f0abfc 0 30%, #c026d3 30% 70%, #86198f 70%);
  transition: width 0.25s linear;
}

.agario-bossbar-track::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(0, 0, 0, 0.55) calc(10% - 2px) 10%);
}

.agario-bossbar.is-ending .agario-bossbar-track i {
  background: linear-gradient(#fecaca 0 30%, #e11d48 30% 70%, #881337 70%);
}

/* ---------- kill feed (death messages) ---------- */
.agario-feed {
  position: absolute;
  top: 70px;
  left: 14px;
  z-index: 3;
  display: grid;
  gap: 3px;
  max-width: min(360px, 46%);
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}

.agario-feed li {
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #3f3f3f;
  animation: agarioFeedIn 0.18s ease-out both;
}

.agario-feed b {
  color: #f0abfc;
}

@keyframes agarioFeedIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- minimap: Minecraft map in an item frame ---------- */
body.v2 .agario-map-frame {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: grid;
  gap: 4px;
  width: 184px;
  padding: 8px;
  background: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.35)), var(--mg-planks) 0 0 / 32px 32px;
  image-rendering: pixelated;
  box-shadow: inset 0 0 0 2px #1b120a, inset 3px 3px 0 2px rgba(255, 255, 255, 0.12), inset -3px -3px 0 2px rgba(0, 0, 0, 0.45), 4px 4px 0 rgba(0, 0, 0, 0.4);
}

body.v2 .agario-map-frame.is-hidden {
  display: none;
}

body.v2 .agario-map-frame .agario-minimap {
  position: static;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border: 0;
  background: #c9b88a;
  box-shadow: 0 0 0 2px #3b2a14;
  image-rendering: pixelated;
}

.agario-map-coords {
  color: #fff;
  font: 800 11px/1.2 ui-monospace, Consolas, monospace;
  text-align: center;
  text-shadow: 1px 1px 0 #3f3f3f;
}

/* ---------- leaderboard: Minecraft tab list ---------- */
body.v2 .agario-board {
  top: 236px;
  right: 12px;
  width: 232px;
  max-height: calc(100% - 320px);
  padding: 6px 6px 4px;
  background: rgba(0, 0, 0, 0.45);
  text-shadow: 1px 1px 0 #3f3f3f;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

body.v2 .agario-board-head {
  margin-bottom: 4px;
  padding: 0 4px 4px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.12);
}

body.v2 .agario-board h2 {
  font-size: 13px;
  text-shadow: 2px 2px 0 #3f3f3f;
}

body.v2 .agario-board ol {
  gap: 2px;
  max-height: none;
}

body.v2 .agario-board li {
  grid-template-columns: 22px 16px minmax(0, 1fr) auto;
  gap: 6px;
  padding: 2px 4px;
  border: 0;
  background: rgba(255, 255, 255, 0.06);
}

body.v2 .agario-board li.is-player {
  background: rgba(192, 132, 252, 0.28);
}

body.v2 .agario-board li.is-bot strong,
body.v2 .agario-board li.is-afk strong {
  color: #a8a2b3;
}

body.v2 .agario-board li span {
  width: 22px;
  height: 18px;
  color: #e9d5ff;
  font-size: 12px;
}

body.v2 .agario-board-avatar {
  width: 16px;
  height: 16px;
  filter: none;
  box-shadow: 1px 1px 0 #000;
}

body.v2 .agario-board li strong {
  font-size: 12px;
}

body.v2 .agario-board li strong small {
  margin-left: 4px;
  padding: 0 3px;
  background: rgba(0, 0, 0, 0.5);
  color: #a8a2b3;
  font-size: 9px;
  letter-spacing: 0.04em;
}

body.v2 .agario-board li em {
  color: #80ff20;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

/* ---------- start hint + touch controls ---------- */
.agario-keys {
  position: absolute;
  bottom: 70px;
  left: 50%;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  max-width: calc(100% - 40px);
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #3f3f3f;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.agario-keys[hidden] {
  display: none;
}

.agario-keys.is-fading {
  opacity: 0;
}

.agario-keys span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.agario-touch {
  display: none;
}

body.v2 .minigame-shell.is-playing.is-touch .agario-touch {
  position: absolute;
  right: 14px;
  bottom: 74px;
  z-index: 6;
  display: flex;
  gap: 12px;
}

.agario-touch button {
  width: 72px;
  height: 72px;
  border: 0;
  background: linear-gradient(rgba(124, 58, 237, 0.62), rgba(76, 29, 149, 0.78)), var(--tex-amethyst) 0 0 / 36px 36px;
  color: #fff;
  font: 900 15px/1 system-ui, sans-serif;
  text-shadow: 2px 2px 0 #3f3f3f;
  box-shadow: inset 0 0 0 3px #000, inset 3px 3px 0 3px rgba(255, 255, 255, 0.2), inset -3px -3px 0 3px rgba(0, 0, 0, 0.4);
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.agario-touch button:active {
  filter: brightness(1.25);
  transform: translateY(2px);
}

body.v2 .agario-controls .btn {
  min-height: 38px;
  padding: 0 11px;
  font-size: 12px;
}

/* ---------- death / winner screen ---------- */
body.v2 .minigame-result-overlay {
  backdrop-filter: none;
  background: rgba(7, 4, 11, 0.45);
}

body.v2 .minigame-result-overlay.is-death {
  background: linear-gradient(rgba(120, 0, 0, 0.42), rgba(60, 0, 0, 0.62));
}

body.v2 .minigame-result-overlay.is-winner {
  background: linear-gradient(rgba(76, 29, 149, 0.4), rgba(20, 8, 40, 0.68));
}

body.v2 .minigame-result-icon {
  display: none;
}

body.v2 .minigame-result-card b {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 900;
  text-shadow: 4px 4px 0 #3f3f3f;
}

body.v2 .minigame-result-card p {
  color: #fff;
  font-weight: 700;
  text-shadow: 2px 2px 0 #3f3f3f;
}

.minigame-result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: min(380px, 100%);
  margin: 4px 0 0;
}

.minigame-result-stats div {
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.6);
}

.minigame-result-stats dt {
  color: #d4d0dc;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000;
}

.minigame-result-stats dd {
  margin: 0;
  color: #ffd84d;
  font-size: 15px;
  font-weight: 900;
  text-shadow: 2px 2px 0 #3f3f3f;
}

body.v2 .minigame-result-actions {
  display: grid;
  gap: 8px;
  width: min(320px, 100%);
}

body.v2 .minigame-result-actions .btn {
  width: 100%;
  justify-content: center;
  min-height: 42px;
  background: linear-gradient(rgba(110, 110, 116, 0.9), rgba(76, 76, 82, 0.95)), var(--mg-stone) 0 0 / 32px 32px;
  box-shadow: inset 0 0 0 2px #000, inset 2px 2px 0 2px rgba(255, 255, 255, 0.25), inset -2px -2px 0 2px rgba(0, 0, 0, 0.45);
  color: #fff;
  text-shadow: 2px 2px 0 #3f3f3f;
}

body.v2 .minigame-result-actions .btn:hover,
body.v2 .minigame-result-actions .btn:focus-visible {
  background: linear-gradient(rgba(124, 58, 237, 0.62), rgba(76, 29, 149, 0.75)), var(--tex-amethyst) 0 0 / 32px 32px;
  box-shadow: inset 0 0 0 2px #fff, inset 2px 2px 0 2px rgba(255, 255, 255, 0.25);
}

/* ---------- tanks reuse the map frame ---------- */
body.v2 .tank-map-frame {
  width: 184px;
}

body.v2 .tank-map-frame .agario-minimap {
  aspect-ratio: 25 / 17;
}

body.v2 .tank-board {
  top: 212px;
}

/* ---------- fullscreen ---------- */
body.v2 .minigame-shell:fullscreen #agario-canvas,
body.v2 .minigame-shell.is-fullscreen #agario-canvas,
body.v2 .minigame-shell:fullscreen #tank-canvas,
body.v2 .minigame-shell.is-fullscreen #tank-canvas {
  height: 100%;
}

/* ---------- small screens ---------- */
@media (max-width: 991px) {
  body.v2 .minigame-start {
    grid-template-columns: 1fr;
  }

  body.v2 .minigame-head {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body.v2 .minigame-hub {
    grid-template-columns: 1fr;
  }

  body.v2 .minigame-card button {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    min-height: 76px;
  }

  body.v2 .minigame-card-icon {
    width: 52px;
    height: 52px;
  }

  body.v2 #agario-canvas,
  body.v2 #tank-canvas {
    height: min(620px, calc(100vh - 140px));
    min-height: 460px;
  }

  body.v2 .agario-hud {
    right: auto;
    left: 8px;
    top: 8px;
    max-width: calc(100% - 132px);
  }

  body.v2 .agario-hud > div {
    min-width: 0;
    flex: 0 1 auto;
    padding: 4px 7px;
  }

  body.v2 .agario-map-frame {
    top: 8px;
    right: 8px;
    width: 112px;
    padding: 5px;
  }

  .agario-map-coords {
    display: none;
  }

  body.v2 .agario-board {
    top: 128px;
    right: 8px;
    width: 160px;
    max-height: 180px;
  }

  /* Die eigene Zeile bleibt sichtbar, auch hinter Platz 5 (überstimmt auch die n + 7-Regel aus style.css). */
  body.v2 .agario-board li:nth-child(n + 6):not(.is-player) {
    display: none;
  }

  body.v2 .agario-board li.is-player {
    display: grid;
  }

  .agario-bossbar {
    top: auto;
    bottom: 132px;
    width: min(260px, 70%);
  }

  .agario-feed {
    top: auto;
    bottom: 160px;
    max-width: 70%;
  }

  body.v2 .agario-controls .btn:not(#agario-lobby):not(#agario-fullscreen):not(#agario-sound):not(#agario-map-toggle):not(#tank-lobby):not(#tank-fullscreen):not(#tank-ability):not(#tank-boost):not(#tank-sound) {
    display: none;
  }

  body.v2 .agario-controls .btn {
    flex: 1 1 auto;
  }

  /* Sound und Karte bleiben als kompakte Icon-Buttons erreichbar; der Text bleibt im DOM
     und damit der Name für Screenreader. */
  body.v2 .agario-controls #agario-sound,
  body.v2 .agario-controls #agario-map-toggle,
  body.v2 .agario-controls #tank-sound {
    flex: 0 0 44px;
    gap: 0;
    padding: 0;
    font-size: 0;
  }

  body.v2 .agario-controls #agario-sound i,
  body.v2 .agario-controls #agario-map-toggle i,
  body.v2 .agario-controls #tank-sound i {
    font-size: 14px;
  }

  body.v2 .tank-board {
    top: 128px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .agario-feed li,
  .agario-bossbar-track i,
  .agario-keys {
    animation: none;
    transition: none;
  }
}
