/* Schlachtfeld – Oberfläche im Stil einer Amiga-Workbench */

:root {
  --blue-0: #071c42;
  --blue-1: #0b2a63;
  --blue-2: #12408f;
  --orange: #ff8a00;
  --white: #f2f2ea;
  --grey: #9aa4b8;
  --black: #0a0a10;
  --shadow: rgba(0, 0, 0, 0.55);
  --green: #5ad24a;
  --red: #ff5a4a;
  --cyan: #7ef2ff;
  --font: "Courier New", "Lucida Console", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--blue-0);
  color: var(--white);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
}

body.scanlines::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
}

#app { display: flex; flex-direction: column; height: 100%; }

/* ------------------------------------------------------------------ */
/* Kopfzeile                                                           */
/* ------------------------------------------------------------------ */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
  background: var(--white);
  color: var(--black);
  border-bottom: 3px solid var(--black);
  flex: 0 0 auto;
}
.tb-title { font-weight: bold; letter-spacing: 3px; white-space: nowrap; }
.tb-logo { color: var(--orange); }
.tb-status {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: #333;
}
.tb-actions { display: flex; gap: 6px; }

/* ------------------------------------------------------------------ */
/* Bedienelemente                                                      */
/* ------------------------------------------------------------------ */
.btn {
  font-family: var(--font);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: var(--white);
  color: var(--black);
  border: 2px solid;
  border-color: #ffffff #4a4a4a #4a4a4a #ffffff;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--orange); }
.btn:active:not(:disabled) { border-color: #4a4a4a #ffffff #ffffff #4a4a4a; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.small { font-size: 12px; padding: 3px 8px; }
.btn.big { font-size: 16px; padding: 10px 14px; width: 100%; text-align: left; }
.btn.danger:hover { background: var(--red); }
.btn.active { background: var(--orange); }

/*
 * Der Zug-Ende-Knopf ist die wichtigste Schaltfläche der Leiste und deshalb
 * dauerhaft hervorgehoben. Sind keine Züge mehr möglich, kommt "attention"
 * hinzu und macht ihn durch Blinken unmissverständlich.
 */
.btn.primary {
  border-color: var(--orange);
  color: var(--orange);
  font-weight: bold;
  letter-spacing: 1px;
}
.btn.primary:hover:not(:disabled) { background: var(--orange); color: var(--black); }

.btn.attention:not(:disabled) {
  background: var(--orange);
  color: var(--black);
  animation: pochen 1.1s steps(2, end) infinite;
}
@keyframes pochen {
  0%, 49% { background: var(--orange); color: var(--black); }
  50%, 100% { background: var(--blue-1); color: var(--orange); }
}

/* Hinweis am unteren Spielfeldrand: Runde ist durch */
.board-note {
  grid-area: 1 / 1;
  place-self: end center;
  z-index: 6;
  margin-bottom: 14px;
  padding: 8px 18px;
  font: inherit;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--black);
  background: var(--orange);
  border: 3px solid;
  border-color: #ffffff #7a4200 #7a4200 #ffffff;
  box-shadow: 4px 4px 0 var(--shadow);
  cursor: pointer;
  animation: pochen-note 1.4s ease-in-out infinite;
}
.board-note:hover { background: #ffb347; }
.board-note small { display: block; font-size: 11px; letter-spacing: 0; opacity: 0.8; }
@keyframes pochen-note {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* Zahl der noch handlungsfähigen Einheiten in der Kopfzeile */
.gb-open {
  font-size: 12px;
  letter-spacing: 1px;
  padding: 2px 8px;
  border: 2px solid var(--grey);
  color: var(--grey);
  white-space: nowrap;
}
.gb-open.none {
  border-color: var(--orange);
  color: var(--orange);
  font-weight: bold;
}

@media (prefers-reduced-motion: reduce) {
  .btn.attention:not(:disabled) { animation: none; }
  .board-note { animation: none; }
}

input[type="text"], input[type="number"], input[type="password"], select {
  font-family: var(--font);
  font-size: 14px;
  background: var(--white);
  color: var(--black);
  border: 2px solid;
  border-color: #4a4a4a #ffffff #ffffff #4a4a4a;
  padding: 4px 6px;
  min-width: 0;
}
input[type="range"] { width: 150px; accent-color: var(--orange); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--orange); }
label { cursor: pointer; }

/* ------------------------------------------------------------------ */
/* Fenster                                                             */
/* ------------------------------------------------------------------ */
#main { position: relative; flex: 1; min-height: 0; }

.screen {
  display: none;
  position: absolute;
  inset: 0;
  padding: 12px;
  overflow: auto;
}
.screen.active { display: block; }
#screen-game.active { display: flex; flex-direction: column; padding: 6px; overflow: hidden; }

.window {
  background: var(--blue-1);
  border: 3px solid;
  border-color: #ffffff #16305f #16305f #ffffff;
  box-shadow: 5px 5px 0 var(--shadow);
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  max-height: 100%;
}
.center-window { max-width: 620px; }
.wide-window { max-width: 1100px; }

.win-title {
  background: var(--orange);
  color: var(--black);
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  padding: 5px 10px;
  border-bottom: 3px solid var(--black);
  flex: 0 0 auto;
}
.win-body { padding: 14px; overflow: auto; flex: 1 1 auto; }
.win-foot {
  padding: 8px 10px;
  border-top: 2px solid #16305f;
  background: var(--blue-0);
  flex: 0 0 auto;
}
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hint { font-size: 12px; color: var(--grey); }

h3 { margin: 18px 0 6px; color: var(--orange); letter-spacing: 2px; text-transform: uppercase; font-size: 14px; }
h3:first-child { margin-top: 0; }
p { line-height: 1.5; margin: 6px 0; }
a { color: var(--cyan); }

/* ------------------------------------------------------------------ */
/* Hauptmenü                                                           */
/* ------------------------------------------------------------------ */
.menu-body { display: grid; grid-template-columns: 1fr; gap: 14px; }
.menu-art {
  border: 2px solid #16305f;
  background: var(--blue-0);
  display: flex;
  justify-content: center;
  padding: 8px;
}
.menu-art canvas { image-rendering: pixelated; }
.menu-buttons { display: grid; gap: 6px; }
#menu-foot { font-size: 12px; color: var(--grey); }

/* ------------------------------------------------------------------ */
/* Konfiguration                                                       */
/* ------------------------------------------------------------------ */
.cfg-group { margin-bottom: 16px; border: 2px solid #16305f; }
.cfg-group > h4 {
  margin: 0;
  padding: 4px 8px;
  background: var(--blue-2);
  color: var(--white);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 13px;
}
.cfg-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.6fr) minmax(120px, 1fr);
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border-top: 1px solid #16305f;
}
.cfg-row:nth-child(even) { background: rgba(255, 255, 255, 0.03); }
.cfg-label { font-size: 14px; }
.cfg-label small { display: block; color: var(--grey); font-size: 11px; line-height: 1.35; }
.cfg-ctl { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cfg-ctl output { min-width: 56px; text-align: right; font-size: 13px; color: var(--orange); }
.cfg-ctl input[type="number"], .cfg-ctl input[type="text"], .cfg-ctl select { width: 100%; max-width: 220px; }

/* ------------------------------------------------------------------ */
/* Spielaufbau                                                         */
/* ------------------------------------------------------------------ */
.lobby-grid { display: grid; gap: 10px; }
.lobby-player {
  display: grid;
  grid-template-columns: 44px 1fr 150px 150px 110px;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 2px solid #16305f;
  background: rgba(255, 255, 255, 0.03);
}
.lobby-player.off { opacity: 0.35; }
.swatch { width: 32px; height: 32px; border: 2px solid var(--black); }
.lobby-side { font-size: 12px; color: var(--grey); text-align: right; }
.lobby-summary { margin-top: 12px; font-size: 13px; color: var(--grey); line-height: 1.6; }
.lobby-summary b { color: var(--white); }

@media (max-width: 700px) {
  .lobby-player { grid-template-columns: 44px 1fr; }
  .cfg-row { grid-template-columns: 1fr; }
  .cfg-ctl { justify-content: flex-start; }
}

/* ------------------------------------------------------------------ */
/* Spielbildschirm                                                     */
/* ------------------------------------------------------------------ */
.gamebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  background: var(--blue-1);
  border: 2px solid;
  border-color: #ffffff #16305f #16305f #ffffff;
  flex: 0 0 auto;
  margin-bottom: 6px;
}
.gb-round .lbl { color: var(--grey); font-size: 12px; }
.gb-round { font-weight: bold; letter-spacing: 1px; }
.gb-turn { font-weight: bold; letter-spacing: 2px; padding: 2px 8px; border: 2px solid var(--black); }
.gb-ticker {
  flex: 1;
  font-size: 12px;
  color: var(--grey);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gb-actions { display: flex; gap: 6px; }

/*
 * Die mittlere Spalte darf sich NICHT nach ihrem Inhalt richten (auto),
 * sonst kann der Renderer keine freie Fläche messen und das Spielfeld
 * bleibt winzig. Feste Anteile geben dem Feld den größten Teil.
 */
.arena {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(0, 2.6fr) minmax(140px, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 6px;
}
.board-wrap {
  grid-column: 2;
  grid-row: 1 / 3;
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}
.board-wrap > canvas { grid-area: 1 / 1; }
#board {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 3px solid var(--black);
  box-shadow: 0 0 0 2px #16305f, 6px 6px 0 var(--shadow);
  background: #3d8a34;
}
#fx { pointer-events: none; }

.board-msg {
  grid-area: 1 / 1;
  z-index: 5;
  background: rgba(7, 28, 66, 0.92);
  border: 3px solid var(--orange);
  padding: 18px 26px;
  text-align: center;
  font-size: 20px;
  letter-spacing: 2px;
  box-shadow: 6px 6px 0 var(--shadow);
  place-self: center;
}
.board-msg small { display: block; font-size: 13px; color: var(--grey); margin-top: 8px; letter-spacing: 0; }

.pslot { min-width: 0; min-height: 0; display: flex; }
.pslot[data-slot="nw"] { grid-column: 1; grid-row: 1; }
.pslot[data-slot="sw"] { grid-column: 1; grid-row: 2; }
.pslot[data-slot="ne"] { grid-column: 3; grid-row: 1; }
.pslot[data-slot="se"] { grid-column: 3; grid-row: 2; }

.arena.players-2 .pslot[data-slot="nw"] { grid-row: 1 / 3; }
.arena.players-2 .pslot[data-slot="ne"] { grid-row: 1 / 3; }
.arena.players-3 .pslot[data-slot="ne"] { grid-row: 1 / 3; }

/* Spielerpanel */
.pcard {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 3px solid;
  border-color: #ffffff #16305f #16305f #ffffff;
  background: var(--blue-1);
  overflow: hidden;
  min-height: 0;
}
.pcard.dead { opacity: 0.5; filter: grayscale(0.6); }
.pcard.active { box-shadow: 0 0 0 3px var(--orange); }
.pcard-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-bottom: 2px solid var(--black);
  font-weight: bold;
  letter-spacing: 1px;
}
.pcard-head .side { margin-left: auto; font-size: 11px; font-weight: normal; opacity: 0.8; }
.pcard-body { padding: 6px; display: flex; flex-direction: column; gap: 6px; overflow: auto; }
.stat-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.stat-row canvas { image-rendering: pixelated; flex: 0 0 auto; }
.stat-row .k { color: var(--grey); flex: 1; }
.stat-row .v { font-weight: bold; font-size: 15px; }
.bar { height: 10px; background: var(--blue-0); border: 2px solid var(--black); }
.bar > i { display: block; height: 100%; }
.pcard-tag {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 1px 5px;
  border: 1px solid currentColor;
  align-self: flex-start;
}

@media (max-width: 900px) {
  .arena { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto; }
  .board-wrap { grid-column: 1 / 3; grid-row: 1; }
  .pslot[data-slot="nw"] { grid-column: 1; grid-row: 2; }
  .pslot[data-slot="ne"] { grid-column: 2; grid-row: 2; }
  .pslot[data-slot="sw"] { grid-column: 1; grid-row: 3; }
  .pslot[data-slot="se"] { grid-column: 2; grid-row: 3; }
  .arena.players-2 .pslot[data-slot="nw"],
  .arena.players-2 .pslot[data-slot="ne"],
  .arena.players-3 .pslot[data-slot="ne"] { grid-row: 2; }
}

/* ------------------------------------------------------------------ */
/* Tabellen (Spielstände, Admin)                                       */
/* ------------------------------------------------------------------ */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { text-align: left; padding: 5px 8px; border-bottom: 1px solid #16305f; }
table.grid th { background: var(--blue-2); text-transform: uppercase; letter-spacing: 1px; font-size: 12px; }
table.grid tr:hover td { background: rgba(255, 255, 255, 0.05); }
table.grid td.actions { text-align: right; white-space: nowrap; }
.empty-note { padding: 20px; text-align: center; color: var(--grey); }

table.keys td { padding: 3px 10px 3px 0; vertical-align: top; font-size: 13px; }
table.keys td:first-child { color: var(--orange); white-space: nowrap; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; }
.legend div { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.legend canvas { image-rendering: pixelated; }

.auth-form { display: grid; gap: 10px; max-width: 340px; }
.auth-form label { display: grid; gap: 4px; font-size: 13px; }
/* Kompaktes Formular innerhalb der Administration */
.auth-form.inline {
  max-width: none;
  grid-template-columns: repeat(3, minmax(120px, 220px)) auto;
  align-items: end;
  gap: 8px 10px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--grey);
}
.auth-form.inline h4 { grid-column: 1 / -1; margin: 0; font-size: 13px; letter-spacing: 1px; }
.auth-form.inline .hint { grid-column: 1 / -1; margin: 0; }
@media (max-width: 720px) {
  .auth-form.inline { grid-template-columns: 1fr; }
}
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }

.badge { font-size: 11px; padding: 1px 6px; border: 1px solid var(--grey); letter-spacing: 1px; }
.badge.admin { border-color: var(--orange); color: var(--orange); }
.badge.banned { border-color: var(--red); color: var(--red); }
/* Ergebnis einer beendeten Partie in der Historie */
.badge.won { border-color: var(--green); color: var(--green); }
.badge.lost { border-color: var(--red); color: var(--red); }

/* ------------------------------------------------------------------ */
/* Meldungen                                                           */
/* ------------------------------------------------------------------ */
#toast-host {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--white);
  color: var(--black);
  border: 2px solid var(--black);
  box-shadow: 3px 3px 0 var(--shadow);
  padding: 6px 14px;
  font-size: 13px;
  letter-spacing: 1px;
  animation: toast-in 0.15s ease-out;
}
.toast.warn { background: var(--orange); }
.toast.err { background: var(--red); color: var(--white); }
.toast.good { background: var(--green); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

#modal-host {
  position: fixed;
  inset: 0;
  z-index: 960;
  background: rgba(7, 28, 66, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#modal-host[hidden] { display: none; }
#modal-host .window { max-width: 520px; width: 100%; }
.modal-body { padding: 14px; display: grid; gap: 10px; }

/* ------------------------------------------------------------------ */
/* Dev-Mode                                                            */
/* ------------------------------------------------------------------ */
#dev-panel {
  position: fixed;
  top: 42px;
  right: 8px;
  width: 330px;
  max-height: calc(100% - 60px);
  overflow: auto;
  z-index: 940;
  background: rgba(4, 12, 28, 0.95);
  border: 2px solid var(--cyan);
  box-shadow: 4px 4px 0 var(--shadow);
  font-size: 12px;
  padding: 8px;
}
#dev-panel[hidden] { display: none; }
#dev-panel h4 {
  margin: 8px 0 4px;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 11px;
  border-bottom: 1px solid #234;
}
#dev-panel h4:first-child { margin-top: 0; }
#dev-panel .kv { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
#dev-panel .kv span:last-child { color: var(--cyan); }
#dev-panel .dev-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#dev-panel .btn.small { font-size: 11px; padding: 2px 6px; }
#dev-log {
  max-height: 170px;
  overflow: auto;
  background: #020814;
  border: 1px solid #234;
  padding: 4px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
#dev-log .r-att { color: var(--green); }
#dev-log .r-def { color: var(--red); }
#dev-log .r-draw { color: var(--orange); }
body.dev-on #board { box-shadow: 0 0 0 2px var(--cyan), 6px 6px 0 var(--shadow); }
