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

body {
  background: #0d1117;
  color: #c9d1d9;
  font-family: 'Courier New', Courier, monospace;
  min-height: 100vh;
}

/* Screens */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

/* ── Lobby ── */
#lobby-screen {
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  gap: 24px;
  padding: 32px 16px;
}

/* ── Lobby header with insignia ── */
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 700px;
  gap: 16px;
}

.lobby-title { text-align: center; flex: 1; }

h1 {
  font-size: 2.8rem;
  letter-spacing: 0.25em;
  color: #f0a500;
  text-shadow: 0 0 20px rgba(240,165,0,0.4), 0 0 60px rgba(240,165,0,0.15);
}
.tagline { color: #6e7681; font-size: 0.78rem; margin-top: 6px; letter-spacing: 0.06em; }

.insignia-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.insignia-svg {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(0,0,0,0.6);
}
.insignia-label {
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.allies-text  { color: #7a9fd4; }
.german-text  { color: #cc6644; }

/* ── Game screen faction insignia (corner badge) ── */
.game-insignia-bar {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 10;
  pointer-events: none;
}
.game-insignia {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0,0,0,0.7);
  display: none;
}
#game-screen[data-faction="allies"] .allies-insignia { display: block; }
#game-screen[data-faction="german"] .german-insignia { display: block; }

.lobby-panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 24px;
  width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.name-row { display: flex; gap: 8px; }
input[type="text"] {
  flex: 1;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 12px;
}
input[type="text"]:focus { outline: 1px solid #f0a500; border-color: #f0a500; }

button {
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 16px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #30363d; border-color: #6e7681; }
button:disabled { opacity: 0.4; cursor: default; }
button.small { padding: 4px 10px; font-size: 0.8rem; }

#create-btn {
  background: #b45309;
  border-color: #d97706;
  color: #fff;
  font-weight: bold;
}
#create-btn:hover { background: #d97706; }

/* Plane selector */
.faction-row { display: flex; gap: 6px; flex-wrap: wrap; }

.faction-btn { flex: 1; min-width: 0; padding: 8px 4px; font-size: 0.76rem; text-align: center; color: #6e7681; }

.faction-btn.active[data-plane="camel"],
.faction-btn.active[data-plane="spad"] {
  background: #1a1500;
  border-color: #c8b060;
  color: #c8b060;
  font-weight: bold;
}

.faction-btn.active[data-plane="dr1"],
.faction-btn.active[data-plane="albatros"] {
  background: #1a0808;
  border-color: #cc2200;
  color: #cc2200;
  font-weight: bold;
}

/* ── Game Over overlay ── */
#game-over-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#game-over-overlay.active { display: flex; }

.game-over-panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 48px 40px;
  width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  text-align: center;
}

.game-over-title {
  font-size: 2rem;
  letter-spacing: 0.2em;
  color: #f0a500;
  text-shadow: 0 0 16px rgba(240,165,0,0.4);
}

.game-over-msg {
  color: #c9d1d9;
  font-size: 1.05rem;
  line-height: 1.7;
  max-width: 360px;
}

#back-to-lobby-btn {
  background: #0e1f0e;
  border-color: #3fb950;
  color: #3fb950;
  font-size: 0.95rem;
  font-weight: bold;
  padding: 12px 28px;
}
#back-to-lobby-btn:hover { background: #3fb950; color: #000; }

/* ── Combat event modal ── */
.combat-modal {
  display: none;
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  min-width: 300px;
  max-width: 460px;
  background: rgba(20, 8, 4, 0.94);
  border: 1px solid #cc4400;
  border-radius: 6px;
  padding: 14px 18px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: #f0c090;
  pointer-events: none;
  animation: combatFadeOut 3.5s forwards;
}
.combat-modal.active { display: block; }
.combat-modal div { border-bottom: 1px solid rgba(200,100,30,0.22); padding: 2px 0; }
.combat-modal div:last-child { border-bottom: none; }

@keyframes combatFadeOut {
  0%   { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}

.open-games-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
h2 { font-size: 0.85rem; color: #6e7681; letter-spacing: 0.1em; text-transform: uppercase; }

#game-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
#game-list li {
  background: #0d1117;
  border: 1px solid #21262d;
  border-radius: 4px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}
#game-list li.empty { color: #6e7681; justify-content: center; }
#game-list li button { padding: 4px 12px; font-size: 0.8rem; }

/* ── Stats leaderboard ── */
.stats-panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 16px;
  width: 560px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.stats-table th {
  color: #6e7681;
  font-weight: normal;
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid #21262d;
  letter-spacing: 0.05em;
}
.stats-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #21262d;
  color: #c9d1d9;
}
.stats-table tr:last-child td { border-bottom: none; }
.stats-table td.stat-name { color: #f0a500; font-weight: bold; }
.stats-table td.stat-allies { color: #c8b060; }
.stats-table td.stat-german { color: #cc2200; }
.stats-table td.stat-win  { color: #3fb950; }
.stats-table td.stat-loss { color: #e05050; }
.stats-empty { color: #6e7681; text-align: center; padding: 12px !important; }

/* ── Game layout ── */
#game-screen { min-height: 100vh; padding: 8px; }

.game-layout {
  display: grid;
  grid-template-columns: 148px 1fr 200px;
  gap: 8px;
  height: calc(100vh - 16px);
  align-items: start;
}

/* Shared panel look */
.moves-col, .cockpit-col, .status-col, .map-col {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px;
  min-height: 0;
}

/* Column 1: Orders */
.moves-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: calc(100vh - 16px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}

/* Column 2: Cockpit */
.cockpit-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cockpit-top-bar {
  display: flex;
  gap: 4px;
  align-items: center;
}

.view-rotate-btn {
  font-size: 0.9rem;
  padding: 5px 10px;
  background: #0d1117;
  border-color: #21262d;
  color: #8b949e;
}
.view-rotate-btn:hover { background: #161b22; border-color: #555; color: #c9d1d9; }

.view-angle-display {
  flex: 1;
  text-align: center;
  font-size: 0.72rem;
  color: #3fb950;
  font-family: inherit;
  padding: 5px 4px;
  background: #0e1f0e;
  border: 1px solid #21262d;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}
.view-angle-display:hover { border-color: #3fb950; }

#cockpit-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 600 / 400;
  border-radius: 4px;
  border: 1px solid #21262d;
}

.view-snap-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 4px;
}
.view-snap-btn {
  font-size: 0.65rem;
  padding: 4px 2px;
  background: #0d1117;
  border-color: #21262d;
  text-align: center;
  color: #6e7681;
}
.view-snap-btn:hover { background: #161b22; border-color: #444; color: #c9d1d9; }

/* Column 3: Right column (status + map stacked) */
.right-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100vh - 16px);
  min-height: 0;
}

.status-col {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex-shrink: 0;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 2px;
  border-bottom: 1px solid #21262d;
}
.stat-row:last-child { border-bottom: none; }

.stat-lbl {
  font-size: 0.68rem;
  color: #6e7681;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-val {
  font-size: 0.82rem;
  color: #c9d1d9;
  font-weight: bold;
  text-align: right;
}
.stat-val.ok   { color: #3fb950; }
.stat-val.warn { color: #f0a500; }
.stat-val.crit { color: #ff4444; }

.stat-sep {
  font-size: 0.62rem;
  color: #484f58;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 2px 3px;
  border-bottom: 1px solid #21262d;
}

/* Map panel (inside right-col) */
.map-col {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.map-canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#map-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  border: 1px solid #21262d;
  background: #0d1117;
}

/* Shared panel label */
.panel-label {
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: #6e7681;
  text-transform: uppercase;
  margin-bottom: 6px;
}

/* Move panel */
.move-status {
  font-size: 0.8rem;
  color: #8b949e;
  margin-bottom: 4px;
  min-height: 1.4em;
  line-height: 1.4;
}

/* Speed selector */
.speed-selector {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.speed-btn {
  flex: 1;
  font-size: 0.8rem;
  padding: 5px 2px;
  background: #0d1117;
  border-color: #21262d;
  color: #6e7681;
}
.speed-btn:hover:not(:disabled) { background: #161b22; border-color: #444; color: #c9d1d9; }
.speed-btn.active {
  background: #1a1000;
  border-color: #f0a500;
  color: #f0a500;
  font-weight: bold;
}

.move-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.move-btn {
  font-size: 0.72rem;
  padding: 7px 4px;
  background: #0d1117;
  border-color: #30363d;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.move-btn:hover:not(:disabled) { background: #1c2a1c; border-color: #3fb950; color: #3fb950; }
.move-btn.selected {
  background: #0e2a1a;
  border-color: #3fb950;
  color: #3fb950;
  font-weight: bold;
}

#submit-btn {
  margin-top: 6px;
  width: 100%;
  background: #0e3a1e;
  border-color: #3fb950;
  color: #3fb950;
  font-size: 0.85rem;
  font-weight: bold;
  padding: 9px;
}
#submit-btn:hover:not(:disabled) { background: #3fb950; color: #000; }
#submit-btn:disabled { opacity: 0.35; cursor: default; }

/* Event log below cockpit */
.event-log {
  flex-shrink: 0;
  height: 120px;
  overflow-y: auto;
  background: #0d1117;
  border: 1px solid #21262d;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 0.78rem;
  color: #8b949e;
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}
.event-log .log-entry { border-bottom: 1px solid #161b22; padding: 1px 0; }
.event-log .log-entry:last-child { color: #c9d1d9; border-bottom: none; }
.event-log .log-hit   { color: #e05050; }
.event-log .log-fire  { color: #f0a500; }
.event-log .log-end   { color: #3fb950; font-weight: bold; }
.event-log .log-lobby-btn {
  display: block;
  margin-top: 8px;
  background: #0e1f0e;
  border: 1px solid #3fb950;
  border-radius: 4px;
  color: #3fb950;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: bold;
  padding: 6px 14px;
  cursor: pointer;
}
.event-log .log-lobby-btn:hover { background: #3fb950; color: #000; }

/* Error */
.error-msg {
  background: #3d1515;
  border: 1px solid #7d2020;
  border-radius: 4px;
  color: #ff7b7b;
  font-size: 0.85rem;
  padding: 8px 12px;
  margin-top: 8px;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .moves-col, .right-col { height: auto; }
  .map-canvas-wrap { min-height: 280px; }
}
