:root {
  --navy-900: #071a30;
  --navy-800: #0b2545;
  --navy-700: #123a63;
  --navy-600: #1b4f86;
  --sea: #13699b;
  --sea-light: #2f95c9;
  --foam: #e8f4fb;
  --sand: #f2d7a0;
  --gold: #ffcf5c;
  --hit: #ff5a4d;
  --hit-deep: #b3271c;
  --miss: #6f97b8;
  --ok: #35c26a;
  --text: #eaf3fb;
  --text-dim: #9fbdd6;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, #12406e 0%, transparent 60%),
    linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
  background-attachment: fixed;
  min-height: 100%;
  overflow-x: hidden;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100%; position: relative; }

.hidden { display: none !important; }

/* ---------- Screens ---------- */
.screen { display: none; padding: 16px 16px calc(16px + var(--safe-b)); animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 24px 8px 12px; }
.logo { font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); animation: bob 4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg);} 50% { transform: translateY(-8px) rotate(3deg);} }
.hero h1 { margin: 8px 0 4px; font-size: 34px; letter-spacing: .5px; }
.tagline { margin: 0; color: var(--text-dim); font-size: 15px; }
.tagline em { color: var(--gold); font-style: normal; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
  backdrop-filter: blur(6px);
}
.card h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
input, select {
  width: 100%;
  padding: 14px 14px;
  font-size: 16px; /* verhindert Zoom auf iOS */
  color: var(--text);
  background: rgba(0,0,0,.28);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--sea-light); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%239fbdd6' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; }

#code-input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 700; font-size: 22px; }

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; }
.join-row .btn { flex: 0 0 auto; }

.divider { text-align: center; margin: 18px 0; position: relative; color: var(--text-dim); font-size: 13px; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: 34%; height: 1px; background: var(--card-border); }
.divider::before { left: 0; } .divider::after { right: 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border: none; border-radius: 12px; padding: 12px 16px;
  color: #fff; background: var(--navy-600);
  transition: transform .08s ease, filter .15s ease, opacity .15s ease;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-big { width: 100%; padding: 16px; font-size: 17px; }
.btn-sm { padding: 9px 12px; font-size: 13px; }
.btn-primary { background: linear-gradient(180deg, var(--sea-light), var(--sea)); box-shadow: 0 6px 16px rgba(19,105,155,.4); }
.btn-secondary { background: rgba(255,255,255,.1); border: 1px solid var(--card-border); }
.btn-ghost { background: transparent; padding: 8px 10px; color: var(--text-dim); }
.btn-fire { background: linear-gradient(180deg, #ff7a4d, var(--hit-deep)); box-shadow: 0 6px 18px rgba(179,39,28,.5); }

/* ---------- Bars / header ---------- */
.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bar-title { font-size: 20px; font-weight: 800; }
.spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.3); border: 1px solid var(--card-border);
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; letter-spacing: 1px;
}

/* ---------- Lobby ---------- */
.code-card { text-align: center; }
.code-label { color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 2px; }
.code-value { font-size: 48px; font-weight: 900; letter-spacing: 10px; margin: 6px 0 12px; color: var(--gold); text-shadow: 0 3px 8px rgba(0,0,0,.4); }
.code-actions { display: flex; gap: 10px; justify-content: center; }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list.compact li { padding: 8px 10px; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.22); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 12px;
}
.player-list li.you { border-color: var(--sea-light); }
.player-list li.dead { opacity: .5; }
.player-list li.current { box-shadow: inset 0 0 0 2px var(--gold); }
.p-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; background: var(--navy-600); flex: 0 0 auto; }
.p-col { flex: 1; min-width: 0; }
.p-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-sub { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.p-rank { flex: 0 0 auto; width: 26px; text-align: center; font-size: 17px; }
.p-meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 8px; align-items: center; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; font-weight: 700; }
.tag.host { background: rgba(255,207,92,.2); color: var(--gold); }
.tag.ready { background: rgba(53,194,106,.2); color: var(--ok); }
.tag.wait { background: rgba(255,255,255,.12); color: var(--text-dim); }
.tag.off { background: rgba(255,90,77,.18); color: var(--hit); }

.hint { text-align: center; color: var(--text-dim); font-size: 14px; margin: 8px 0 0; }

/* Meldung auf der Anmeldeseite (server-seitig eingesetzt) */
.notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--card);
  font-size: 14px;
  line-height: 1.45;
}
.notice.warn { border-color: rgba(255,90,77,.45); background: rgba(255,90,77,.12); }
.footer-note { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 20px; }
.footer-note a { color: var(--text-dim); }

.sticky-bottom {
  position: sticky; bottom: 0; z-index: 5;
  padding: 12px 0 calc(6px + var(--safe-b));
  margin-top: 8px;
  background: linear-gradient(180deg, transparent, var(--navy-900) 55%);
}

/* ---------- Fleet tray ---------- */
.place-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.place-toolbar .btn { flex: 1 1 auto; }

.fleet-tray { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.fleet-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: rgba(0,0,0,.25); border: 1px solid var(--card-border); cursor: pointer;
}
.fleet-chip .dots { display: flex; gap: 2px; }
.fleet-chip .dots i { width: 8px; height: 8px; border-radius: 2px; background: var(--sea-light); display: block; }
.fleet-chip.placed { opacity: .55; }
.fleet-chip.placed .dots i { background: var(--ok); }
.fleet-chip.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255,207,92,.35); }

/* ---------- Grid ---------- */
.grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.grid {
  display: grid;
  gap: 3px;
  margin: 0 auto;
  touch-action: manipulation;
}
.cell {
  aspect-ratio: 1 / 1;
  border-radius: 5px;
  background: rgba(255,255,255,.05);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  position: relative;
  cursor: pointer;
  min-width: 26px;
  transition: background .1s ease, transform .05s ease;
}
.cell.label { background: transparent; color: var(--text-dim); cursor: default; font-size: 11px; }
.cell.water { background: rgba(47,149,201,.10); box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }
.cell.water:active { background: rgba(47,149,201,.22); }
.cell.ship { background: linear-gradient(180deg, #3a5674, #24405e); box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.cell.preview { background: rgba(255,207,92,.35) !important; }
.cell.preview-bad { background: rgba(255,90,77,.4) !important; }

/* Schussmarken: die FARBE (--pc, per JS aus der Spielerfarbe gesetzt) sagt,
   WER geschossen hat; das SYMBOL sagt, was dabei herauskam.
   ● Wasser · ✹ Treffer · ✖ Feld eines versenkten Schiffs. */
.cell.miss { background: rgba(var(--pc, 111,151,184), .18); box-shadow: inset 0 0 0 1px rgba(var(--pc, 111,151,184), .40); }
.cell.miss::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgb(var(--pc, 111,151,184)); opacity: .85; }
.cell.hit { background: rgb(var(--pc, 255,90,77)); }
.cell.hit::after { content: "✹"; color: rgba(7,26,48,.82); font-size: 15px; }
.cell.sunk { background: linear-gradient(rgba(9,20,34,.52), rgba(9,20,34,.52)), rgb(var(--pc, 255,90,77)); }
.cell.sunk::after { content: "✖"; color: #fff; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.55); }
/* Weißer Rand: dieser Schuss kam von dir. */
.cell.by-you { outline: 2px solid rgba(255,255,255,.78); outline-offset: -2px; }
/* Goldene Ecke: hier stand (oder steht) ein eigenes Schiff. Bewusst eine Ecke
   und kein Ring – der Ring gehört dem Rand oben und würde ihn verdecken. */
.cell.myhit::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  border-top: 7px solid var(--gold); border-right: 7px solid transparent;
  filter: drop-shadow(0 0 1px rgba(0,0,0,.75));
}
.cell.target { box-shadow: inset 0 0 0 3px var(--gold); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { filter: brightness(1);} 50% { filter: brightness(1.4);} }

/* ---------- Legende ---------- */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 10px 2px 0; font-size: 12px; color: var(--text-dim); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend .cell { width: 16px; height: 16px; min-width: 0; border-radius: 4px; cursor: default; }
.legend .cell.hit::after, .legend .cell.sunk::after { font-size: 10px; }
.legend .cell.miss::after { width: 5px; height: 5px; }
.legend-note { flex: 1 1 100%; }

/* ---------- Battle ---------- */
.turn-banner {
  text-align: center; font-weight: 800; font-size: 16px;
  padding: 12px; border-radius: 12px; margin-bottom: 12px;
  background: rgba(0,0,0,.25); border: 1px solid var(--card-border);
}
.turn-banner.mine { background: linear-gradient(180deg, rgba(255,207,92,.25), rgba(255,207,92,.08)); border-color: var(--gold); color: var(--gold); }
.turn-banner.out { background: rgba(255,90,77,.12); border-color: rgba(255,90,77,.45); color: var(--hit); }
.target-label { text-align: center; font-size: 14px; color: var(--text-dim); margin-bottom: 8px; }
.target-label.armed { color: var(--gold); font-weight: 700; }

.scoreboard .p-score { font-weight: 800; color: var(--gold); font-size: 15px; }
.log-card { max-height: 220px; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 6px; max-height: 170px; overflow-y: auto; }
.log li { font-size: 13px; color: var(--text-dim); padding: 6px 8px; background: rgba(0,0,0,.18); border-radius: 8px; }
.log li:first-child { color: var(--text); }
.log li.log-sunk { color: #ffb27a; }
.log li.log-eliminated { color: var(--hit); font-weight: 700; background: rgba(255,90,77,.12); }
.log li.log-win { color: var(--gold); font-weight: 800; background: rgba(255,207,92,.12); }

/* ---------- Ereignismeldung (Ausscheiden) ---------- */
.announce {
  position: fixed; left: 50%; top: 16%; transform: translateX(-50%);
  z-index: 60; width: min(92%, 460px);
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px; border-radius: 16px;
  background: linear-gradient(180deg, rgba(13,32,55,.97), rgba(7,20,36,.97));
  border: 2px solid rgb(var(--pc, 255,90,77));
  box-shadow: 0 18px 44px rgba(0,0,0,.6), 0 0 0 6px rgba(var(--pc, 255,90,77), .12);
  animation: announce-in .35s cubic-bezier(.2,.9,.3,1.5);
}
.announce-icon { font-size: 32px; line-height: 1; flex: 0 0 auto; filter: drop-shadow(0 3px 6px rgba(0,0,0,.5)); }
.announce-text { min-width: 0; }
.announce-title { font-size: 17px; font-weight: 800; }
.announce-sub { font-size: 13px; color: var(--text-dim); margin-top: 3px; line-height: 1.35; }
.announce.is-me { border-color: var(--hit); }
.announce.is-me .announce-title { color: var(--hit); }
@keyframes announce-in {
  from { opacity: 0; transform: translate(-50%, -16px) scale(.92); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* ---------- Siegesfeier ---------- */
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 40; }
.confetti i {
  position: absolute; top: -24px; width: 9px; height: 14px; border-radius: 2px;
  animation-name: confetti-fall; animation-timing-function: linear; animation-fill-mode: forwards;
}
.confetti i.round { width: 9px; height: 9px; border-radius: 50%; }
@keyframes confetti-fall {
  from { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate3d(var(--drift, 0px), 106vh, 0) rotate(var(--spin, 360deg)); opacity: .85; }
}

.over-hero { position: relative; }
.over-rank { margin-top: 12px; font-size: 14px; font-weight: 700; color: var(--text-dim); }
.screen.win .over-rank { color: var(--gold); }
.screen.win .logo {
  animation: trophy 1.2s ease-in-out infinite;
  filter: drop-shadow(0 0 24px rgba(var(--pc, 255,207,92), .6));
}
.screen.win h1 { color: var(--gold); text-shadow: 0 0 26px rgba(255,207,92,.45); letter-spacing: 2px; }
@keyframes trophy {
  0%, 100% { transform: scale(1) rotate(-5deg); }
  50% { transform: scale(1.16) rotate(5deg); }
}
.player-list li.winner {
  border-color: rgb(var(--pc, 255,207,92));
  box-shadow: 0 0 0 2px rgba(var(--pc, 255,207,92), .22);
}

@media (prefers-reduced-motion: reduce) {
  .screen.win .logo { animation: none; }
  .announce { animation: none; }
}

/* ---------- Connection banner / toast ---------- */
.conn-banner {
  position: sticky; top: 0; z-index: 20; text-align: center;
  background: var(--hit-deep); color: #fff; font-size: 13px; font-weight: 700;
  padding: 6px; margin: -16px -16px 8px;
}
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
  background: #1c2b3d; color: #fff; padding: 12px 18px; border-radius: 12px;
  border: 1px solid var(--card-border); box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-size: 14px; z-index: 50; max-width: 90%; text-align: center;
  animation: toastin .2s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 10px);} to { opacity: 1; transform: translate(-50%,0);} }

/* ---------- Rules ---------- */
.rules summary { cursor: pointer; font-weight: 700; }
.rules ul { margin: 12px 0 0; padding-left: 20px; color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.rules li { margin-bottom: 8px; }
.rules b { color: var(--text); }

/* Host/Guest sichtbarkeit wird per JS body-Klasse gesteuert */
body:not(.is-host) .host-only { display: none !important; }
body.is-host .guest-only { display: none !important; }
