/* Schiffe versenken – Echtzeit (Prefix .mg-bs-) */
/* Der Root ist der Modul-Container des Minispiel-Hosts (.mghost-mod, absolut + inset:0). position:relative
   allein würde ihn auf Höhe 0 zusammenfallen lassen (Kind .mg-bs ist absolut) -> volle Größe erzwingen. */
.mg-bs-root { position: relative; width: 100%; height: 100%; }
.mg-bs {
  --bs-ink: var(--c-outline, #1b1b2f);
  --bs-water: #3fa9f5;
  --bs-water2: #2b7fd1;
  --bs-ship: #a7b1c2;
  --bs-hit: #ff4d3d;
  --bs-gold: var(--c-gold, #ffcc33);
  --bs-good: var(--c-good, #3ddc84);
  --bs-panel: var(--c-panel, #fff6e0);
  position: absolute; inset: 0;
  display: flex; gap: 8px; align-items: stretch; justify-content: center;
  padding: calc(var(--safe-top, 0px) + 6px) calc(var(--safe-right, 0px) + 8px)
           calc(var(--safe-bottom, 0px) + 6px) calc(var(--safe-left, 0px) + 8px);
  box-sizing: border-box; overflow: hidden;
  background: radial-gradient(circle at 30% 20%, #1e5aa8, #0e2f66 70%);
  color: var(--c-ink, #1b1b2f);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
.mg-bs * { box-sizing: border-box; }

/* ---------- Spalten ---------- */
.mg-bs-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; min-height: 0; align-items: stretch; }
.mg-bs-main { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; min-width: 0; }
.mg-bs-tgtrow { display: flex; gap: 6px; align-items: stretch; }

.mg-bs.is-battle .mg-bs-side { flex: 1 1 auto; max-width: 340px; }
.mg-bs.is-battle .mg-bs-main { flex: 0 0 auto; }
.mg-bs--tablet.is-battle { gap: 16px; }
.mg-bs--tablet.is-battle .mg-bs-side { flex: 0 0 auto; max-width: none; align-items: center; justify-content: center; }
.mg-bs.is-place .mg-bs-side { flex: 0 0 auto; }
.mg-bs.is-place .mg-bs-main { flex: 1 1 auto; }

/* Sichtbarkeit je Phase */
.mg-bs.is-place .mg-bs-tabs, .mg-bs.is-place .mg-bs-tgtrow, .mg-bs.is-place .mg-bs-ticker { display: none; }
.mg-bs:not(.is-place) .mg-bs-dock, .mg-bs:not(.is-place) .mg-bs-btns, .mg-bs:not(.is-place) .mg-bs-hint { display: none; }
.mg-bs:not(.has-tabs) .mg-bs-tabs { display: none; }
.mg-bs:not(.is-spec) .mg-bs-spec { display: none; }
.mg-bs.is-spec .mg-bs-main, .mg-bs.is-spec .mg-bs-ownwrap, .mg-bs.is-spec .mg-bs-dock, .mg-bs.is-spec .mg-bs-btns { display: none; }
.mg-bs.is-spec .mg-bs-side {
  position: absolute; z-index: 5; top: calc(var(--safe-top, 0px) + 6px); left: calc(var(--safe-left, 0px) + 8px);
  flex-direction: row; align-items: center;
}
.mg-bs.is-spec .mg-bs-ticker { max-width: 50vw; }

/* ---------- Kopf ---------- */
.mg-bs-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bs-panel); border: 3px solid var(--bs-ink); border-radius: 12px; padding: 4px 10px;
  box-shadow: 0 3px 0 var(--bs-ink);
}
.mg-bs--tablet.is-battle .mg-bs-head { align-self: stretch; }
.mg-bs-phase { font-family: "Press Start 2P", system-ui, monospace; font-size: 11px; line-height: 1.3; }
.mg-bs-timer { font-family: "Press Start 2P", system-ui, monospace; font-size: 16px; font-variant-numeric: tabular-nums; }
.mg-bs-timer.is-low { color: var(--bs-hit); animation: mg-bs-pulse .6s infinite alternate; }

/* ---------- Raster ---------- */
.mg-bs-grid {
  position: relative; flex: 0 0 auto;
  width: calc(var(--n) * var(--cell) + 6px); height: calc(var(--n) * var(--cell) + 6px);
  border: 3px solid var(--bs-ink); border-radius: 10px; overflow: hidden;
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.06) 0 6px, transparent 6px 14px),
    linear-gradient(180deg, var(--bs-water), var(--bs-water2));
  box-shadow: 0 4px 0 var(--bs-ink);
}
.mg-bs-cells, .mg-bs-ships, .mg-bs-fx { position: absolute; left: 0; top: 0; width: calc(var(--n) * var(--cell)); height: calc(var(--n) * var(--cell)); }
.mg-bs-cells { z-index: 2; display: grid; grid-template-columns: repeat(var(--n), var(--cell)); grid-auto-rows: var(--cell); }
.mg-bs-ships { z-index: 1; }
.mg-bs-fx { z-index: 3; pointer-events: none; }
.mg-bs-cell { position: relative; border: 1px solid rgba(255,255,255,.2); }
.mg-bs-cell.is-miss::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; transform: translate(-50%, -50%);
  border-radius: 50%; background: #fff; border: 2px solid var(--bs-ink);
}
.mg-bs-cell.is-hit::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 62%; height: 62%; transform: translate(-50%, -50%) rotate(45deg);
  background:
    linear-gradient(var(--bs-hit), var(--bs-hit)) center / 100% 28% no-repeat,
    linear-gradient(var(--bs-hit), var(--bs-hit)) center / 28% 100% no-repeat;
  filter: drop-shadow(0 0 1px var(--bs-ink)) drop-shadow(0 0 1px var(--bs-ink));
}
.mg-bs-cell.is-sunkcell { background: rgba(27,27,47,.25); }
.mg-bs-cell.is-pending::before {
  content: ''; position: absolute; inset: 22%; border-radius: 50%; background: var(--bs-gold); opacity: .85;
  animation: mg-bs-pulse .3s infinite alternate;
}
.mg-bs-cell.is-queued { box-shadow: inset 0 0 0 3px var(--bs-gold); animation: mg-bs-pulse .4s infinite alternate; }

/* Zielraster */
.mg-bs-target .mg-bs-ships { pointer-events: none; }
.mg-bs-target .mg-bs-cell { cursor: crosshair; }
.mg-bs-target.is-cooling { filter: saturate(.55) brightness(.92); }
.mg-bs-target.is-disabled { opacity: .55; pointer-events: none; }

/* Eigenes Raster */
.mg-bs-own .mg-bs-cells { pointer-events: none; }
.mg-bs-ownwrap { display: flex; justify-content: center; align-items: center; border-radius: 14px; }
.mg-bs-ownwrap.is-alarm { animation: mg-bs-alarm .6s ease-out; }

/* Schiffe */
.mg-bs-ship {
  position: absolute; left: calc(var(--x) * var(--cell) + 2px); top: calc(var(--y) * var(--cell) + 2px);
  background: linear-gradient(180deg, #c6cfdc, var(--bs-ship));
  border: 3px solid var(--bs-ink); border-radius: calc(var(--cell) * .45);
}
.mg-bs-ship.dir-h { width: calc(var(--len) * var(--cell) - 4px); height: calc(var(--cell) - 4px); }
.mg-bs-ship.dir-v { width: calc(var(--cell) - 4px); height: calc(var(--len) * var(--cell) - 4px); }
.mg-bs-ship.is-sunk { background: repeating-linear-gradient(45deg, #5b2b2b 0 5px, #3a1c1c 5px 10px); opacity: .9; }
.mg-bs-ship.is-lifted { opacity: .25; }
.mg-bs.is-place .mg-bs-own .mg-bs-ship:not(.is-locked) { cursor: grab; touch-action: none; }

/* Werft (Dock) */
.mg-bs-dock {
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start; flex: 1 1 auto; min-height: 0; overflow: hidden;
  background: var(--bs-panel); border: 3px solid var(--bs-ink); border-radius: 12px; padding: 6px 8px;
}
.mg-bs-dock-title { font-family: "Press Start 2P", system-ui, monospace; font-size: 12px; }
.mg-bs-dock-ok { font-weight: 700; color: #1e8a4c; }
.mg-bs-dockship {
  width: calc(var(--len) * var(--cell)); height: var(--cell); flex: 0 0 auto;
  background: linear-gradient(180deg, #c6cfdc, var(--bs-ship));
  border: 3px solid var(--bs-ink); border-radius: calc(var(--cell) * .45); touch-action: none; cursor: grab;
}
.mg-bs-ghost {
  position: absolute; z-index: 50; pointer-events: none; opacity: .85;
  background: linear-gradient(180deg, #e1e7f0, var(--bs-ship));
  border: 3px solid var(--bs-ink); border-radius: calc(var(--cell) * .45);
}
.mg-bs-ghost.dir-h { width: calc(var(--len) * var(--cell)); height: var(--cell); }
.mg-bs-ghost.dir-v { width: var(--cell); height: calc(var(--len) * var(--cell)); }
.mg-bs-ghost.is-snap { box-shadow: 0 0 0 3px var(--bs-good); }
.mg-bs-ghost.is-bad { box-shadow: 0 0 0 3px var(--bs-hit); background: #f6b1aa; }

.mg-bs-btns { display: flex; flex-direction: column; gap: 6px; }
.mg-bs-btn {
  min-height: var(--btn-min, 48px); padding: 6px 10px; font: inherit; font-weight: 800; font-size: 15px;
  border: 3px solid var(--bs-ink); border-radius: 12px; box-shadow: 0 4px 0 var(--bs-ink);
  background: var(--bs-gold); color: var(--bs-ink); touch-action: manipulation;
}
.mg-bs-btn--ready { background: var(--bs-good); }
.mg-bs-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--bs-ink); }
.mg-bs-btn:disabled { opacity: .6; }
.mg-bs-hint { color: #fff; font-weight: 700; font-size: 13px; text-shadow: 0 2px 0 var(--bs-ink); height: 18px; }

/* ---------- Tabs ---------- */
.mg-bs-tabs { display: flex; gap: 6px; max-width: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; flex: 0 0 auto; }
.mg-bs-tab {
  min-height: 48px; min-width: 64px; padding: 3px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: inherit; font-weight: 800; font-size: 13px; color: var(--bs-ink);
  background: var(--bs-panel); border: 3px solid var(--bs-ink); border-radius: 12px; box-shadow: 0 3px 0 var(--bs-ink);
}
.mg-bs--tablet .mg-bs-tab { min-height: 54px; font-size: 15px; }
.mg-bs-tab.is-sel { background: var(--bs-gold); transform: translateY(-2px); }
.mg-bs-tab.is-out { filter: grayscale(1); opacity: .45; text-decoration: line-through; }
.mg-bs-tab.is-off .mg-bs-tab-name::after { content: ' ⚡'; }
.mg-bs-tab-name { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-bs-pips { display: flex; gap: 2px; margin-top: 2px; }
.mg-bs-pips i { width: 9px; height: 7px; border: 2px solid var(--bs-ink); border-radius: 3px; background: #c33; }
.mg-bs-pips i.on { background: var(--bs-good); }

/* ---------- Cooldown ---------- */
.mg-bs-cd {
  position: relative; width: 14px; flex: 0 0 14px; border: 3px solid var(--bs-ink); border-radius: 8px;
  background: #2a2a44; overflow: hidden;
}
.mg-bs-cd-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; background: linear-gradient(0deg, #ff8a2a, var(--bs-gold)); }
.mg-bs-cd.is-ready .mg-bs-cd-fill { background: var(--bs-good); }
.mg-bs-cd.is-ready { box-shadow: 0 0 8px var(--bs-good); }

/* ---------- Info / Ticker ---------- */
.mg-bs-info { display: flex; flex-direction: column; gap: 3px; }
.mg-bs-stat, .mg-bs-readyline {
  background: rgba(255,246,224,.92); border: 2px solid var(--bs-ink); border-radius: 8px; padding: 2px 8px; font-size: 13px;
}
.mg-bs-stat--out { background: #ffb3a8; font-weight: 800; }
.mg-bs-ticker { display: flex; flex-direction: column; gap: 3px; min-height: 0; overflow: hidden; }
.mg-bs-tick { color: #fff; font-size: 12px; text-shadow: 0 1px 0 var(--bs-ink); animation: mg-bs-in .3s ease-out; }
.mg-bs--tablet .mg-bs-stat, .mg-bs--tablet .mg-bs-tick { font-size: 15px; }

/* ---------- Effekte ---------- */
.mg-bs-boom {
  position: absolute; left: calc((var(--x) + .5) * var(--cell)); top: calc((var(--y) + .5) * var(--cell));
  font-size: calc(var(--cell) * 1.3); line-height: 1; transform: translate(-50%, -50%) scale(.2);
  animation: mg-bs-boom .85s ease-out forwards;
}
.mg-bs-boom.kind-miss { animation-name: mg-bs-splash; }
.mg-bs-grid.is-shake { animation: mg-bs-shake .35s; }

.mg-bs-banner {
  position: absolute; left: 50%; top: 40%; z-index: 30; pointer-events: none; opacity: 0;
  transform: translate(-50%, -50%) scale(.5);
  font-family: "Press Start 2P", system-ui, monospace; font-size: 26px; color: #fff; white-space: nowrap;
  text-shadow: -2px -2px 0 var(--bs-ink), 2px -2px 0 var(--bs-ink), -2px 2px 0 var(--bs-ink), 2px 2px 0 var(--bs-ink), 0 5px 0 var(--bs-ink);
}
.mg-bs-banner.is-on { animation: mg-bs-banner 1.5s ease-out forwards; }
.mg-bs-banner.is-hit { color: #ffd166; }
.mg-bs-banner.is-sunk { color: #ff6b5b; font-size: 32px; }
.mg-bs-banner.is-out { color: #ff6b5b; }
.mg-bs-banner.is-go { color: var(--bs-good); font-size: 34px; }

/* ---------- Zuschauer ---------- */
.mg-bs-spec { flex: 1 1 auto; display: flex; flex-wrap: wrap; gap: 12px; align-content: center; justify-content: center; padding-top: 52px; }
.mg-bs-specbox { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mg-bs-specbox.is-out { filter: grayscale(1); opacity: .5; }
.mg-bs-speclabel { color: #fff; font-weight: 800; text-shadow: 0 2px 0 var(--bs-ink); }
.mg-bs-speclabel span { font-weight: 600; opacity: .85; }
.mg-bs-specgrid .mg-bs-cells { pointer-events: none; }

/* ---------- Ergebnis ---------- */
.mg-bs-overlay { position: absolute; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; background: rgba(14,20,40,.55); }
.mg-bs-overlay.is-on { display: flex; animation: mg-bs-in .3s ease-out; }
.mg-bs-result {
  background: var(--bs-panel); border: 4px solid var(--bs-ink); border-radius: 16px; box-shadow: 0 6px 0 var(--bs-ink);
  padding: 10px 16px; max-width: 92%; max-height: 92%; overflow: auto;
}
.mg-bs-result h2 { margin: 0 0 6px; font-family: "Press Start 2P", system-ui, monospace; font-size: 15px; text-align: center; }
.mg-bs-result table { border-collapse: collapse; width: 100%; font-size: 14px; }
.mg-bs-result th, .mg-bs-result td { padding: 2px 8px; text-align: center; border-bottom: 2px solid rgba(27,27,47,.15); }
.mg-bs-result td:nth-child(2) { text-align: left; }
.mg-bs-result tr.is-me { background: rgba(255,204,51,.45); }
.mg-bs-result tr.is-out td { opacity: .7; }
.mg-bs-formula { margin-top: 6px; font-weight: 800; text-align: center; }
.mg-bs-formula-sub { font-size: 12px; text-align: center; opacity: .8; }

/* ---------- Animationen ---------- */
@keyframes mg-bs-pulse { from { opacity: 1; } to { opacity: .45; } }
@keyframes mg-bs-boom {
  0% { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  40% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}
@keyframes mg-bs-splash {
  0% { transform: translate(-50%, -30%) scale(.2); opacity: 1; }
  50% { transform: translate(-50%, -70%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -60%) scale(1.1); opacity: 0; }
}
@keyframes mg-bs-shake {
  0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); } 60% { transform: translate(-3px, -1px); } 80% { transform: translate(3px, 1px); }
}
@keyframes mg-bs-alarm { 0% { box-shadow: 0 0 0 6px var(--bs-hit); } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes mg-bs-banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}
@keyframes mg-bs-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Dauerfeuer (Badge/Knopf-Stil in mg-tanks.css) */
.mg-bs-rapidrow { display: flex; gap: 8px; align-items: center; justify-content: center; min-height: 0; }
