:root {
  --bg: #0b2239;
  --bg-2: #0f3050;
  --card: #13385c;
  --line: rgba(255, 255, 255, 0.12);
  --text: #eaf3fb;
  --muted: #9fb6cc;
  --water: #1a5a8c;
  --water-2: #1f6aa3;
  --ship: #b9c7d4;
  --ship-edge: #8496a8;
  --hit: #ff5a4e;
  --sunk: #8e2a22;
  --miss: #d8e8f5;
  --accent: #ffc83d;
  --primary: #2fa86a;
  --primary-hover: #26905a;
  --danger: #d9443a;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2), var(--bg));
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hidden {
  display: none !important;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.9rem;
}

h2 {
  font-size: 1.3rem;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero {
  text-align: center;
  padding: 28px 0 8px;
}

.hero-icon {
  font-size: 3.2rem;
  line-height: 1;
  margin-bottom: 8px;
}

label {
  font-weight: 600;
}

input[type='text'] {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}

input[type='text']:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  min-height: 48px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border: 2px solid var(--line);
}

.btn.small {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn.wide {
  width: 100%;
}

.row {
  display: flex;
  gap: 10px;
}

.row > .btn {
  flex: 1;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Warteliste ---------- */

.radar {
  width: 96px;
  height: 96px;
  margin: 6px auto 4px;
  border-radius: 50%;
  border: 2px solid rgba(58, 160, 255, 0.6);
  background: radial-gradient(circle, rgba(58, 160, 255, 0.15) 0 30%, transparent 31% 60%, rgba(58, 160, 255, 0.12) 61%);
  position: relative;
  overflow: hidden;
}

.radar span {
  position: absolute;
  inset: 0;
  background: conic-gradient(rgba(58, 160, 255, 0.55), transparent 25%);
  animation: sweep 2s linear infinite;
}

@keyframes sweep {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Kopfzeile im Spiel ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.opp-name {
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opp-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  flex: none;
}

.opp-dot.offline {
  background: var(--danger);
}

.hint {
  font-size: 0.92rem;
  color: var(--muted);
}

.hint.error {
  color: var(--hit);
}

.turn-banner {
  text-align: center;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
}

.turn-banner.mine {
  background: var(--accent);
  color: #1b1b1b;
}

.board-label {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 4px;
}

/* ---------- Spielfeld ---------- */

.board {
  display: grid;
  grid-template-columns: 0.7fr repeat(10, 1fr);
  gap: 2px;
  width: 100%;
}

.small-board {
  width: 72%;
  align-self: center;
}

.board .label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--muted);
  aspect-ratio: 1;
}

.board .label.col {
  aspect-ratio: auto;
  padding-bottom: 2px;
}

.cell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: var(--water);
  position: relative;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.cell:disabled {
  cursor: default;
}

.cell.ship {
  background: var(--ship);
  box-shadow: inset 0 0 0 2px var(--ship-edge);
}

.cell.selected {
  background: var(--accent);
  box-shadow: inset 0 0 0 2px #c79100;
}

.cell.invalid {
  background: var(--hit);
}

.cell.revealed {
  background: rgba(185, 199, 212, 0.55);
}

.cell.target {
  background: var(--water-2);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.cell.target::after {
  content: '';
  position: absolute;
  inset: 22%;
  border: 2px solid var(--accent);
  border-radius: 50%;
}

.cell.miss::after {
  content: '';
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: var(--miss);
  opacity: 0.85;
}

.cell.hit {
  background: var(--hit);
  box-shadow: none;
}

.cell.hit::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8em;
  font-weight: 900;
  color: #fff;
}

.cell.sunk {
  background: var(--sunk);
}

.cell.last {
  animation: pulse 0.9s ease-out 2;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.9);
  }
  100% {
    box-shadow: 0 0 0 8px rgba(255, 200, 61, 0);
  }
}

.small-board .cell {
  border-radius: 3px;
  cursor: default;
}

/* ---------- Flotten-Anzeigen ---------- */

.ship-picker,
.fleet-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ship-chip {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.ship-chip.selected {
  border-color: var(--accent);
  background: rgba(255, 200, 61, 0.15);
}

.ship-chip .pips {
  display: inline-flex;
  gap: 2px;
}

.ship-chip .pips i {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--ship);
}

.fleet-status .ship-chip {
  cursor: default;
  font-size: 0.75rem;
  padding: 4px 8px;
}

.fleet-status .ship-chip.sunk {
  opacity: 0.5;
  text-decoration: line-through;
}

.fleet-status .ship-chip.sunk .pips i {
  background: var(--hit);
}

/* ---------- Ergebnis ---------- */

.result {
  text-align: center;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 800;
}

.result.win {
  border-color: var(--accent);
}

/* ---------- Hinweise und Dialoge ---------- */

.conn-banner {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--danger);
  color: #fff;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #0a1a2b;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
  z-index: 40;
}

.toast.hit {
  background: var(--hit);
  color: #fff;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 22, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.dialog {
  width: 100%;
  max-width: 340px;
}

@media (min-width: 700px) {
  .small-board {
    width: 60%;
  }
}
