:root {
  --bg: #0a1622;
  --bg-2: #0f2233;
  --card: #13293d;
  --card-2: #1a3a52;
  --line: #21445f;
  --sea: #10334d;
  --sea-hover: #175b82;
  --ink: #e8f2fa;
  --muted: #8fb0c7;
  --accent: #2fa8e0;
  --accent-2: #1b7fb0;
  --ship: #4d6b82;
  --hit: #e2574c;
  --sunk: #8e2d26;
  --miss: #446079;
  --ok: #46b98a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #17384f 0%, var(--bg) 60%);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 .4em; font-weight: 650; letter-spacing: .2px; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.error { color: #ff9c92; font-size: .9rem; }

/* ------------------------------------------------------------------- Topbar */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .8rem 1.2rem;
  background: rgba(8, 20, 31, .75);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(6px);
}
.topbar-right { display: flex; align-items: center; gap: .8rem; }

.badge {
  background: var(--card); border: 1px solid var(--line);
  padding: .25rem .6rem; border-radius: 999px; font-size: .85rem;
}
.badge b { letter-spacing: .18em; color: var(--accent); }

.conn { font-size: .8rem; color: var(--muted); }
.conn.on { color: var(--ok); }
.conn.off { color: #ff9c92; }

main { max-width: 1180px; margin: 0 auto; padding: 1.2rem; }

/* -------------------------------------------------------------------- Karten */

.card {
  background: linear-gradient(180deg, rgba(28,60,86,.55), rgba(19,41,61,.75));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.menu-grid {
  display: grid; gap: 1rem; margin-top: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.menu-block {
  background: rgba(9, 24, 37, .5);
  border: 1px solid var(--line);
  border-radius: 11px; padding: 1rem;
  display: flex; flex-direction: column;
}
.menu-block .btn { margin-top: auto; }

/* -------------------------------------------------------------------- Inputs */

.btn {
  font: inherit; font-weight: 600;
  color: var(--ink); background: #1d4260;
  border: 1px solid var(--line); border-radius: 9px;
  padding: .55rem .9rem; cursor: pointer;
  transition: background .15s, transform .05s, opacity .15s;
}
.btn:hover:not(:disabled) { background: #27567a; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-2); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: rgba(47,168,224,.12); }
.btn.big { padding: .7rem 1rem; width: 100%; }

input {
  font: inherit; color: var(--ink);
  background: #0c1e2e; border: 1px solid var(--line);
  border-radius: 9px; padding: .55rem .7rem; min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.code-input {
  text-transform: uppercase; letter-spacing: .35em;
  font-weight: 700; text-align: center; width: 7ch; flex: 0 0 auto;
}

.row { display: flex; gap: .5rem; }
.stack { display: flex; flex-direction: column; gap: .5rem; margin-top: .9rem; }

kbd {
  background: #0c1e2e; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px;
  padding: 0 .35em; font-size: .85em; font-family: inherit;
}

/* --------------------------------------------------------------------- Brett */

.board {
  display: grid;
  grid-template-columns: 1.4rem repeat(10, 1fr);
  gap: 2px;
  /* width ist noetig: die Karte zentriert ihre Kinder, dadurch waere die Breite
     inhaltsabhaengig - und haenge damit an den Schiffsgrafiken. */
  width: 100%;
  max-width: 420px;
  user-select: none;
  touch-action: manipulation;
}

.lbl {
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; color: var(--muted);
}

.cell {
  position: relative; /* Traeger fuer Einschlag-Effekte (::before) */
  aspect-ratio: 1 / 1;
  background: var(--sea);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 3px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; line-height: 1;
  color: transparent;
  cursor: default;
  transition: background .12s;
}

.cell.ship { background: #1b4361; border-color: #2f6c92; }
.cell.miss { background: var(--miss); color: rgba(232,242,250,.6); }
.cell.miss::after { content: "•"; font-size: 1.1rem; }

/* Treffermarken liegen ueber der Schiffsgrafik - daher halbtransparent. */
.cell.hit, .cell.sunk { position: relative; z-index: 2; color: #fff; }
.cell.hit  { background: rgba(226, 87, 76, .82); }
.cell.hit::after  { content: "✕"; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.cell.sunk { background: rgba(142, 45, 38, .85); color: #ffd9d5; }
.cell.sunk::after { content: "✕"; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.cell.miss { position: relative; z-index: 2; }

/* Platzierungsvorschau */
.cell.preview-ok  { background: #2f6f52; box-shadow: inset 0 0 0 2px var(--ok); }
.cell.preview-bad { background: #6e2f2f; box-shadow: inset 0 0 0 2px var(--hit); }

/* anklickbares Gegnerfeld */
.board.enemy.active .cell:not(.miss):not(.hit):not(.sunk) { cursor: crosshair; }
.board.enemy.active .cell:not(.miss):not(.hit):not(.sunk):hover {
  background: #1d5b82; box-shadow: inset 0 0 0 2px var(--accent);
}
#board-place .cell { cursor: pointer; }

.cell.last { animation: pop .5s ease; }
@keyframes pop {
  0%   { transform: scale(1.35); filter: brightness(1.8); }
  100% { transform: scale(1); filter: none; }
}

/* ------------------------------------------------------------------- Layouts */

.place-layout {
  display: grid; gap: 1rem;
  /* Feste Obergrenze statt 1fr: sonst zieht sich die Karte auf die volle
     Fensterbreite und das 420px breite Brett schwimmt mittig darin. */
  grid-template-columns: minmax(0, 472px) 270px;
  justify-content: center;
  align-items: start;
}
.game-layout {
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 472px) minmax(0, 472px) minmax(260px, 300px);
  justify-content: center;
  align-items: start;
}
.board-card { display: flex; flex-direction: column; align-items: center; }
.board-card h2, .board-card h3, .board-card p { align-self: stretch; }

.pill {
  float: right; font-weight: 500; font-size: .8rem;
  color: var(--muted); background: rgba(9,24,37,.6);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 .55rem;
}

/* ------------------------------------------------------------------- Flotte */

.fleet-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.fleet-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .55rem; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(9,24,37,.45);
  cursor: pointer;
}
.fleet-item:hover { border-color: var(--accent); }
.fleet-item.selected { border-color: var(--accent); background: rgba(47,168,224,.14); }
.fleet-item.placed { opacity: .62; }
.fleet-item .name { flex: 1; font-size: .88rem; }
.fleet-item .pips { display: flex; gap: 2px; }
.fleet-item .pip { width: 9px; height: 9px; border-radius: 2px; background: var(--ship); }
.fleet-item.placed .pip { background: var(--ok); }
.fleet-item .mark { font-size: .78rem; color: var(--ok); width: 1.2em; text-align: right; }

/* --------------------------------------------------------------- Zug-Banner */

.turn-banner {
  text-align: center; font-weight: 650;
  padding: .7rem 1rem; margin-bottom: 1rem;
  border-radius: 12px; border: 1px solid var(--line);
  background: rgba(9,24,37,.55);
}
.turn-banner.you { border-color: var(--ok); background: rgba(70,185,138,.14); color: #cdf3e3; }
.turn-banner.them { border-color: var(--line); color: var(--muted); }

/* ------------------------------------------------------------ Verlauf / Chat */

.log-card { display: flex; flex-direction: column; max-height: 560px; }
.log {
  flex: 1; overflow-y: auto; min-height: 180px;
  display: flex; flex-direction: column; gap: .3rem;
  padding-right: .3rem; font-size: .86rem;
}
.log-line { padding: .3rem .5rem; border-radius: 7px; background: rgba(9,24,37,.45); }
.log-line.sys { color: var(--muted); background: transparent; padding: .15rem .5rem; }
.log-line.you { border-left: 3px solid var(--accent); }
.log-line.them { border-left: 3px solid #7a5ea8; }
.log-line.chat-you { background: rgba(47,168,224,.13); }
.log-line.chat-them { background: rgba(122,94,168,.15); }
.log-line b { color: var(--ink); }
.chat-row { margin-top: .7rem; }
.chat-row input { flex: 1; }

/* ------------------------------------------------------------------ Overlay */

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(4, 12, 20, .78);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  backdrop-filter: blur(3px);
}
.overlay-card { max-width: 420px; width: 100%; text-align: center; }
.overlay-card .stack { margin-top: 1.2rem; }

/* --------------------------------------------------------------- Responsive */

@media (max-width: 980px) {
  .place-layout, .game-layout { grid-template-columns: minmax(0, 1fr); }
  .log-card { max-height: 420px; }
}


/* ==========================================================================
   Schiffsgrafiken
   ========================================================================== */

.sprite-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.board { position: relative; }

.ship-sprite {
  /* Normales Rasterelement - so sitzt es exakt auf seinen Feldern.
     Das SVG darin ist absolut gesetzt, damit sein Seitenverhaeltnis die
     Zeilenhoehe nicht aufblaeht. */
  position: relative;
  pointer-events: none;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45));
  transition: filter .4s ease, opacity .4s ease;
}
.ship-sprite svg { position: absolute; inset: 1px; width: auto; height: auto; display: block; }

/* Versenkt: absacken, dunkler werden, leicht kippen. */
.ship-sprite.sunk {
  animation: sink 1.1s ease forwards;
  filter: grayscale(.75) brightness(.5) drop-shadow(0 0 6px rgba(0, 0, 0, .6));
}
@keyframes sink {
  0%   { transform: none; opacity: 1; }
  35%  { transform: translateY(2px) rotate(-2deg); }
  100% { transform: translateY(5px) rotate(-4deg); opacity: .72; }
}

/* Einlaufen beim Platzieren */
.ship-sprite.drop { animation: drop-in .38s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes drop-in {
  0%   { transform: scale(.6) translateY(-14px); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

.fleet-icon {
  width: 46px; height: 20px;
  display: flex; align-items: center;
  flex: 0 0 auto;
}
.fleet-icon svg { width: 100%; height: 100%; }
.fleet-item.placed .fleet-icon { filter: grayscale(.4) brightness(1.15); }

/* ==========================================================================
   Animationen
   ========================================================================== */

/* Leichtes Flimmern des Wassers.
   position:absolute nimmt das Pseudo-Element aus dem Grid-Fluss heraus -
   sonst wuerde es als Grid-Item eine Zelle belegen und alles verschieben. */
.board::before {
  content: "";
  position: absolute; inset: 0;
  z-index: 3;          /* liegt ueber den Zellen, daher bewusst sehr dezent */
  pointer-events: none;
  background:
    radial-gradient(120px 60px at 20% 30%, rgba(120, 200, 255, .07), transparent 70%),
    radial-gradient(160px 80px at 75% 70%, rgba(120, 200, 255, .06), transparent 70%);
  animation: drift 11s ease-in-out infinite alternate;
  border-radius: 6px;
}
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(6px, -5px, 0) scale(1.05); }
}

/* --------------------------------------------------------------------------
   Einschlag-Effekte (Partikel werden per JS eingehaengt und wieder entfernt)
   -------------------------------------------------------------------------- */

.fx {
  position: absolute;
  left: 50%; top: 50%;
  width: 0; height: 0;
  pointer-events: none;
  z-index: 4;
}
.fx span {
  position: absolute;
  left: 0; top: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* ---- Treffer: Blitz, Feuerball, Rauch, Funken ---- */

.fx-hit .flash {
  width: 46px; height: 46px;
  background: radial-gradient(circle, #fff 0%, #ffe9a8 40%, rgba(255,233,168,0) 70%);
  animation: fx-flash .22s ease-out forwards;
}
@keyframes fx-flash {
  0%   { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}

.fx-hit .fire {
  width: 34px; height: 34px;
  background: radial-gradient(circle, #fff3c4 0%, #ffb340 32%, #f2622e 58%, #c4291d 78%, rgba(196,41,29,0) 88%);
  animation: fx-fire .75s cubic-bezier(.2,.7,.3,1) forwards;
  filter: blur(.4px);
}
@keyframes fx-fire {
  0%   { transform: translate(-50%, -50%) scale(.25); opacity: 1; }
  40%  { transform: translate(-50%, -60%) scale(1.05); opacity: .95; }
  100% { transform: translate(-50%, -85%) scale(.55); opacity: 0; }
}

.fx-hit .smoke {
  width: 20px; height: 20px;
  background: radial-gradient(circle, rgba(120,120,125,.75) 0%, rgba(90,90,96,.45) 55%, rgba(80,80,85,0) 75%);
  animation: fx-smoke 1.5s ease-out forwards;
  animation-delay: var(--d, 0ms);
  opacity: 0;
}
@keyframes fx-smoke {
  0%   { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
  25%  { opacity: .75; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(calc(1.9 * var(--sc, 1))); opacity: 0; }
}

.fx-hit .spark {
  width: 4px; height: 4px;
  background: #ffd88a;
  box-shadow: 0 0 4px #ffb340;
  animation: fx-spark .62s cubic-bezier(.15,.8,.3,1) forwards;
}
@keyframes fx-spark {
  0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.25); opacity: 0; }
}

/* ---- Fehlschuss: Wassersaeule, Ringe, Tropfen ---- */

.fx-miss .column {
  width: 11px; height: 11px;
  border-radius: 40%;
  background: linear-gradient(180deg, #dff2ff 0%, #8ccbf0 45%, rgba(120,190,230,0) 100%);
  animation: fx-column .5s cubic-bezier(.2,.9,.35,1) forwards;
}
@keyframes fx-column {
  0%   { transform: translate(-50%, -50%) scaleY(.3) scaleX(1.2); opacity: .9; }
  45%  { transform: translate(-50%, -115%) scaleY(2.6) scaleX(.85); opacity: 1; }
  100% { transform: translate(-50%, -150%) scaleY(.6) scaleX(1.3); opacity: 0; }
}

.fx-miss .ring {
  width: 16px; height: 16px;
  border: 2px solid rgba(190, 230, 255, .95);
  background: transparent;
  animation: fx-ring .95s cubic-bezier(.2,.7,.3,1) forwards;
}
.fx-miss .ring.r2 { animation-delay: .16s; border-color: rgba(150, 205, 240, .7); }
@keyframes fx-ring {
  0%   { transform: translate(-50%, -50%) scale(.25); opacity: 1; }
  70%  { opacity: .5; }
  100% { transform: translate(-50%, -50%) scale(2.6); opacity: 0; }
}

.fx-miss .drop {
  width: 4px; height: 5px;
  border-radius: 50% 50% 55% 55%;
  background: #cfe9fb;
  box-shadow: 0 0 3px rgba(190,230,255,.7);
  animation: fx-drop .78s cubic-bezier(.25,.6,.4,1) forwards;
  animation-delay: var(--d, 0ms);
}
@keyframes fx-drop {
  0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  60%  { opacity: .95; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.4); opacity: 0; }
}

/* Getroffene Felder glimmen leicht nach */
.cell.hit { animation: ember 2.6s ease-in-out infinite; }
@keyframes ember {
  0%, 100% { box-shadow: inset 0 0 6px rgba(255, 160, 90, .0); }
  50%      { box-shadow: inset 0 0 9px rgba(255, 160, 90, .45); }
}

/* Erschuetterung des getroffenen Bretts */
.board.shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}

/* Banner beim Zugwechsel */
.turn-banner.pulse { animation: pulse .7s ease; }
@keyframes pulse {
  0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(70, 185, 138, .5); }
  50%  { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(70, 185, 138, 0); }
  100% { transform: scale(1); }
}

/* Anklickbares Gegnerfeld: Fadenkreuz-Puls */
.board.enemy.active .cell:not(.miss):not(.hit):not(.sunk):hover::before {
  content: "";
  position: absolute; inset: 0;
  border: 2px solid var(--accent);
  border-radius: 3px;
  animation: target .9s ease-in-out infinite;
}
.board.enemy .cell { position: relative; }
@keyframes target {
  0%, 100% { opacity: .45; transform: scale(1); }
  50%      { opacity: 1; transform: scale(.86); }
}

/* Spielende-Overlay */
.overlay:not(.hidden) { animation: fade-in .3s ease; }
.overlay:not(.hidden) .overlay-card { animation: rise .42s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise {
  from { transform: translateY(18px) scale(.94); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.overlay[data-result="won"] #over-title { animation: cheer 1.1s ease .1s both; }
@keyframes cheer {
  0%   { transform: scale(.7) rotate(-6deg); }
  45%  { transform: scale(1.12) rotate(3deg); }
  70%  { transform: scale(.98) rotate(-1deg); }
  100% { transform: none; }
}

/* ==========================================================================
   Sprachumschalter
   ========================================================================== */

.lang-switch { display: flex; gap: .3rem; }

.flag {
  width: 30px; height: 21px;
  padding: 0; cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: transparent;
  opacity: .5;
  transition: opacity .15s, transform .15s, border-color .15s;
  display: block;
}
.flag svg { width: 100%; height: 100%; display: block; }
.flag:hover { opacity: .85; transform: translateY(-1px); }
.flag.active { opacity: 1; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}


/* ==========================================================================
   Einstellungen (Schalter)
   ========================================================================== */

body.no-shake .board.shake { animation: none !important; }

body.no-fx .fx { display: none; }
body.no-fx .board::before,
body.no-fx .ship-sprite.drop,
body.no-fx .ship-sprite.sunk,
body.no-fx .turn-banner.pulse,
body.no-fx .cell.hit,
body.no-fx .overlay:not(.hidden),
body.no-fx .overlay:not(.hidden) .overlay-card,
body.no-fx .overlay[data-result="won"] #over-title,
body.no-fx .board.enemy.active .cell:hover::before { animation: none !important; }
body.no-fx .ship-sprite.sunk { opacity: .72; }

.icon-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 1rem; line-height: 1;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); background: rgba(47,168,224,.12); }

.settings-panel {
  position: absolute;
  top: calc(100% + .5rem); right: 1.2rem;
  z-index: 20;
  min-width: 230px;
  padding: .9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #12293c;
  box-shadow: 0 14px 34px rgba(0,0,0,.45);
}
.settings-panel h3 { margin-bottom: .6rem; }
.settings-row {
  display: flex; align-items: center; gap: .55rem;
  padding: .35rem 0;
  font-size: .9rem; cursor: pointer;
}
.settings-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ==========================================================================
   Verlauf und Chat getrennt
   ========================================================================== */

.side-column { display: flex; flex-direction: column; gap: 1rem; }
.side-column .card { padding: .9rem; }

.log { min-height: 120px; max-height: 260px; }
.chat-log {
  display: flex; flex-direction: column; gap: .3rem;
  min-height: 90px; max-height: 200px;
  overflow-y: auto;
  font-size: .86rem;
  padding-right: .3rem;
}
.chat-empty { color: var(--muted); font-size: .84rem; font-style: italic; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .5rem;
}
.card-head h3 { margin: 0; }
