/* Schiffe versenken – GameFunJunkies. Dunkles Marine-/Neon-Theme,
   passend zum PengPong-Look (#0d1117-Palette), mit DOM-Boards + CSS-Animationen. */

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #0b1220;
  --line: #30363d;
  --line2: #21262d;
  --ink: #e6edf3;
  --muted: #8b949e;
  --dim: #484f58;
  --accent: #58a6ff;
  --accent2: #1f6feb;
  --blue: #58a6ff;
  --red: #ff7b72;
  --gold: #f2cc60;
  --green: #3fb950;
  --water: #0e2233;
  --water2: #123049;
  --cell: 30px;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, #10233a 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}
body { min-height: 100%; }
button { font-family: inherit; }
a { color: inherit; }

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

/* ---------------- HUD / Kopfleiste ---------------- */
#hud {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: rgba(13,17,23,.85);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 30;
}
.hud-brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; font-weight: 800; letter-spacing: .5px;
  color: var(--ink); white-space: nowrap;
}
.hud-ship { font-size: 22px; filter: drop-shadow(0 0 6px #1f6feb88); }
.hud-name { font-size: 15px; }

.cap-hud {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 14px 5px 6px;
  min-width: 0;
}
.cap-badge {
  font-size: 22px; width: 34px; height: 34px;
  display: grid; place-items: center;
  background: #0b1220; border: 1px solid var(--line); border-radius: 50%;
  flex: none;
}
.cap-meta { min-width: 120px; }
.cap-line { display: flex; align-items: baseline; gap: 8px; font-size: 12px; }
.cap-cap { font-weight: 700; color: var(--ink); }
.cap-rank { color: var(--muted); }
.cap-lvl { color: var(--accent); font-weight: 700; margin-left: auto; }
.cap-bar {
  position: relative; height: 7px; width: 160px; max-width: 40vw;
  background: var(--line2); border-radius: 4px; overflow: visible; margin-top: 4px;
}
.cap-bar > #capBarFill {
  display: block; height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  box-shadow: 0 0 8px #1f6feb99;
  transition: width .8s cubic-bezier(.2,.8,.2,1);
}
.cap-bar-gain {
  position: absolute; right: 0; top: -16px; font-size: 11px; font-weight: 700;
  color: var(--green); opacity: 0; white-space: nowrap;
}
.cap-bar-gain.show { animation: floatUp 1.4s ease-out forwards; }
.cap-xp { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.hud-right { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  text-decoration: none; font-size: 16px; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { border-color: var(--accent); background: #172131; }

.conn-bar {
  text-align: center; font-size: 13px; color: #ffd7a8;
  background: #3d2a12; border-bottom: 1px solid #5a3d1a;
  padding: 6px; display: none;
}
.conn-bar.show { display: block; }

#stage { flex: 1; display: flex; flex-direction: column; padding: 18px 16px 30px; }
.screen { flex: 1; }
[hidden] { display: none !important; }

/* ---------------- Menü ---------------- */
.menu-head { text-align: center; max-width: 680px; margin: 10px auto 6px; }
.menu-title {
  font-size: clamp(26px, 4vw, 40px); letter-spacing: 1px;
  background: linear-gradient(90deg, #79c0ff, #58a6ff 55%, #a5d6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.menu-sub { color: var(--muted); margin-top: 6px; }
.name-field {
  display: inline-flex; flex-direction: column; gap: 4px; margin-top: 16px;
  font-size: 12px; color: var(--muted); text-align: left;
}
.name-field input {
  font-size: 16px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg3); color: var(--ink);
  outline: none; width: min(320px, 80vw);
}
.name-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #1f6feb33; }

.mode-grid {
  display: grid; gap: 14px; margin: 22px auto 0; max-width: 900px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.mode-card {
  position: relative; cursor: pointer; text-align: left;
  background: linear-gradient(160deg, var(--bg2), #10192a);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px 16px; color: var(--ink);
  display: flex; flex-direction: column; gap: 6px;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  overflow: hidden;
}
.mode-card::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120px 80px at 100% 0, #1f6feb22, transparent 70%);
  opacity: 0; transition: opacity .15s;
}
.mode-card:hover {
  transform: translateY(-3px); border-color: var(--accent);
  box-shadow: 0 10px 30px -12px #1f6feb88;
}
.mode-card:hover::after { opacity: 1; }
.mode-icon { font-size: 34px; }
.mode-title { font-size: 20px; font-weight: 800; }
.mode-desc { font-size: 13px; color: var(--muted); min-height: 34px; }
.mode-tag {
  align-self: flex-start; font-size: 11px; font-weight: 700; letter-spacing: .4px;
  background: #1f6feb22; color: var(--accent); border: 1px solid #1f6feb55;
  border-radius: 999px; padding: 2px 10px;
}
.menu-foot { text-align: center; color: var(--dim); margin-top: 18px; font-size: 13px; min-height: 18px; }

/* ---------------- Lobby ---------------- */
.lobby-grid {
  display: grid; gap: 20px; max-width: 1100px; margin: 0 auto;
  grid-template-columns: minmax(260px, 340px) 1fr;
}
@media (max-width: 820px) { .lobby-grid { grid-template-columns: 1fr; } }
.lobby-side {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.lobby-h { font-size: 18px; display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 12px; font-weight: 700; background: #1f6feb22; color: var(--accent);
  border: 1px solid #1f6feb55; border-radius: 999px; padding: 1px 10px;
}
.teams { display: flex; align-items: stretch; gap: 8px; }
.team-col { flex: 1; min-width: 0; }
.team-h { font-weight: 800; font-size: 13px; text-align: center; padding: 4px; border-radius: 8px; }
.team-a { color: var(--blue); background: #1f6feb1a; }
.team-b { color: var(--red); background: #ff7b721a; }
.vs-split { align-self: center; color: var(--dim); font-weight: 800; font-size: 12px; }
.seat-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.seat {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-height: 38px;
}
.seat .s-ava { font-size: 15px; }
.seat .s-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .s-tag { margin-left: auto; font-size: 11px; color: var(--muted); }
.seat.free .s-name { color: var(--dim); font-style: italic; font-weight: 400; }
.seat.me { border-color: var(--accent); box-shadow: 0 0 0 1px #1f6feb55 inset; }
.seat.ready .s-tag { color: var(--green); }
.seat.ai .s-tag { color: var(--gold); }

.lobby-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lobby-hint { font-size: 13px; color: var(--muted); min-height: 18px; }
.backlink { font-size: 13px; color: var(--muted); text-decoration: none; margin-top: auto; }
.backlink:hover { color: var(--accent); }

.place-area {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.place-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.place-head h3 { font-size: 17px; }
.place-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.place-body { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.fleet-tray { list-style: none; display: flex; flex-direction: column; gap: 8px; min-width: 160px; }
.tray-ship {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  transition: border-color .12s, background .12s;
}
.tray-ship:hover { border-color: var(--accent); }
.tray-ship.active { border-color: var(--accent); background: #16233a; box-shadow: 0 0 0 1px #1f6feb55 inset; }
.tray-ship.placed { opacity: .5; }
.tray-ship.placed .ts-cells { filter: grayscale(1); }
.ts-cells { display: flex; gap: 2px; }
.ts-cells i { width: 12px; height: 12px; background: linear-gradient(180deg, #6e7681, #4b5563); border-radius: 2px; display: block; }
.ts-name { font-size: 13px; font-weight: 600; }
.ts-len { font-size: 11px; color: var(--muted); margin-left: auto; }
.place-hint { font-size: 12px; color: var(--dim); }
.place-hint b { color: var(--muted); }

/* ---------------- Boards ---------------- */
.board {
  display: grid;
  grid-template-columns: 18px repeat(10, var(--cell));
  grid-template-rows: 18px repeat(10, var(--cell));
  gap: 2px; user-select: none; touch-action: manipulation;
}
.board .lbl {
  display: grid; place-items: center; font-size: 10px; color: var(--dim); font-weight: 700;
}
.cell {
  position: relative; border-radius: 3px; cursor: default;
  background:
    radial-gradient(70% 70% at 50% 35%, var(--water2), var(--water));
  box-shadow: inset 0 0 0 1px #0a1a2955;
  overflow: hidden;
}
.cell::before {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(135deg, #ffffff05 0 3px, transparent 3px 7px);
  opacity: .5;
}

/* eigene Flotte */
.cell.ship {
  background: linear-gradient(160deg, #7d8590, #4b5563 60%, #3a424e);
  box-shadow: inset 0 0 0 1px #0006, inset 0 2px 3px #ffffff22;
}
.cell.ship.bow-h-start { border-radius: 12px 3px 3px 12px; }
.cell.ship.bow-h-end   { border-radius: 3px 12px 12px 3px; }
.cell.ship.bow-v-start { border-radius: 12px 12px 3px 3px; }
.cell.ship.bow-v-end   { border-radius: 3px 3px 12px 12px; }

/* Treffer / Fehlschuss */
.cell.miss::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: #9fb3c8; box-shadow: 0 0 0 2px #ffffff22;
  animation: ripple .5s ease-out;
}
.cell.hit {
  background: radial-gradient(60% 60% at 50% 45%, #ff9d5c, #e5484d 70%, #7d1416);
}
.cell.hit::after {
  content: "✸"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff4e0; font-size: calc(var(--cell) * .6); text-shadow: 0 0 6px #ff5c33;
}
.cell.hit.fresh { animation: boom .45s ease-out; }
.cell.sunk {
  background: linear-gradient(160deg, #7d1416, #4a0d0e);
  box-shadow: inset 0 0 0 1px #000;
}
.cell.sunk::after {
  content: "💀"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--cell) * .55);
}
.cell.sunk.fresh { animation: sink .6s ease-out; }

/* Platzierungs-Board */
.place-board .cell { cursor: pointer; }
.place-board .cell.hover-ok { background: #17493a; box-shadow: inset 0 0 0 2px #3fb95099; }
.place-board .cell.hover-bad { background: #4a1417; box-shadow: inset 0 0 0 2px #e5484d99; }

/* Board-Karten im Gefecht */
.battle-boards { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: flex-start; }
.board-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .15s, box-shadow .15s;
}
.board-card.own { border-color: #1f6feb55; }
.board-card.enemy { }
.board-card.targetable { cursor: crosshair; }
.board-card.turn-here { box-shadow: 0 0 0 1px var(--gold), 0 8px 30px -14px #f2cc6088; border-color: var(--gold); }
.board-card.dead { opacity: .55; filter: grayscale(.4); }
.bc-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.bc-ava { font-size: 16px; }
.bc-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bc-name.t0 { color: var(--blue); }
.bc-name.t1 { color: var(--red); }
.bc-role { font-size: 11px; color: var(--muted); }
.bc-fleet { margin-left: auto; display: flex; gap: 3px; }
.bc-pip { width: 9px; height: 9px; border-radius: 2px; background: #6e7681; }
.bc-pip.down { background: #e5484d; }
.bc-turn { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--gold); }

/* Radar-Sweep auf anvisierbaren Boards */
.board-wrap { position: relative; }
.board-card.targetable.turn-here .board-wrap::after {
  content: ""; position: absolute; inset: 18px 0 0 18px; pointer-events: none; border-radius: 4px;
  background: conic-gradient(from 0deg, transparent 0deg, #58a6ff22 30deg, transparent 60deg);
  animation: sweep 3s linear infinite; mix-blend-mode: screen;
}
.board-card.targetable .cell:not(.shot):hover {
  outline: 2px solid var(--gold); outline-offset: -2px; z-index: 2;
  background: #2a2f16;
}
.cell.shot { cursor: not-allowed; }

.turn-banner {
  text-align: center; font-size: 16px; font-weight: 700; padding: 10px;
  margin-bottom: 14px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line);
}
.turn-banner.mine { color: #0d1117; background: linear-gradient(90deg, #f2cc60, #ffd97a); border-color: #f2cc60; animation: pulse 1.6s ease-in-out infinite; }
.turn-banner.theirs { color: var(--muted); }

.battle-foot { max-width: 720px; margin: 16px auto 0; width: 100%; }
.battle-log {
  list-style: none; display: flex; flex-direction: column; gap: 3px;
  font-size: 12.5px; color: var(--muted); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  max-height: 120px; overflow: auto;
}
.battle-log li { line-height: 1.4; }
.battle-log li b.t0 { color: var(--blue); }
.battle-log li b.t1 { color: var(--red); }
.battle-log li .ev-hit { color: #ffab70; }
.battle-log li .ev-sunk { color: #ff7b72; font-weight: 700; }

/* ---------------- Buttons ---------------- */
.btn {
  font-size: 14px; font-weight: 600; padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg3); color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); background: #16233a; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.accent { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.accent:hover:not(:disabled) { background: #388bfd; }
.btn.ghost { background: var(--bg3); }
.btn.danger { border-color: #7d1416; color: #ff9d9d; }

/* ---------------- Ergebnis-Overlay ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(1,4,9,.78); backdrop-filter: blur(4px); padding: 16px;
}
.over-box {
  background: linear-gradient(160deg, var(--bg2), #10192a);
  border: 1px solid var(--line); border-radius: 16px; padding: 28px 34px;
  text-align: center; width: min(440px, 94vw); animation: popIn .4s ease-out;
}
.over-icon { font-size: 56px; animation: bob 2.4s ease-in-out infinite; }
.over-box h1 { font-size: 30px; margin: 4px 0; }
.over-box.win h1 { color: var(--gold); }
.over-box.lose h1 { color: var(--red); }
.over-sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.over-xp { background: var(--bg3); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.over-xp-num { font-size: 26px; font-weight: 800; color: var(--green); }
.over-xp-break { list-style: none; font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.over-xp-break li { display: flex; justify-content: space-between; }
.over-levelup {
  font-size: 15px; font-weight: 800; color: var(--gold); margin-bottom: 12px;
  padding: 10px; border-radius: 10px; background: #2a230a; border: 1px solid #6b5613;
  animation: rankPop .6s ease-out;
}
.over-btns { display: flex; gap: 10px; justify-content: center; }
.over-guest { font-size: 11px; color: var(--dim); margin-top: 10px; }

/* ---------------- Toasts ---------------- */
.toast-layer { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; box-shadow: 0 10px 30px -12px #000;
  animation: toastIn .3s ease-out, toastOut .4s ease-in forwards; animation-delay: 0s, 2.4s;
}
.toast.gold { border-color: #6b5613; color: var(--gold); }

/* ---------------- Animationen ---------------- */
@keyframes ripple { from { transform: translate(-50%,-50%) scale(.2); opacity: 0; } to { transform: translate(-50%,-50%) scale(1); opacity: 1; } }
@keyframes boom { 0% { transform: scale(.4); filter: brightness(2.2); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes sink { 0% { transform: scale(1) rotate(0); } 40% { transform: scale(1.1) rotate(-4deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-16px); } }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 #f2cc6055; } 50% { box-shadow: 0 0 0 6px #f2cc6000; } }
@keyframes popIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes rankPop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

/* kleine Screens: Boards kompakter */
@media (max-width: 560px) {
  :root { --cell: 26px; }
  .hud-name { display: none; }
  .cap-meta { min-width: 90px; }
}
