/* ═══════════════════════════════════════════════════════════════════════════
   Battleship – Schiffe versenken
   Maritimes Theme: dunkle Meerestöne, klare Kontraste
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Reset & Basis ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sea-deep:    #0a1628;
  --sea-mid:     #0d2240;
  --sea-light:   #1a3a6b;
  --sea-bright:  #2456a4;
  --accent:      #00b4d8;
  --accent-glow: #48cae4;
  --hit:         #e63946;
  --hit-glow:    #ff6b6b;
  --miss:        #a8dadc;
  --sunk:        #c1121f;
  --ship-color:  #4a5568;
  --ship-border: #718096;
  --text-light:  #e2e8f0;
  --text-muted:  #94a3b8;
  --border:      rgba(255,255,255,0.1);
  --glass:       rgba(13,34,64,0.8);
  --radius:      8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--sea-deep);
  color: var(--text-light);
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(ellipse at 20% 80%, rgba(0,180,216,0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(36,86,164,0.08) 0%, transparent 60%);
  min-height: 100vh;
}

/* ─── Screens ────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  min-height: 100vh;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; align-items: center; justify-content: center; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 22px;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--sea-deep);
  box-shadow: 0 0 16px rgba(0,180,216,0.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-glow);
  box-shadow: 0 0 24px rgba(0,180,216,0.5);
}

.btn-secondary {
  background: var(--sea-light);
  color: var(--text-light);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--sea-bright); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text-light); border-color: rgba(255,255,255,0.3); }

.btn-large { padding: 14px 32px; font-size: 1.05rem; }
.btn-small { padding: 6px 14px; font-size: 0.85rem; }

.hidden { display: none !important; }

/* ─── Menü ───────────────────────────────────────────────────────────────── */
.menu-container {
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.logo {
  font-size: clamp(2.5rem, 8vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(0,180,216,0.4);
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 40px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.menu-buttons { display: flex; flex-direction: column; gap: 14px; }

.join-form {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.join-form input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--sea-mid);
  color: var(--text-light);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  outline: none;
}
.join-form input:focus { border-color: var(--accent); }

/* ─── Matchmaking ────────────────────────────────────────────────────────── */
.matchmaking-container {
  text-align: center;
  max-width: 460px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(0,180,216,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bot-offer {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  backdrop-filter: blur(8px);
}

.lobby-share {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  backdrop-filter: blur(8px);
  width: 100%;
}

.lobby-link-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--sea-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  width: 100%;
}

#lobby-link-text {
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--accent);
  word-break: break-all;
  flex: 1;
}

.copy-feedback {
  font-size: 0.8rem;
  color: #4ade80;
}

/* ─── Platzierung ────────────────────────────────────────────────────────── */
.placement-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  max-width: 760px;
  width: 100%;
}

.placement-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.placement-layout {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

.ship-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
}

.ship-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--sea-mid);
  transition: all 0.15s;
  user-select: none;
}
.ship-item:hover { background: var(--sea-light); }
.ship-item.selected { border-color: var(--accent); background: rgba(0,180,216,0.1); }
.ship-item.placed { opacity: 0.5; cursor: default; }
.ship-item.placed .ship-preview { background: #4ade80; }

.ship-name { font-size: 0.85rem; color: var(--text-light); flex: 1; }

.ship-preview {
  display: flex;
  gap: 2px;
}
.ship-cell-preview {
  width: 12px;
  height: 12px;
  background: var(--ship-color);
  border-radius: 2px;
  border: 1px solid var(--ship-border);
}

.placement-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.status-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ─── Board ──────────────────────────────────────────────────────────────── */
.board-wrapper {
  display: flex;
  gap: 4px;
}

.board-labels-col {
  display: grid;
  grid-template-rows: 32px repeat(10, 38px);
  gap: 2px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  padding-right: 6px;
}

.board-labels-row {
  display: grid;
  grid-template-columns: repeat(10, 38px);
  gap: 2px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  height: 32px;
  align-items: center;
  margin-bottom: 2px;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, 38px);
  grid-template-rows:    repeat(10, 38px);
  gap: 2px;
}

/* Kleinere Boards im Spielscreen */
.board.board-small {
  grid-template-columns: repeat(10, 30px);
  grid-template-rows:    repeat(10, 30px);
}
.board.board-small + .board-labels-row,
.board-small ~ .board-labels-row { grid-template-columns: repeat(10, 30px); }
.board-wrapper.compact .board-labels-col { grid-template-rows: 26px repeat(10, 32px); }
.board-wrapper.compact .board-labels-row { grid-template-columns: repeat(10, 30px); height: 26px; }

/* Zellen */
.cell {
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.07);
  background: var(--sea-mid);
  position: relative;
  cursor: default;
  transition: background 0.15s, transform 0.1s;
}

/* Platzierungs-Hover */
.cell.hover-valid   { background: rgba(0,180,216,0.25); border-color: var(--accent); }
.cell.hover-invalid { background: rgba(230,57,70,0.25); border-color: var(--hit); }

/* Schiff */
.cell.ship {
  background: var(--ship-color);
  border-color: var(--ship-border);
}

/* Schuss-Ergebnisse */
.cell.miss::after {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, var(--miss) 30%, transparent 70%);
  border-radius: 3px;
}

.cell.hit {
  background: var(--hit);
  border-color: var(--hit-glow);
  box-shadow: 0 0 8px rgba(230,57,70,0.6);
}
.cell.hit::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  color: #fff;
  font-weight: bold;
}

.cell.sunk {
  background: var(--sunk);
  border-color: #ff4444;
}
.cell.sunk::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  color: rgba(255,255,255,0.8);
  font-weight: bold;
}

/* Gegner-Board: anklickbar wenn es mein Zug ist */
.board-enemy .cell { cursor: crosshair; }
.board-enemy .cell:hover:not(.miss):not(.hit):not(.sunk) {
  background: rgba(0,180,216,0.2);
  border-color: var(--accent);
  transform: scale(1.05);
}
.board-enemy.disabled .cell { cursor: not-allowed; }
.board-enemy.disabled .cell:hover { background: var(--sea-mid); transform: none; border-color: rgba(255,255,255,0.07); }

/* Shot-Animation */
@keyframes shotPop {
  0%   { transform: scale(1.6); }
  100% { transform: scale(1); }
}
.cell.animate { animation: shotPop 0.25s ease-out; }

/* ─── Spiel-Screen ───────────────────────────────────────────────────────── */
#screen-game.active {
  flex-direction: column;
  justify-content: flex-start;
  padding: 12px;
  gap: 12px;
}

.game-header {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto;
}

.turn-indicator {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 20px;
  background: var(--sea-mid);
  border: 1px solid var(--border);
  transition: all 0.3s;
}
.turn-indicator.my-turn {
  background: rgba(0,180,216,0.15);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 16px rgba(0,180,216,0.2);
}
.turn-indicator.opponent-turn { color: var(--text-muted); }

.game-layout {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.board-section { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.board-section h3 { font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }

.game-log {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  max-height: 100px;
  overflow-y: auto;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
}

.log-entry { line-height: 1.5; }
.log-hit   { color: var(--hit-glow); }
.log-sunk  { color: #ff6b6b; font-weight: 600; }
.log-miss  { color: var(--miss); }
.log-win   { color: #4ade80; font-weight: 700; }

/* ─── Ergebnis-Screen ────────────────────────────────────────────────────── */
.result-container {
  text-align: center;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.result-icon {
  font-size: 5rem;
  line-height: 1;
}

#result-title {
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 800;
}

#result-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
}

.result-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: var(--sea-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.9rem;
  max-width: 300px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
}
.toast.error { border-color: var(--hit); background: rgba(230,57,70,0.15); }
.toast.success { border-color: #4ade80; background: rgba(74,222,128,0.1); }

@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(20px); } }

/* ─── Keyboard-Hint ─────────────────────────────────────────────────────── */
kbd {
  background: var(--sea-light);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.85em;
  font-family: monospace;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .placement-layout { flex-direction: column; align-items: center; }
  .ship-list { flex-direction: row; flex-wrap: wrap; justify-content: center; min-width: unset; }
  .game-layout { gap: 16px; }
  .board { grid-template-columns: repeat(10, 28px); grid-template-rows: repeat(10, 28px); }
  .board.board-small { grid-template-columns: repeat(10, 24px); grid-template-rows: repeat(10, 24px); }
  .board-labels-col { grid-template-rows: 28px repeat(10, 30px); }
  .board-labels-row { grid-template-columns: repeat(10, 28px); }
  .board-wrapper.compact .board-labels-col { grid-template-rows: 24px repeat(10, 26px); }
  .board-wrapper.compact .board-labels-row { grid-template-columns: repeat(10, 24px); }
}
