:root {
  /* Default Dark Mode Palette */
  --bg: #05070d;
  --card: rgba(13, 18, 34, 0.85);
  --text: #eaf0ff;
  --muted: #a9b4d4;
  --border: #283458;
  --accent: #4a9eff;
  --cell: #0b1022;
  --cellHover: #182044;
  --hit: #ff5c5c;
  --miss: #6aa9ff;
  --ship: #ffcc66;
  --glow: 0 0 18px rgba(255, 204, 102, 0.18);
  --panelShadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

/* Light Mode Override */
body.light-theme {
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1a1f2e;
  --muted: #5a6782;
  --border: #cbd5e1;
  --accent: #2563eb;
  --cell: #e2e8f0;
  --cellHover: #cbd5e1;
  --hit: #dc2626;
  --miss: #3b82f6;
  --ship: #d97706;
  --glow: 0 0 18px rgba(217, 119, 6, 0.1);
  --panelShadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Header & Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.badge {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(255,204,102,0.25), rgba(106,169,255,0.12));
  border: 1px solid var(--border);
  box-shadow: var(--glow);
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

/* View Management */
.hidden {
  display: none !important;
}

.screen {
  animation: fadeIn 0.4s ease;
  width: 100%;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Layouts & Panels */
.view-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 80vh;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--panelShadow);
  backdrop-filter: blur(10px);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 15px;
  text-align: center;
}

/* Battle Arena: Forced Side-by-Side */
.battle-arena {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 15px;
  width: 100%;
  max-width: 100vw;
}

.board-panel {
  flex: 0 1 auto;
  padding: 15px;
}

/* Mini Board Dimensions for Single Screen */
.board.mini-board {
  display: grid;
  grid-template-columns: repeat(11, 28px);
  grid-template-rows: repeat(11, 28px);
  gap: 2px;
  padding: 5px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: max-content;
  margin: 0 auto;
}

.cell {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--cell);
  border: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s, opacity 0.2s;
  padding: 0;
}

.cell:hover:not(:disabled) {
  background: var(--cellHover);
}

.cell:disabled {
  cursor: default;
  opacity: 1;
}

.board > div {
  width: 28px;
  height: 28px;
}

#placementBoard.board > div {
  width: 32px;
  height: 32px;
}

.side-panel-compact {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 280px;
  flex: 0 0 auto;
}

/* Typography */
h2 { font-size: 1.8rem; margin: 0; }
h3 { font-size: 1.1rem; margin: 0; color: var(--accent); }
p.hint { font-size: 1rem; margin: 0; color: var(--muted); }

/* Form Elements */
input, select {
  padding: 10px;
  background: var(--cell);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

button {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

button:hover:not(:disabled) {
  filter: brightness(1.2);
  transform: translateY(-1px);
}

.success {
  background: #2ecc71 !important;
  color: white !important;
  border: none !important;
  text-transform: uppercase;
}

.danger {
  background: #e74c3c !important;
  color: white !important;
  border: none !important;
  text-transform: uppercase;
}

/* Board state styling */
.cell.ship {
  background: var(--ship);
  opacity: 0.75;
}

.cell.hit {
  background-color: var(--hit) !important;
  color: white;
  border-color: rgba(255,255,255,0.2);
}

.cell.miss {
  background-color: var(--miss) !important;
  color: white;
  border-color: rgba(255,255,255,0.2);
}

.cell.hit::after {
  content: "×";
  color: white;
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}

.cell.miss::after {
  content: "•";
  color: white;
  font-size: 20px;
  line-height: 1;
}

.cell.ship.hit {
  background-color: var(--hit) !important;
  opacity: 1;
}

.cell.sunk {
  background: #333 !important;
  border-radius: 0;
}

.cell.sunk::after {
  content: "🚢";
  font-size: 14px;
}

/* Logs & Stats */
.small-log {
  max-height: 150px;
  overflow-y: auto;
  width: 100%;
  font-size: 11px;
  background: rgba(4,6,14,0.55);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: left;
}

.hitTxt {
  color: var(--hit) !important;
  font-weight: bold;
}

.missTxt {
  color: var(--miss) !important;
  font-weight: bold;
}

/* Lobby List */
.scroll-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.game-item {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

/* Status Bar */
.statusbar {
  position: fixed;
  bottom: 0;
  width: 100%;
  padding: 8px 20px;
  background: var(--card);
  border-top: 1px solid var(--border);
  font-size: 12px;
  display: flex;
  gap: 20px;
  z-index: 100;
}

/* Fix Screen 4 Placement Grid */
#placementBoard.board {
  display: grid;
  grid-template-columns: repeat(11, 32px);
  grid-template-rows: repeat(11, 32px);
  gap: 4px;
  width: max-content;
  margin: 0 auto;
}

.grid-label,
.grid-corner {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}

#placementBoard .grid-label,
#placementBoard .grid-corner {
  width: 32px;
  height: 32px;
}
