/* ============================================================================
   games.css — Spielspezifische Stile
   ----------------------------------------------------------------------------
   Alles, was nur während einer laufenden Partie relevant ist:
   Tetris-Split-View mit Mini-Boards, Effekt-HUD, Item-Legende, Touch-
   Steuerung und die spieleigenen Overlays. PolyPong und Bomben brauchen
   keine eigenen Canvas-Styles, weil die Spielfläche in den universellen
   .canvas-wrap eingebettet ist; ihre HUD-Elemente teilen sich .my-effects
   und .pm-bar mit den anderen Spielen.

   --player-color kommt vom JS (Spielerfarbe) und steuert den linken Rand
   des Mini-Boards. --tetris-aspect wird von ensureViewMode() gesetzt.
   ============================================================================ */

/* ── Tetris (style.css:811-928) ─────────────────────────────────────── */

/* Solo: 16:10-Aspect überschreiben — Tetris braucht mehr Höhe für das 1:2-Brett. */
#gameCanvas.tetris-active {
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

/* 2×5 Split-View */
.tetris-split {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: #0a0a10;
  box-sizing: border-box;
}

.tetris-split-head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
}

.split-timer {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary, #e8e8ea);
}
.split-timer.urgent { color: var(--red); }

.split-hint {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.tetris-split-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 8px;
}

.mini-board {
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  border-left: 3px solid var(--player-color, var(--border));
}
.mini-board.me {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 14px rgba(34, 211, 238, 0.18);
}
.mini-board.dead { opacity: 0.45; }
.mini-board.gameover { outline: 2px solid var(--red); }

.mini-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px;
  background: var(--bg-3);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mini-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.mini-score {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
}
.mini-board.dead .mini-score,
.mini-board.gameover .mini-score {
  color: var(--red);
}

.mini-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  image-rendering: pixelated;
}

/* Fußzeile eines Mini-Bretts: Next-Vorschau, Lines/Level, BOT-Badge. */
.mini-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  background: var(--bg-3);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 0;
}
.mini-next {
  width: 72px;
  height: 20px;
  flex-shrink: 0;
  image-rendering: pixelated;
}
.mini-meta {
  font-size: 10px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.mini-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: #8a8a95;
  color: #0a0a10;
  flex-shrink: 0;
}
.mini-badge.hidden { display: none; }

/* ── Effects HUD (style.css:666-707) ───────────────────────────────── */
/* Zeigt aktive Effekte des eigenen Spielers (Bomben: Schutz, Multi-Bombe,
   Speed-Down usw.). Position: rechts oben über dem Canvas. */
.my-effects {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  z-index: 5;
}
.my-effects .chip {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 11px;
  color: var(--text-primary);
  letter-spacing: 1px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.my-effects .chip.green { border-color: var(--green); color: var(--green); }
.my-effects .chip.red   { border-color: var(--red);   color: var(--red); }
.my-effects .chip.blue  { border-color: var(--blue);  color: var(--blue); }

.my-effects .chip .bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 0;
  background: currentColor;
  opacity: 0.8;
}

.my-effects .chip .pu-ic {
  width: 14px;
  height: 14px;
  margin-right: 4px;
}

/* ── Item-Legende (style.css:710-809) ───────────────────────────────── */
.pu-legend {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  font-size: 12px;
}
.pu-head {
  margin: 8px 0 2px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.9;
}
.pu-head.green { color: var(--green); }
.pu-head.red   { color: var(--red); }
.pu-head.blue  { color: var(--blue); }
.pu-row {
  display: grid;
  grid-template-columns: 30px 96px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 6px;
}
.pu-row:hover { background: rgba(255, 255, 255, 0.04); }
.pu-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid;
  background: rgba(0, 0, 0, 0.6);
}
.pu-ic {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex: none;
}
.pu-badge .pu-ic { width: 17px; height: 17px; }
.pu-badge.green { color: var(--green); border-color: var(--green); }
.pu-badge.red   { color: var(--red);   border-color: var(--red); }
.pu-badge.blue  { color: var(--blue);  border-color: var(--blue); }
.pu-name  { font-weight: 600; }
.pu-desc  { color: var(--text-secondary); }
.pu-who {
  color: var(--text-secondary);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* Legende als Overlay im Spiel (style.css:776-802) */
.legend-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.legend-overlay.hidden { display: none; }
.legend-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  max-height: 88%;
  max-width: min(760px, 92%);
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.legend-title {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.legend-title small { color: var(--text-secondary); font-weight: 400; letter-spacing: 0; }

/* ── Touch-Steuerung (style.css:979-1026) ───────────────────────────── */
/* Wird nur auf Geräten ohne Tastatur eingehängt (FW.isTouchDevice), liegt
   also im Normalfall gar nicht im DOM. Schwebt über dem Canvas, damit das
   Spielbild seine volle Größe behält. */
.touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px;
  gap: 12px;
  pointer-events: none;
  z-index: 6;
}
.touch-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 45vw;
  pointer-events: auto;
}
.touch-cluster-right { justify-content: flex-end; }
.touch-cluster-left  { max-width: 46vw; }
.touch-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(20, 22, 28, 0.62);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn.is-down {
  background: rgba(0, 212, 170, 0.35);
  border-color: var(--accent);
}

/* Vier Richtungen als Kreuz. Der ."-Bereich in der Mitte deckt mit der
   up/down/left/right-Belegung nicht alle Zellen ab — vorher blieb genau
   in der Mitte ein Loch, in dem ein Daumen ins Leere tippte. Phase 2
   / Task #7: explizites gap und ein zentraler "Stopp"-Knopf hilft
   gegen das Loch. */
.touch-cluster-dpad {
  display: grid;
  grid-template-areas:
    ".    up    ."
    "left stop right"
    ".    down  .";
  gap: 6px;
  max-width: none;
  width: max-content;
}
.touch-cluster-dpad .touch-btn-up    { grid-area: up; }
.touch-cluster-dpad .touch-btn-left  { grid-area: left; }
.touch-cluster-dpad .touch-btn-down  { grid-area: down; }
.touch-cluster-dpad .touch-btn-right { grid-area: right; }
.touch-cluster-dpad .touch-btn-stop  { grid-area: stop; }
.touch-btn.touch-btn-stop {
  width: 36px;
  height: 36px;
  font-size: 14px;
  background: rgba(20, 22, 28, 0.42);
}

/* ── Schmale Displays: Touch-Tasten kleiner (style.css:1124-1126) ──── */
@media (max-width: 480px) {
  .touch-btn { width: 54px; height: 54px; font-size: 19px; }
  .touch-btn.touch-btn-stop { width: 30px; height: 30px; font-size: 12px; }
}

/* ── Tablet-Bereich (Phase 2 / Task #7) ──────────────────────────────
   Bisher fielen Tablets in den Telefon-Zweig. Auf 700-1100 Pixel Breite
   ist die Spielflaeche gross genug fuer einen etwas grosszuegigeren
   Hub, ohne dass die Steuerung das Bild zufranst. */
@media (min-width: 700px) and (max-width: 1100px) {
  .touch-btn { width: 56px; height: 56px; font-size: 20px; }
  .touch-cluster { max-width: 280px; }
}

/* ── Querformat (Phase 2 / Task #7) ─────────────────────────────────
   Im Landscape frass vorher die Seitenleiste 42vh ueber dem Spielbild.
   Die Touch-Cluster wandern an die seitlichen Raender und die Topbar
   schrumpft, damit das Spielfeld die volle Bildhoehe bekommt. */
@media (orientation: landscape) and (max-height: 600px) {
  .touch-controls {
    inset: 0 0 0 auto;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    width: auto;
    height: 100%;
    padding: 8px;
  }
  .touch-cluster { max-width: 64px; }
  .topbar { padding: 6px 12px; }
  .topbar .logo { font-size: 14px; }
}

/* ── Tetris auf schmalen Displays: aspect-ratio kommt vom JS über
   --tetris-aspect, sonst rutscht das Canvas in einen 244 px hohen Streifen
   in der Mitte. (style.css:1106-1115) ─────────────────────────────── */
@media (max-width: 860px) {
  #gameCanvas.tetris-active {
    height: auto;
    aspect-ratio: var(--tetris-aspect, 1.6);
  }
}
