:root {
  --bg-top: #0e4a6e;
  --bg-bottom: #04192a;
  --card: rgba(255, 255, 255, 0.07);
  --card-border: rgba(255, 255, 255, 0.14);
  --text: #e8f4fb;
  --muted: #9cc2d8;
  --water: #2c84b6;
  --water-dark: #1d6290;
  --water-hover: #4aa7dc;
  --accent: #ffb347;
  --accent-text: #3a2200;
  --good: #5fd38d;
  --bad: #ff6b6b;
  --hit: #d9534f;
  --gap: 2px;
  --cell: min(34px, calc((100vw - 56px) / 11));
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%) fixed;
  padding: 0 16px 32px;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

/* --- Deko-Blasen ------------------------------------------------------- */

.bubbles { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.bubbles span {
  position: absolute;
  bottom: -40px;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.05);
  animation: rise 14s linear infinite;
}
.bubbles span:nth-child(1) { left: 6%;  animation-duration: 16s; }
.bubbles span:nth-child(2) { left: 18%; width: 8px; height: 8px; animation-delay: 3s; }
.bubbles span:nth-child(3) { left: 31%; width: 20px; height: 20px; animation-delay: 7s; animation-duration: 19s; }
.bubbles span:nth-child(4) { left: 47%; animation-delay: 1s; }
.bubbles span:nth-child(5) { left: 62%; width: 10px; height: 10px; animation-delay: 5s; }
.bubbles span:nth-child(6) { left: 74%; width: 24px; height: 24px; animation-delay: 9s; animation-duration: 21s; }
.bubbles span:nth-child(7) { left: 86%; width: 9px; height: 9px; animation-delay: 2s; }
.bubbles span:nth-child(8) { left: 94%; animation-delay: 11s; }
@keyframes rise {
  0%   { transform: translate(0, 0); opacity: 0; }
  10%  { opacity: 1; }
  50%  { transform: translate(14px, -55vh); }
  100% { transform: translate(-6px, -110vh); opacity: 0; }
}

/* --- Kopf ------------------------------------------------------------- */

.top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 0 8px;
}
.top h1 { margin: 0; font-size: clamp(1.6rem, 5vw, 2.4rem); letter-spacing: 0.5px; }
.logo { display: inline-block; animation: swim 3s ease-in-out infinite; }
@keyframes swim {
  0%, 100% { transform: translateX(0) rotate(0); }
  50% { transform: translateX(-6px) rotate(-6deg); }
}
.code-badge {
  font-family: ui-monospace, Consolas, monospace;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--muted);
}

.mute-btn { padding: 4px 10px; border-radius: 999px; }

main { max-width: 960px; margin: 0 auto; }

/* --- Bausteine -------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 16px 20px;
  backdrop-filter: blur(4px);
}

.btn {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #ffc46e; }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.wide { width: 100%; }

input {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hint { color: var(--muted); font-size: 0.9rem; margin: 8px 0 0; }
.msg { color: var(--bad); min-height: 1.2em; margin: 4px 0 0; }

/* --- Lobby ------------------------------------------------------------ */

.lobby { max-width: 380px; margin: 24px auto; display: flex; flex-direction: column; gap: 14px; }
.tagline { margin: 0; text-align: center; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--card-border); }
.join-row { display: flex; gap: 8px; }
.join-row input {
  text-transform: uppercase;
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 4px;
  text-align: center;
}

/* --- Status & Einladung ------------------------------------------------ */

.status {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  margin: 12px auto 16px;
  padding: 10px 16px;
  border-radius: 12px;
  max-width: 640px;
  background: var(--card);
  border: 1px solid var(--card-border);
  transition: background 0.2s, color 0.2s;
}
.status.my-turn { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.status.win { background: var(--good); color: #05301a; border-color: transparent; }
.status.lose { background: var(--hit); color: #fff; border-color: transparent; }

.invite { max-width: 640px; margin: 0 auto 16px; text-align: center; }
.invite p { margin: 0 0 8px; }
.invite-link { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.invite-link code {
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 10px;
  border-radius: 8px;
  word-break: break-all;
}
.invite strong { font-family: ui-monospace, Consolas, monospace; letter-spacing: 2px; color: var(--accent); }

.over { max-width: 640px; margin: 0 auto 16px; text-align: center; }
.over-text { font-size: 1.2rem; margin-bottom: 12px; }

/* --- Spielfelder ------------------------------------------------------ */

.boards { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; }
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.board-wrap h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }

.board {
  display: grid;
  grid-template-columns: repeat(11, var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  padding: 8px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 14px;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow 0.25s;
}
.board.active { box-shadow: 0 0 0 3px var(--accent), 0 0 28px rgba(255, 179, 71, 0.35); }

.lbl {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.38);
  color: var(--muted);
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: calc(var(--cell) * 0.62);
  line-height: 1;
  background-color: var(--water);
  background-image: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.16), transparent 60%);
  transition: background-color 0.15s;
}

/* Fischbilder liegen als eigene Gitter-Elemente über den Zellen und gehen über die ganze
   Fischlänge. Das SVG ist immer waagerecht gezeichnet und wird für senkrechte Fische gedreht. */
.fishimg { position: relative; z-index: 1; pointer-events: none; }
.fishimg svg {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--len) * var(--cell) + (var(--len) - 1) * var(--gap));
  height: calc(var(--cell) * 1.4);
  transform: translate(-50%, -50%);
  overflow: visible;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}
.fishimg.v svg { transform: translate(-50%, -50%) rotate(90deg); }
/* Gefangene Fische treiben bauchoben, grau und mit rotem Rahmen um die ganze Fischlänge */
.fishimg.sunk svg {
  transform: translate(-50%, -50%) scaleY(-1);
  filter: grayscale(1) brightness(0.95) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
}
.fishimg.sunk::before {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid var(--hit);
  border-radius: 6px;
  box-shadow: 0 0 10px rgba(217, 83, 79, 0.6);
}
.fishimg.v.sunk svg { transform: translate(-50%, -50%) rotate(90deg) scaleY(-1); }
.fishimg.revealed { opacity: 0.6; }
.fishimg.ghost { opacity: 0.75; }

/* Markierungen liegen über den Fischbildern: Wasserringe = daneben, rot-weiße Pose = Biss */
.cell.miss::after,
.cell.hit::after {
  content: "";
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
}
.cell.miss { background-color: var(--water-dark); }
.cell.miss::after {
  width: 42%;
  height: 42%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 calc(var(--cell) * 0.1) rgba(255, 255, 255, 0.15);
}
.cell.hit::after {
  width: 42%;
  height: 42%;
  background: linear-gradient(#e53935 0 50%, #fff 50%);
  border: 2px solid #3a0d0d;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.cell.fish { background-color: #2577a8; }
.cell.hit:not(.fish) { background-color: var(--hit); }
.cell.sunkcell {
  background-color: #5a2433;
  background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.3) 0 4px, transparent 4px 8px);
}
.cell.sunkcell::after { display: none; }
.cell.hint { background-color: var(--water-dark); opacity: 0.55; }

/* Platzieren */
#myBoard.placing .cell { cursor: pointer; }
.cell.preview.ok { background-color: rgba(95, 211, 141, 0.6); }
.cell.preview.bad { background-color: rgba(255, 107, 107, 0.75); }

/* Zielen */
.board.active .cell.target { cursor: crosshair; }
.board.active .cell.target:hover { background-color: var(--water-hover); box-shadow: inset 0 0 0 2px var(--accent); }

/* Letzter Wurf pulsiert kurz (als eigene Ebene, damit der Ring auch über Fischen sichtbar ist) */
.cell.last::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 4px;
  pointer-events: none;
  animation: pulse 1.1s ease-out 2;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.9); }
  100% { box-shadow: 0 0 0 12px rgba(255, 255, 255, 0); }
}

/* Animationen für den letzten Wurf. Sie laufen nur an, wenn ein Feld die Klasse neu bekommt. */

/* Daneben: Wasserringe breiten sich aus */
.cell.last.miss::before {
  inset: 18%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  opacity: 0;
  animation: ripple 0.9s ease-out 2;
}
.cell.last.miss::after { animation: drop-in 0.4s ease-out; }
@keyframes ripple {
  0%   { transform: scale(0.3); opacity: 1; }
  100% { transform: scale(1.9); opacity: 0; }
}
@keyframes drop-in {
  0%   { transform: translate(-50%, -50%) scale(0); }
  70%  { transform: translate(-50%, -50%) scale(1.25); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* Biss: die Pose wird unter Wasser gezogen und taucht wieder auf */
.cell.last.hit::before { animation-name: pulse-hit; }
.cell.last.hit::after { animation: bite 0.55s ease-in-out 2; }
@keyframes pulse-hit {
  0%   { box-shadow: 0 0 0 0 rgba(255, 90, 80, 0.95); }
  100% { box-shadow: 0 0 0 14px rgba(255, 90, 80, 0); }
}
@keyframes bite {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-50%, -15%) scale(0.85); }
  55% { transform: translate(-50%, -70%); }
  80% { transform: translate(-50%, -42%); }
}

/* Gefangen: der Fisch dreht sich auf den Rücken, der Rahmen blinkt auf */
.fishimg.sunk.fresh svg { animation: belly-up 0.8s ease-in-out; }
.fishimg.v.sunk.fresh svg { animation-name: belly-up-v; }
.fishimg.sunk.fresh::before { animation: frame-flash 0.45s ease-in-out 3; }
@keyframes belly-up {
  from {
    transform: translate(-50%, -50%) scaleY(1);
    filter: grayscale(0) brightness(1) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
  }
}
@keyframes belly-up-v {
  from {
    transform: translate(-50%, -50%) rotate(90deg) scaleY(1);
    filter: grayscale(0) brightness(1) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
  }
}
@keyframes frame-flash {
  50% { border-color: #fff; box-shadow: 0 0 22px rgba(255, 90, 80, 1); }
}

@media (prefers-reduced-motion: reduce) {
  .cell.last::before, .cell.last::after,
  .fishimg.fresh svg, .fishimg.fresh::before { animation: none !important; }
}

/* --- Fischauswahl & Flotten --------------------------------------------- */

.place-tools { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 380px; }
.fish-picker { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.pick {
  font: inherit;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
}
.pick.selected { outline: 2px solid var(--accent); background: rgba(255, 179, 71, 0.18); }
.pick.placed { opacity: 0.55; }
.pick.placed::after { content: "✓"; color: var(--good); font-weight: 700; }
.tool-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Kleine Fischbilder in Auswahl und Flottenliste – Breite passend zur Länge */
.mini { display: inline-block; width: calc(var(--len) * 15px); height: 16px; flex: none; }
.mini svg { display: block; width: 100%; height: 100%; overflow: visible; }

kbd {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8em;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--card-border);
  border-bottom-width: 2px;
  background: rgba(0, 0, 0, 0.25);
}
.dir-icon { display: inline-block; min-width: 1em; font-weight: 700; color: var(--accent); }

.fleet { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 380px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
}
.chip small { color: var(--muted); }
.chip.sunk {
  text-decoration: line-through;
  background: rgba(217, 83, 79, 0.2);
  border-color: var(--hit);
}
.chip.sunk .mini svg { filter: grayscale(1); transform: scaleY(-1); }

/* --- Chat & Fangbuch ---------------------------------------------------- */

.side-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-top: 24px; }
.side-row .card { flex: 1 1 300px; max-width: 640px; min-width: 0; }
.side-row h3 { margin: 0 0 8px; font-size: 1rem; color: var(--muted); font-weight: 600; }

.chat {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
}
.chat li {
  max-width: 85%;
  padding: 6px 10px;
  border-radius: 12px 12px 12px 4px;
  background: rgba(255, 255, 255, 0.1);
  align-self: flex-start;
  overflow-wrap: anywhere;
}
.chat li.mine {
  align-self: flex-end;
  border-radius: 12px 12px 4px 12px;
  background: var(--accent);
  color: var(--accent-text);
}
.chat li small { display: block; font-size: 0.75rem; opacity: 0.7; }
.chat li.emoji { font-size: 1.8rem; line-height: 1.1; }
.chat li.emoji small { font-size: 0.75rem; }
.chat .empty { color: var(--muted); background: none; align-self: center; font-style: italic; }
.chat-quick { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chat-quick button {
  font-size: 1.1rem;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.chat-quick button:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.12); }
.chat-form { display: flex; gap: 8px; }
.chat-form input { padding: 6px 10px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow-y: auto; font-size: 0.92rem; }
.log li { padding: 4px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.log li:first-child { font-weight: 600; }

.footer-row { display: flex; justify-content: center; margin-top: 16px; }

/* --- Toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #0b2233;
  border: 1px solid var(--card-border);
  padding: 10px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 32px);
  z-index: 10;
}
