:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --hit: #ef4444;
  --miss: #64748b;
  --ship: #22c55e;
  --water: #0ea5e9;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--water));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.card label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.card input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.card input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.actions-card .btn {
  width: 100%;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.actions-card .btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 1rem 0;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

.join-row input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-transform: uppercase;
}

.join-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.join-row .btn {
  width: auto;
  padding: 0.75rem 1.25rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  margin-top: 1rem;
}

/* ----- Game page ----- */
.game-page .header {
  margin-bottom: 1rem;
}

.lobby-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.lobby-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.share-link {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.share-link input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.share-link .btn-copy {
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.share-link .btn-copy:hover {
  background: var(--accent-hover);
}

.waiting-msg {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.players-list {
  list-style: none;
  margin-top: 0.5rem;
}

.players-list li {
  padding: 0.4rem 0;
  color: var(--text);
}

/* QR code */
.qr-wrapper {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.qr-card {
  padding: 0.5rem;
  border-radius: 12px;
  background: radial-gradient(circle at top, rgba(59, 130, 246, 0.35), rgba(15, 23, 42, 0.9));
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.9);
}

.qr-card img {
  display: block;
  width: 180px;
  height: 180px;
}

.qr-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* Battleship grid */
.battleship-section {
  margin-top: 1rem;
}

.battleship-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.grid-container {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, 30px);
  grid-template-rows: repeat(10, 30px);
  gap: 3px;
}

.cell {
  width: 30px;
  height: 30px;
  background:
    radial-gradient(circle at 20% 0%, rgba(148, 163, 184, 0.45), transparent 55%),
    radial-gradient(circle at 80% 120%, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 1)),
    linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(15, 23, 42, 0.9));
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.15s, transform 0.08s, box-shadow 0.12s;
}

.cell.water {
  background: rgba(14, 165, 233, 0.2);
}

.cell.ship {
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 1)),
    linear-gradient(90deg, rgba(34, 197, 94, 0.85), rgba(21, 128, 61, 0.95));
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.8), 0 0 12px rgba(34, 197, 94, 0.55);
}

.cell.ship::before {
  content: "";
  position: absolute;
  inset: 4px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 20'%3E%3Cdefs%3E%3ClinearGradient id='hull'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop offset='0'%20stop-color='%2338bdf8'/%3E%3Cstop offset='1'%20stop-color='%230f172a'/%3E%3C/linearGradient%3E%3ClinearGradient id='deck'%20x1='0'%20y1='0'%20x2='1'%20y2='0'%3E%3Cstop offset='0'%20stop-color='%23e5e7eb'/%3E%3Cstop offset='1'%20stop-color='%239ca3af'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect x='2'%20y='10'%20width='60'%20height='6'%20rx='3'%20fill='url(%23hull)'/%3E%3Crect x='16'%20y='6'%20width='20'%20height='4'%20rx='2'%20fill='url(%23deck)'/%3E%3Ccircle cx='22'%20cy='8'%20r='1'%20fill='%230f172a'/%3E%3Ccircle cx='26'%20cy='8'%20r='1'%20fill='%230f172a'/%3E%3Ccircle cx='30'%20cy='8'%20r='1'%20fill='%230f172a'/%3E%3C/svg%3E");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.95;
}

.cell.ship.placed {
  background: rgba(34, 197, 94, 0.6);
}

.cell.hit {
  background:
    radial-gradient(circle at 50% 50%, rgba(248, 113, 113, 0.9), rgba(127, 29, 29, 1));
  cursor: default;
}

.cell.hit::after {
  content: "";
  position: absolute;
  inset: 4px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%23fee2e2' stroke-width='2'%3E%3Ccircle cx='20' cy='20' r='5' fill='%23b91c1c'/%3E%3Cpath d='M20 1 L22 10 L30 6 L26 14 L35 15 L26 20 L33 25 L24 24 L26 33 L20 26 L14 33 L16 24 L7 25 L14 20 L5 15 L14 14 L10 6 L18 10 Z'/%3E%3C/g%3E%3C/svg%3E");
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  animation: hit-pop 220ms ease-out;
}

.cell.hit.sunk::after {
  animation: hit-pop 220ms ease-out, sunk-wave 700ms ease-out 120ms;
}

.cell.miss {
  background:
    radial-gradient(circle at 40% 30%, rgba(148, 163, 184, 0.8), rgba(15, 23, 42, 1));
  cursor: default;
}

.cell.miss::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 999px;
  border: 2px solid rgba(248, 250, 252, 0.6);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.7);
  opacity: 0.9;
}

/* Petite ondulation quand on survole la grille adverse */
.grid#grid-theirs .cell:not(.disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.8);
}

@keyframes hit-pop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes sunk-wave {
  0% { box-shadow: 0 0 0 0 rgba(248, 250, 252, 0.4); }
  100% { box-shadow: 0 0 0 10px rgba(15, 23, 42, 0); }
}

.cell.disabled {
  pointer-events: none;
  opacity: 0.7;
}

.cell.dragover {
  background: rgba(34, 197, 94, 0.4);
}

.turn-msg {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.turn-msg.your-turn {
  color: var(--accent);
  font-weight: 600;
}

.game-over-msg {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  text-align: center;
}

.game-over-msg.win {
  background: rgba(34, 197, 94, 0.2);
  color: var(--ship);
}

.game-over-msg.lose {
  background: rgba(239, 68, 68, 0.2);
  color: var(--hit);
}

.placement-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.placement-actions .btn {
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.placement-actions .btn-rotate {
  background: var(--surface-hover);
  color: var(--text);
}

.placement-actions .btn-ready {
  background: var(--ship);
  color: white;
}

.placement-actions .btn-ready:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.back-link {
  display: inline-block;
  margin-top: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 100;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.error-msg {
  color: var(--hit);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

