/* ==========================================================================
   Battaglia Navale — tema scuro da ammiraglia
   ========================================================================== */
:root {
  --bg-0: #04070f;
  --bg-1: #0a1430;
  --panel: #0e1d3d;
  --panel-2: #142647;
  --line: #1d3157;
  --water: #0d1c3d;
  --accent: #3fa0ff;
  --accent-2: #2dd4a7;
  --danger: #ff4d6d;
  --sunk: #58111f;
  --text: #e9f0ff;
  --muted: #8196bd;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 20% -10%, var(--bg-1), transparent 60%),
    radial-gradient(1000px 700px at 110% 110%, #0a1f3a, transparent 55%),
    var(--bg-0);
  overflow-x: hidden;
}

.bg {
  position: fixed; inset: 0; z-index: -1;
  background-image: repeating-linear-gradient(0deg, rgba(63, 160, 255, 0.03) 0 2px, transparent 2px 42px);
}

.hidden { display: none !important; }

/* ===== Schermate ===== */
.screen {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding: 24px 16px;
}
.hero { text-align: center; }
.title {
  font-size: clamp(2rem, 6vw, 3.4rem);
  letter-spacing: 1px;
  text-shadow: 0 0 30px rgba(63, 160, 255, 0.35);
}
.subtitle { color: var(--muted); margin-top: 6px; font-size: 1.05rem; }

.card {
  width: min(92vw, 400px);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.card.center { align-items: center; text-align: center; }

.field-label { font-size: 0.85rem; color: var(--muted); }

input[type="text"] {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }

button {
  font: inherit;
  border: none; border-radius: 10px;
  cursor: pointer;
  padding: 11px 16px;
  transition: transform 0.06s, filter 0.15s, background 0.15s, border-color 0.15s;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.primary { background: linear-gradient(180deg, #4ba6ff, #2f7fe0); color: #fff; font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.1); }
.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.secondary:hover { border-color: var(--accent); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.ghost:hover { color: var(--text); }
.big { padding: 14px; font-size: 1.05rem; }

.btn-row { display: flex; gap: 10px; }
.btn-row button { flex: 1; }

.hint { color: var(--muted); font-size: 0.85rem; line-height: 1.5; }
.status { color: var(--muted); }

/* spinner */
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 8px 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== HUD ===== */
.hud {
  width: min(96vw, 880px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 18px;
  margin-top: 18px;
}
.player { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.player .dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.you { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
.dot.opp { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.turn-box { text-align: center; }
.turn { font-weight: 700; }
.last-shot { color: var(--muted); font-size: 0.8rem; margin-top: 2px; min-height: 1.2em; }

/* ===== Fasi ===== */
.phase { width: min(96vw, 880px); }
.placing { display: flex; gap: 22px; align-items: flex-start; justify-content: center; flex-wrap: wrap; margin: 22px 0; }
.side { width: 300px; display: flex; flex-direction: column; gap: 14px; }
.phase h3 { color: var(--muted); font-weight: 600; font-size: 0.95rem; letter-spacing: 0.5px; }

.boards { display: flex; gap: 22px; align-items: flex-start; justify-content: center; flex-wrap: wrap; margin: 22px 0; }
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* ===== Griglie ===== */
.board {
  background: linear-gradient(180deg, #0a1530, #081022);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(0, 0, 0, 0.35);
}
.grid {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 3px;
  width: min(88vw, 400px);
}
.cell {
  aspect-ratio: 1;
  background: var(--water);
  border: 1px solid rgba(29, 49, 87, 0.55);
  border-radius: 4px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.cell.coord {
  background: transparent; border-color: transparent;
  color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

/* navi mie */
.cell.ship {
  background: linear-gradient(160deg, #4ba6ff, #2f6fd0);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.cell.hit {
  background: var(--danger);
  border-color: rgba(255, 255, 255, 0.4);
  animation: pop 0.25s ease;
}
.cell.hit::after, .cell.sunk::after {
  content: "✕";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 900; font-size: 1.1rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.cell.sunk { background: var(--sunk); border-color: rgba(255, 255, 255, 0.25); }

.cell.miss { background: transparent; border-color: transparent; }
.cell.miss::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.28) 0 3px, transparent 4px);
}

/* griglia nemica */
.cell.target { cursor: crosshair; }
.cell.target:hover { background: rgba(63, 160, 255, 0.35); border-color: var(--accent); }
.cell.pending { background: rgba(63, 160, 255, 0.25); animation: blink 0.7s infinite alternate; }
@keyframes blink { from { opacity: 0.5; } to { opacity: 1; } }
@keyframes pop { 50% { transform: scale(1.35); } }

/* anteprima piazzamento */
.cell.preview-ok { background: rgba(45, 212, 167, 0.55); border-color: var(--accent-2); }
.cell.preview-bad { background: rgba(255, 77, 109, 0.55); border-color: var(--danger); }

/* ===== Lista flotta ===== */
.ship-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.ship-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.ship-item:hover { border-color: var(--accent); }
.ship-item.selected { border-color: var(--accent); background: rgba(63, 160, 255, 0.08); }
.ship-item.placed { opacity: 0.55; }
.ship-name { flex: 1; font-size: 0.9rem; }
.ship-cells { display: flex; gap: 3px; }
.ship-cells i {
  width: 16px; height: 16px; border-radius: 3px;
  background: linear-gradient(160deg, #4ba6ff, #2f6fd0);
}
.ship-status { color: var(--accent-2); font-weight: 700; }

/* ===== Overlay fine partita ===== */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(2, 6, 16, 0.8);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.3s ease;
}
@keyframes fade { from { opacity: 0; } }
.overlay-card {
  width: min(92vw, 380px);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 24px;
  text-align: center;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.overlay-card h2 { font-size: 1.7rem; }
#over-sub { color: var(--muted); }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 100;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 20px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.95rem;
  animation: slide 0.25s ease;
}
@keyframes slide { from { transform: translate(-50%, -12px); opacity: 0; } }

kbd {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; font-size: 0.8rem;
}

/* ===== Toggle modalità (lobby) ===== */
.mode-toggle {
  display: flex; gap: 8px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 12px; padding: 4px;
}
.mode-btn {
  flex: 1;
  background: transparent; color: var(--muted);
  border-radius: 8px; padding: 9px 8px;
  font-weight: 600;
}
.mode-btn.active {
  background: linear-gradient(180deg, #4ba6ff, #2f7fe0);
  color: #fff;
}
.mode-btn.active.powers {
  background: linear-gradient(180deg, #ffd166, #f0a92e);
  color: #1a1206;
}

/* ===== Card personaggi (lobby) ===== */
.character-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 230px;
  overflow-y: auto;
  padding-right: 2px;
}
.char-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: transform 0.08s, background 0.12s, box-shadow 0.12s;
}
.char-card:hover { background: rgba(255, 255, 255, 0.06); }
.char-card.selected {
  background: rgba(63, 160, 255, 0.12);
  box-shadow: 0 0 0 2px var(--accent), 0 6px 20px rgba(63, 160, 255, 0.25);
}
.char-header { display: flex; align-items: center; gap: 8px; }
.char-emoji-big { font-size: 1.6rem; }
.char-name-big { display: block; font-weight: 700; font-size: 0.92rem; }
.char-desc { display: block; color: var(--muted); font-size: 0.7rem; line-height: 1.25; }
.char-powers { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.char-power {
  display: flex; justify-content: space-between;
  font-size: 0.72rem; color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px; padding: 3px 7px;
}
.cp-cost { color: #ffd166; font-weight: 700; }

/* ===== Sidebar battaglia ===== */
.sidebar {
  width: 300px;
  display: flex; flex-direction: column; gap: 14px;
  align-items: stretch;
}
.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.panel h3 { color: var(--muted); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.5px; }

/* personaggi nella sidebar */
.char-box { margin-bottom: 2px; }
.char-card.mini { display: block; padding: 8px 10px; }
.char-label { display: block; color: var(--muted); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 1px; }
.char-powers-list { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.power-tag {
  font-size: 0.65rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--text);
}
.power-tag em { color: #ffd166; font-style: normal; font-weight: 700; }

/* ===== Energia ===== */
.energy-bar {
  position: relative;
  height: 30px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  overflow: hidden;
}
#energy-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #3fa0ff, #2dd4a7);
  transition: width 0.3s ease;
}
#energy-value {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  font-size: 0.95rem;
}
.energy-log {
  font-size: 0.72rem; color: var(--muted);
  min-height: 1em;
  display: flex; flex-direction: column; gap: 1px;
}

/* ===== Barra poteri ===== */
.power-bar {
  display: flex; flex-direction: column; gap: 7px;
}
.power-btn {
  text-align: left;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.85rem;
  line-height: 1.25;
  transition: border-color 0.12s, background 0.12s, transform 0.06s;
}
.power-btn em { color: #ffd166; font-style: normal; font-weight: 700; }
.power-btn:not(:disabled):hover {
  border-color: var(--accent);
  background: linear-gradient(180deg, #1b2f58, var(--panel));
}
.power-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.power-btn.targetable:not(:disabled) { border-color: var(--accent-2); }
.power-btn.active-power { border-color: #ffd166; background: rgba(255, 209, 102, 0.1); }

/* ===== Pannello flotta nemica ===== */
.fleet-list { display: flex; flex-direction: column; gap: 8px; }
.fleet-ship {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.02);
}
.fs-name { flex: 1; font-size: 0.8rem; }
.fs-cells { display: flex; gap: 3px; }
.fs-cell {
  width: 14px; height: 14px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
}
.fs-cell.hit { background: var(--danger); border-color: rgba(255, 255, 255, 0.35); }
.fs-status { font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.fleet-ship.damaged { border-color: var(--danger); }
.fleet-ship.sunk { opacity: 0.5; }
.fleet-ship.sunk .fs-name { text-decoration: line-through; }
.fleet-ship.sunk .fs-status { color: var(--danger); }

/* ===== Badge HUD ===== */
.hud-badges { display: flex; gap: 6px; align-items: center; }
.badge {
  font-size: 0.75rem; font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.badge.energy-badge { color: #ffd166; border-color: rgba(255, 209, 102, 0.4); }
.badge.shield-badge { color: var(--accent); border-color: rgba(63, 160, 255, 0.4); }
.badge.extra-badge { color: var(--accent-2); border-color: rgba(45, 212, 167, 0.4); }

/* ===== Stati cella: rivelata / bloccata / riparata ===== */
.cell.revealed {
  background: linear-gradient(160deg, rgba(138, 92, 246, 0.75), rgba(102, 51, 204, 0.65));
  border-color: rgba(190, 140, 255, 0.6);
  box-shadow: inset 0 0 0 1px rgba(190, 140, 255, 0.35);
}
.cell.blocked {
  background: rgba(63, 160, 255, 0.12);
  border-color: rgba(63, 160, 255, 0.9);
  box-shadow: inset 0 0 0 2px rgba(63, 160, 255, 0.7), 0 0 12px rgba(63, 160, 255, 0.4);
  cursor: crosshair;
}
.cell.repaired { animation: repair-flash 1.2s ease; }
@keyframes repair-flash {
  0% { box-shadow: 0 0 0 3px var(--accent-2); }
  70% { box-shadow: 0 0 0 3px rgba(45, 212, 167, 0.2); }
  100% { box-shadow: none; }
}
.cell.targeting { cursor: crosshair; }
.cell.targeting:hover { background: rgba(255, 209, 102, 0.25); border-color: #ffd166; }

@media (max-width: 900px) {
  .sidebar { width: min(92vw, 400px); }
  .boards { align-items: center; }
}
@media (max-width: 640px) {
  .grid { width: 88vw; }
  .hud { font-size: 0.8rem; padding: 10px 8px; }
  .character-grid { grid-template-columns: 1fr; }
  .hud-badges { display: none; }
}
