/* ==============================
   SCHIFFE VERSENKEN – NAVAL STYLE
   ============================== */
@import url('https://fonts.googleapis.com/css2?family=VT323&family=Share+Tech+Mono&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --sea:      #0a1628;
  --sea-light:#162a4a;
  --hit:      #ef4444;
  --miss:     #4a5568;
  --ship:     #64748b;
  --ship-sunk:#991b1b;
  --water:    #1e3a5f;
  --cyan:     #00e5ff;
  --amber:    #fcd34d;
  --green:    #22c55e;
  --dark:     #0a0e17;
  --panel:    rgba(0,229,255,0.04);
  --border:   rgba(0,229,255,0.25);
  --glow:     0 0 8px #00e5ff, 0 0 20px rgba(0,229,255,0.3);
  --font-mono:'Share Tech Mono', 'Courier New', monospace;
  --font-pixel:'VT323', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font-mono);
  background: var(--dark);
  color: var(--cyan);
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.12) 2px, rgba(0,0,0,0.12) 4px);
  pointer-events: none; z-index: 9998;
}

.hidden { display: none !important; }

/* ── Setup ── */
#game-setup {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.setup-card {
  background: var(--panel); border: 1px solid var(--border);
  padding: 40px 32px;
  max-width: 420px; width: 100%; text-align: center;
  box-shadow: var(--glow);
}
.setup-logo { font-size: 3rem; margin-bottom: 8px; }
h1 {
  font-family: var(--font-pixel); font-size: 2.5rem;
  text-shadow: var(--glow); margin-bottom: 4px;
}
.blink { animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0; } }
.setup-subtitle { color: #94a3b8; font-size: .9rem; margin-bottom: 24px; }
.back-btn {
  display: inline-block; color: var(--cyan); text-decoration: none;
  font-size: .85rem; margin-bottom: 16px; opacity: .7;
  transition: opacity .2s;
}
.back-btn:hover { opacity: 1; }

.form-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.settings-row { flex-direction: row; align-items: center; justify-content: center; gap: 12px; }

input[type="text"], select {
  background: rgba(0,229,255,0.06); border: 1px solid var(--border);
  color: var(--cyan); padding: 12px 16px;
  font-family: var(--font-mono); font-size: 1rem;
  text-align: center; outline: none; width: 100%;
}
input::placeholder { color: rgba(0,229,255,0.35); }
select { cursor: pointer; width: auto; }
label { font-size: .9rem; white-space: nowrap; }

.btn-primary {
  background: linear-gradient(135deg, #00e5ff, #0284c7);
  color: #000; font-weight: bold; border: none;
  padding: 14px 28px; font-size: 1rem;
  cursor: pointer; width: 100%; margin-top: 8px;
  font-family: var(--font-mono); letter-spacing: 1px;
  transition: transform .15s, box-shadow .15s;
}
.btn-primary:hover { transform: scale(1.03); box-shadow: var(--glow); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: transparent; border: 1px solid var(--border);
  color: var(--cyan); padding: 10px 20px;
  cursor: pointer; font-family: var(--font-mono); font-size: .9rem;
  transition: background .2s;
}
.btn-secondary:hover { background: rgba(0,229,255,0.1); }
.btn-secondary.active {
  background: rgba(252,211,77,0.15);
  border-color: var(--amber);
  color: var(--amber);
}

.btn-danger-sm {
  background: transparent; border: 1px solid #ef4444;
  color: #ef4444; padding: 8px 16px;
  cursor: pointer; font-family: var(--font-mono); font-size: .8rem;
  margin-top: 12px;
}

.or-divider { color: #475569; margin: 12px 0; font-size: .85rem; }
.invite-hint { color: var(--amber); margin-bottom: 12px; font-size: .9rem; }
.status-msg { color: #94a3b8; font-size: .85rem; margin-top: 16px; }

/* ── QR ── */
#qrcode-wrapper {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.qr-card {
  background: var(--panel); border: 1px solid var(--border);
  padding: 32px; text-align: center;
  box-shadow: var(--glow);
}
.qr-card h2 { margin-bottom: 16px; font-family: var(--font-pixel); }
.qr-card p { color: #94a3b8; margin: 12px 0; font-size: .9rem; }
#qrcode-with-id { display: inline-block; margin: 16px auto; }
#qrcode-id { color: var(--amber); margin-top: 8px; font-size: .85rem; }

/* ── Phase Header ── */
.phase-header {
  text-align: center; padding: 16px 20px 8px;
}
.phase-header h2 { font-family: var(--font-pixel); font-size: 1.6rem; }
.phase-header p { color: #94a3b8; font-size: .85rem; margin-top: 4px; }

/* ── Ship Selector ── */
#ship-selector {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; padding: 8px 16px 12px;
}
.ship-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--sea-light); border: 2px solid var(--border);
  color: var(--cyan); padding: 8px 14px;
  cursor: pointer; font-family: var(--font-mono); font-size: .85rem;
  transition: all .2s;
}
.ship-btn:hover { background: rgba(0,229,255,0.15); }
.ship-btn.selected { border-color: var(--amber); color: var(--amber); box-shadow: 0 0 8px rgba(252,211,77,0.3); }
.ship-btn.placed { border-color: var(--green); color: var(--green); opacity: .6; cursor: default; }
.ship-cells { display: flex; gap: 2px; }
.ship-cells.vertical { flex-direction: column; }
.ship-cell-preview {
  width: 14px; height: 14px; background: var(--ship);
}
.ship-btn.placed .ship-cell-preview { background: var(--green); }

/* ── Game Grid ── */
.game-grid {
  display: inline-grid; gap: 2px;
  background: #0d1b2a; padding: 2px;
  border: 1px solid var(--border);
}
.game-grid .cell {
  width: 36px; height: 36px;
  background: var(--water);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; transition: background .15s;
  position: relative; cursor: default;
}
.game-grid.clickable .cell { cursor: crosshair; }
.game-grid.clickable .cell:hover { background: rgba(0,229,255,0.25); }
.game-grid.notes-active .cell { cursor: cell; }
.game-grid.notes-active .cell:hover { background: rgba(252,211,77,0.2); }

.cell.ship { background: var(--ship); cursor: grab; }
.cell.ship-selected { background: var(--amber); cursor: grab; }
.cell.hit { background: #4a5568; }
.cell.hit::after {
  content: '\2716'; color: #cbd5e1; font-size: 1.1rem; font-weight: bold;
}
.cell.miss { background: var(--miss); }
.cell.miss::after {
  content: '\2022'; color: #94a3b8; font-size: 1.4rem;
}
.cell.sunk { background: var(--ship-sunk); }
.cell.sunk::after {
  content: '\2716'; color: #fca5a5; font-size: 1.1rem; font-weight: bold;
}
.cell.mark { position: relative; }
.cell.mark::before {
  content: '\2022'; color: rgba(252,211,77,0.5); font-size: .9rem;
  position: absolute;
}
.cell.preview { background: rgba(100,116,139,0.5); }
.cell.preview-invalid { background: rgba(239,68,68,0.3); }
.cell.anchor {
  background: var(--amber) !important;
  box-shadow: inset 0 0 8px rgba(252,211,77,0.8);
}
.cell.endpoint {
  background: rgba(34,197,94,0.5) !important;
  cursor: pointer !important;
  animation: pulse-endpoint 1s infinite;
}
.cell.endpoint:hover {
  background: rgba(34,197,94,0.8) !important;
}
@keyframes pulse-endpoint {
  50% { background: rgba(34,197,94,0.3) !important; }
}
.ship-delete-btn {
  position: absolute; inset: 0;
  background: rgba(239,68,68,0.7);
  color: #fff; border: none;
  font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
.ship-delete-btn:hover { background: rgba(239,68,68,0.95); }

/* ── Board Labels ── */
.board-labels {
  display: flex; gap: 2px; padding: 0 2px; margin-bottom: 2px;
}
.board-labels .lbl {
  width: 36px; text-align: center; font-size: .7rem;
  color: #64748b; font-family: var(--font-pixel);
}
.board-labels-left {
  display: flex; flex-direction: column; gap: 2px;
  padding: 2px 4px 2px 0;
}
.board-labels-left .lbl {
  height: 36px; display: flex; align-items: center; justify-content: center;
  font-size: .7rem; color: #64748b; font-family: var(--font-pixel);
  min-width: 18px;
}
.board-row-wrapper { display: flex; }

#placement-board-wrapper, .board-section {
  display: flex; flex-direction: column; align-items: center;
  margin: 8px auto;
}

/* ── Notes Toggle ── */
#notes-toggle-wrapper {
  text-align: center; padding: 4px 16px;
}

/* ── Boards Container (shooting) ── */
#boards-container {
  display: flex; gap: 16px; justify-content: center;
  align-items: flex-start;
  flex-wrap: nowrap; padding: 0 16px 12px;
  --board-size: 10;
}
.board-section h3 {
  font-family: var(--font-pixel); font-size: 1.1rem;
  text-align: center; margin-bottom: 4px;
}
.board-hint { color: #64748b; font-size: .75rem; font-weight: normal; }

/* Attack board: 80% of viewport width (portrait) or height (landscape) */
/* Cell size = available space / board-size, with gap overhead */
.board-section:first-child .game-grid .cell {
  width: calc((80vw - 60px) / var(--board-size));
  height: calc((80vw - 60px) / var(--board-size));
  max-width: 52px; max-height: 52px;
}
.board-section:first-child .board-labels .lbl {
  width: calc((80vw - 60px) / var(--board-size));
  max-width: 52px;
}
.board-section:first-child .board-labels-left .lbl {
  height: calc((80vw - 60px) / var(--board-size));
  max-height: 52px;
}

/* Own board: smaller, right side */
.board-section:last-child .game-grid .cell { width: 24px; height: 24px; font-size: .7rem; }
.board-section:last-child .board-labels .lbl { width: 24px; font-size: .6rem; }
.board-section:last-child .board-labels-left .lbl { height: 24px; font-size: .6rem; }

/* Landscape: attack board sized by height instead */
@media (orientation: landscape) {
  .board-section:first-child .game-grid .cell {
    width: calc((70vh - 60px) / var(--board-size));
    height: calc((70vh - 60px) / var(--board-size));
    max-width: 52px; max-height: 52px;
  }
  .board-section:first-child .board-labels .lbl {
    width: calc((70vh - 60px) / var(--board-size));
    max-width: 52px;
  }
  .board-section:first-child .board-labels-left .lbl {
    height: calc((70vh - 60px) / var(--board-size));
    max-height: 52px;
  }
}

/* ── Placement Controls ── */
#placement-controls {
  display: flex; gap: 10px; justify-content: center;
  padding: 8px 16px 4px; flex-wrap: wrap;
}

/* Mobile: Placement controls sticky am unteren Rand, Drehen-Button hervorgehoben */
@media (max-width: 768px) {
  #placement-controls {
    position: sticky; bottom: 0; z-index: 50;
    background: var(--sea); border-top: 1px solid var(--border);
    padding: 10px 16px;
  }
  #rotate-btn {
    font-size: 1.1rem; padding: 10px 20px;
    order: -1; /* Drehen-Button links/oben */
  }
}

/* ── Players Bar ── */
#players-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 12px 16px; text-align: center;
}
.player-info { font-size: 1rem; }
.player-info.self { color: var(--cyan); font-weight: bold; }
.player-info.opponent { color: var(--hit); font-weight: bold; }
#turn-indicator { color: #94a3b8; font-size: .9rem; }
#turn-text { font-weight: bold; }

#status-banner {
  text-align: center; padding: 8px;
  font-family: var(--font-pixel); font-size: 1.2rem;
  animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .6; } }
.banner-my-turn { color: var(--green); }
.banner-waiting { color: var(--amber); }

/* ── Ship Status ── */
#ship-status-bar {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 16px; font-size: .8rem;
}
.ship-status-section {
  display: flex; align-items: center; gap: 10px;
  justify-content: center; flex-wrap: wrap;
}
.ship-status-label {
  font-family: var(--font-pixel); font-size: .75rem;
  min-width: 90px; text-align: right;
}
.ship-status-items {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.ship-type-status {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 6px; border: 1px solid var(--border);
  background: var(--sea-light);
}
.ship-type-status.all-sunk {
  opacity: .4; text-decoration: line-through;
  border-color: var(--hit);
}
.ship-vis {
  display: flex; gap: 1px;
}
.ship-dot-sm {
  width: 8px; height: 8px;
  background: var(--ship); display: inline-block;
}
.ship-type-status.all-sunk .ship-dot-sm { background: var(--ship-sunk); }
.ship-count {
  font-family: var(--font-mono); font-size: .75rem;
  color: #94a3b8; margin-left: 2px;
}

/* ── Result Overlay ── */
#result-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
}
#result-content {
  background: var(--panel); border: 1px solid var(--border);
  padding: 40px; text-align: center;
  box-shadow: var(--glow); max-width: 400px;
}
#result-content h2 { font-family: var(--font-pixel); font-size: 2rem; margin-bottom: 8px; }
#result-content p { color: #94a3b8; margin-bottom: 16px; }

/* ── Game Controls ── */
#game-controls {
  display: flex; gap: 10px; justify-content: center; padding: 12px 16px;
}

/* ── Chat ── */
#chat-panel {
  position: fixed; bottom: 0; right: 16px;
  width: 300px; z-index: 9000;
  border: 1px solid var(--border); border-bottom: none;
  overflow: hidden;
  background: var(--sea);
}
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--sea-light); cursor: pointer;
  font-size: .85rem;
}
#chat-header button {
  background: none; border: none; color: var(--cyan); cursor: pointer; font-size: 1rem;
}
.chat-badge {
  background: var(--hit); color: #fff; font-size: .7rem;
  padding: 2px 6px; margin-left: 6px;
}
#chat-body { max-height: 200px; display: flex; flex-direction: column; }
#chat-body.hidden { display: none; }
#chat-messages {
  flex: 1; overflow-y: auto; padding: 8px;
  max-height: 150px; font-size: .8rem;
}
#chat-input-row { display: flex; gap: 4px; padding: 6px 8px; }
#chat-input {
  flex: 1; background: rgba(0,229,255,0.06); border: 1px solid var(--border);
  color: var(--cyan); padding: 6px 10px;
  font-family: var(--font-mono); font-size: .8rem; outline: none;
}
#chat-send {
  background: var(--cyan); color: #000; border: none;
  padding: 6px 10px; cursor: pointer;
}
#chat-messages { display: flex; flex-direction: column; }
.chat-msg { margin-bottom: 4px; max-width: 85%; }
.chat-msg.self { align-self: flex-start; text-align: left; }
.chat-msg.other { align-self: flex-end; text-align: right; }
.chat-msg.self .chat-name { color: var(--cyan); }
.chat-msg.other .chat-name { color: var(--amber); }
.chat-msg.system { align-self: center; color: #64748b; font-style: italic; max-width: 100%; }
.chat-msg.admin-msg { align-self: flex-start; border-left: 2px solid var(--amber); padding-left: 8px; background: rgba(255,215,0,0.06); }
.admin-name { color: var(--amber) !important; }
.chat-name { font-size: .75rem; font-weight: bold; }
.chat-text { color: #e2e8f0; }


/* ── Snackbar ── */
#snackbar {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  background: var(--sea-light); color: var(--cyan);
  border: 1px solid var(--border); padding: 10px 24px;
  font-size: .9rem; z-index: 10000;
  opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
#snackbar.show { opacity: 1; }

/* ── Responsive ── */
@media (max-width: 768px) {
  #boards-container { flex-direction: column; gap: 12px; align-items: center; }
  /* Attack board: 90% width on mobile portrait */
  .board-section:first-child .game-grid .cell {
    width: calc((90vw - 50px) / var(--board-size));
    height: calc((90vw - 50px) / var(--board-size));
  }
  .board-section:first-child .board-labels .lbl {
    width: calc((90vw - 50px) / var(--board-size));
  }
  .board-section:first-child .board-labels-left .lbl {
    height: calc((90vw - 50px) / var(--board-size));
  }
  .board-section:last-child .game-grid .cell { width: 20px; height: 20px; font-size: .6rem; }
  .board-section:last-child .board-labels .lbl { width: 20px; font-size: .55rem; }
  .board-section:last-child .board-labels-left .lbl { height: 20px; font-size: .55rem; }
  .setup-card { padding: 24px 16px; }
  h1 { font-size: 1.8rem; }
  #chat-panel { width: 260px; right: 8px; }
}
@media (max-width: 480px) {
  .board-section:last-child .game-grid .cell { width: 16px; height: 16px; font-size: .55rem; }
  .board-section:last-child .board-labels .lbl { width: 16px; font-size: .5rem; }
  .board-section:last-child .board-labels-left .lbl { height: 16px; font-size: .5rem; min-width: 12px; }
}

/* ==============================
   GLOBALE ACCOUNT-LEISTE (FIXED TOP)
   ============================== */
.account-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(10,14,23,0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  z-index: 2000;
  font-family: var(--font-mono);
}
.account-bar .acc-name {
  font-size: 0.8rem;
  color: var(--cyan);
  opacity: 0.85;
  margin-right: 4px;
}
.acc-btn {
  background: transparent;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 4px 12px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, color 0.15s;
}
.acc-btn:hover { background: var(--cyan); color: #0a0e17; }
.acc-btn.acc-dim { border-color: rgba(150,150,150,0.4); color: #888; }
.acc-btn.acc-dim:hover { background: rgba(150,150,150,0.15); color: #aaa; }
a.acc-btn { text-decoration: none; display: inline-flex; align-items: center; }


/* ==============================
   AUTH MODAL
   ============================== */
.auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  backdrop-filter: blur(4px);
}
.auth-modal.hidden { display: none; }
.auth-modal-box {
  background: var(--sea-light);
  border: 1px solid var(--border);
  box-shadow: var(--glow);
  padding: 28px 24px 24px;
  width: min(380px, 92vw);
  position: relative;
  border-radius: 4px;
}
.auth-close {
  position: absolute;
  top: 10px; right: 12px;
  background: transparent;
  border: none;
  color: var(--cyan);
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.7;
}
.auth-close:hover { opacity: 1; }
.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: #94a3b8;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 7px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-tab.active {
  background: rgba(0,229,255,0.12);
  border-color: var(--cyan);
  color: var(--cyan);
}
.auth-tab-content { display: flex; flex-direction: column; gap: 10px; }
.auth-tab-content.hidden { display: none; }
.auth-input {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--cyan); }
.auth-error { color: #f87171; font-size: 0.8rem; padding: 6px 0; }
.auth-error.hidden { display: none; }
.btn-link {
  background: transparent;
  border: none;
  color: var(--cyan);
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 0;
  font-family: var(--font-mono);
}
