* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #0e1217;
  color: #ecf3ff;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.header-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.details-link {
  color: #7bd1ff;
  text-decoration: none;
  font-weight: 700;
}

.details-link:hover {
  text-decoration: underline;
}

.panel {
  background: #151c24;
  border: 1px solid #25313d;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.event-panel h3 {
  margin-top: 0;
}

.welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 10, 0.8);
  backdrop-filter: blur(2px);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.welcome-overlay[hidden] {
  display: none;
}

.welcome-card {
  width: min(680px, 100%);
  background: #141c25;
  border: 1px solid #2f3f50;
  border-radius: 12px;
  padding: 18px 18px 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

.welcome-card h2 {
  margin: 0 0 10px;
}

.welcome-card p {
  margin: 8px 0;
  line-height: 1.5;
  color: #c9d9ea;
}

.welcome-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.player-name-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

#player-name-input {
  flex: 1;
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid #344454;
  background: #0f141b;
  color: #ecf3ff;
  padding: 8px 10px;
}

.btn {
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
}

.yes {
  background: #11a84a;
  color: white;
}

.no {
  background: #c44a3f;
  color: white;
}

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

.cooldown,
.event-status,
.muted {
  color: #9ab0c5;
  margin: 6px 0;
}

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

.stats div {
  margin: 7px 0;
}

.log {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid #25313d;
  border-radius: 6px;
  padding: 8px;
  background: #0f141b;
}

.log-top {
  max-height: 240px;
}

.log-item {
  border-bottom: 1px solid #1f2832;
  padding: 8px 0;
}

.alerts {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #5a2f2f;
  border-radius: 6px;
  padding: 8px;
  background: #1b1010;
}

.inventions {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #2f465a;
  border-radius: 6px;
  padding: 8px;
  background: #10161d;
}

.invention-item {
  border-bottom: 1px solid #223140;
  padding: 8px 0;
}

.invention-item:last-child {
  border-bottom: none;
}

.alert-item {
  border-bottom: 1px solid #3c1f1f;
  padding: 8px 0;
}

.alert-item:last-child {
  border-bottom: none;
}

.god-impact-intro {
  color: #b8a8c9;
  font-size: 0.86rem;
  margin: 0 0 10px;
  line-height: 1.35;
}

.god-impact {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #4a2f6a;
  border-radius: 6px;
  padding: 8px;
  background: #140f1a;
}

.god-impact-item {
  border-bottom: 1px solid #2a1f38;
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.god-impact-item:last-child {
  border-bottom: none;
}

.god-impact-name {
  font-weight: 700;
  color: #d4b8ff;
}

.god-impact-score {
  color: #c98a9a;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.log-item:last-child {
  border-bottom: none;
}

.log-time {
  color: #87a4bf;
  font-size: 0.84rem;
}

.details-pre {
  max-height: 80vh;
  overflow: auto;
  margin: 0;
  background: #0f141b;
  border: 1px solid #25313d;
  padding: 12px;
  border-radius: 6px;
  color: #dceafe;
}

.map-page-main {
  margin: 0;
  padding: 0;
}

.map-viewport {
  width: 100%;
  overflow: hidden;
  border-top: 1px solid #25313d;
  border-bottom: 1px solid #25313d;
  background: #0b1016;
  height: min(70vh, 900px);
  min-height: 280px;
  position: relative;
  touch-action: none;
  cursor: default;
}

.map-viewport--panning {
  cursor: grabbing;
}

.map-transform {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.map-canvas {
  position: relative;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.07) 0 1px, transparent 2px),
    radial-gradient(circle at 70% 50%, rgba(255,255,255,0.08) 0 1px, transparent 2px),
    radial-gradient(circle at 40% 80%, rgba(255,255,255,0.06) 0 1px, transparent 2px);
  background-size: 180px 180px, 220px 220px, 260px 260px;
}

.map-page .log {
  scrollbar-width: thin;
  scrollbar-color: #455a72 #0f141b;
}

.map-page .log::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.map-page .log::-webkit-scrollbar-track {
  background: #0f141b;
  border-radius: 5px;
}

.map-page .log::-webkit-scrollbar-thumb {
  background: #455a72;
  border-radius: 5px;
  border: 2px solid #0f141b;
}

.map-page .log::-webkit-scrollbar-thumb:hover {
  background: #5a7190;
}

.planet-node,
.civ-node {
  position: absolute;
  white-space: nowrap;
  font-size: 0.78rem;
}

.planet-node {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #45b7ff;
  border: 2px solid #a9dfff;
  box-shadow: 0 0 10px rgba(66, 175, 255, 0.55);
  z-index: 3;
}

.planet-node span {
  position: absolute;
  left: 24px;
  top: -2px;
  color: #9fd9ff;
}

.civ-node {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(23, 42, 61, 0.9);
  border: 1px solid #5c89af;
  color: #d6ebff;
  z-index: 3;
}

.map-line {
  position: absolute;
  height: 2px;
  transform-origin: left center;
  opacity: 0.9;
}

.civ-link {
  background: #59a8dd;
  z-index: 1;
}

.war-link {
  background: #ff6a61;
  box-shadow: 0 0 6px rgba(255, 99, 90, 0.6);
  z-index: 1;
}

.war-link-ended {
  background: #8a4a48;
  opacity: 0.45;
  z-index: 1;
}

.route-lore {
  background: linear-gradient(90deg, #3ecf9a, #2a9f78);
  opacity: 0.85;
  height: 3px;
  z-index: 1;
}

.route-invention {
  background: linear-gradient(90deg, #b86cff, #7a4ad4);
  opacity: 0.85;
  height: 3px;
  z-index: 1;
}

.route-generic {
  background: #6a7a8a;
  opacity: 0.5;
  z-index: 1;
}

.map-legend {
  margin: 0 0 12px;
  padding-left: 18px;
  color: #9ab0c5;
  font-size: 0.82rem;
  line-height: 1.55;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  list-style: none;
  padding-left: 0;
}

.map-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.planet-swatch {
  background: #45b7ff;
  border: 1px solid #a9dfff;
}

.civ-swatch {
  background: #172a3d;
  border: 1px solid #5c89af;
  border-radius: 3px;
  width: 14px;
  height: 10px;
}

.legend-line {
  display: inline-block;
  width: 22px;
  height: 3px;
  border-radius: 1px;
}

.war-line {
  background: #ff6a61;
}

.lore-line {
  background: #3ecf9a;
}

.inv-line {
  background: #b86cff;
}

.marker-god {
  background: #ffd27a;
  box-shadow: 0 0 6px rgba(255, 200, 100, 0.7);
}

.marker-signal {
  background: #7a9abf;
}

.ship-lore {
  background: #2a9f78;
  border-radius: 2px;
  width: 10px;
  height: 10px;
}

.ship-tech {
  background: #7a4ad4;
  border-radius: 2px;
  width: 10px;
  height: 10px;
}

.celestial-swatch--moon {
  background: #d6e6ff;
  border: 1px solid #8fa3c9;
}

.celestial-swatch--comet {
  background: #7affea;
  border: 1px solid #2aa295;
}

.celestial-swatch--meteor {
  background: #ffb25e;
  border: 1px solid #b9682f;
}

.celestial-swatch--destroyed {
  background: #767a86;
  border: 1px solid #3a3e49;
}

.map-celestial {
  position: absolute;
  z-index: 2;
  transform: translate(-4px, -4px);
  pointer-events: auto;
  max-width: 130px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.map-celestial-core {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 6px rgba(210, 230, 255, 0.35);
  flex-shrink: 0;
}

.map-celestial-label {
  font-size: 0.63rem;
  color: #c0d2e8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 112px;
}

.map-info-card {
  position: absolute;
  left: 16px;
  top: -6px;
  transform: translateY(-100%);
  background: rgba(8, 13, 20, 0.96);
  border: 1px solid #33485d;
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 220px;
  max-width: 280px;
  color: #d6e7f8;
  font-size: 0.72rem;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
  z-index: 8;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.planet-node:hover .map-info-card,
.civ-node:hover .map-info-card,
.map-celestial:hover .map-info-card {
  opacity: 1;
}

.map-celestial--moon .map-celestial-core {
  background: #d6e6ff;
}

.map-celestial--comet .map-celestial-core {
  background: #7affea;
  box-shadow: 0 0 8px rgba(90, 255, 225, 0.55);
}

.map-celestial--meteor .map-celestial-core {
  background: #ffb25e;
  box-shadow: 0 0 7px rgba(255, 168, 89, 0.45);
}

.map-celestial--destroyed .map-celestial-core {
  background: #767a86;
  box-shadow: none;
  opacity: 0.75;
}

.map-celestial--destroyed .map-celestial-label {
  color: #8998a8;
}

.event-marker {
  position: absolute;
  z-index: 2;
  transform: translate(-4px, -4px);
  pointer-events: auto;
  max-width: 140px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.event-marker-dot {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.25);
}

.event-marker--god .event-marker-dot {
  background: #ffd27a;
  box-shadow: 0 0 8px rgba(255, 200, 100, 0.85);
}

.event-marker--hostile .event-marker-dot {
  background: #ff6a61;
}

.event-marker--diplomatic .event-marker-dot {
  background: #6ec8ff;
}

.event-marker--hazard .event-marker-dot {
  background: #ff9f4a;
}

.event-marker--tech .event-marker-dot {
  background: #b86cff;
}

.event-marker--arcane .event-marker-dot {
  background: #d4a8ff;
}

.event-marker--signal .event-marker-dot {
  background: #7a9abf;
}

.event-marker-label {
  font-size: 0.65rem;
  color: #b8c9d9;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 118px;
  opacity: 0.88;
}

.event-marker:hover .event-marker-label {
  opacity: 1;
  color: #ecf3ff;
}

.map-ship {
  position: absolute;
  z-index: 4;
  transform: translate(-6px, -6px);
  pointer-events: none;
}

.map-ship-icon {
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 10px solid #9fd9ff;
  filter: drop-shadow(0 0 4px rgba(120, 200, 255, 0.6));
}

.map-ship--lore_vessel .map-ship-icon {
  border-bottom-color: #3ecf9a;
}

.map-ship--tech_courier .map-ship-icon {
  border-bottom-color: #b86cff;
}

.historical-log {
  max-height: 75vh;
}

.site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 18px 28px;
  text-align: center;
  font-size: 0.82rem;
  color: #7a8fa3;
  border-top: 1px solid #25313d;
  line-height: 1.45;
}

.site-footer strong {
  color: #b8c9d9;
  font-weight: 700;
}

.help-page .help-intro h2 {
  margin-top: 0;
}

.help-provenance {
  border-left: 3px solid #5c89af;
  padding-left: 14px;
  margin: 14px 0;
  color: #dceafe;
}

.help-bullets {
  margin: 8px 0;
  padding-left: 20px;
  color: #9ab0c5;
  line-height: 1.55;
}

.help-bullets li {
  margin: 6px 0;
}

.help-callout {
  background: #121a24;
  border: 1px solid #2c3a4d;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  color: #b8c9d9;
  font-size: 0.92rem;
  line-height: 1.5;
}

.help-legend-root h3 {
  margin-top: 22px;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.help-legend-root > h3:first-of-type {
  margin-top: 0;
}

.help-legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.help-legend-grid--symbols {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.help-legend-card {
  background: #121a24;
  border: 1px solid #25313d;
  border-radius: 8px;
  padding: 10px 12px;
}

.help-legend-card--row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.help-legend-card-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.help-legend-desc {
  margin: 0;
  font-size: 0.86rem;
}

.help-marker-preview {
  position: relative;
  transform: none;
  max-width: none;
  flex-shrink: 0;
}

.help-symbol-preview {
  flex-shrink: 0;
  padding-top: 4px;
}

.help-code {
  font-size: 0.78rem;
  background: #0f141b;
  padding: 1px 5px;
  border-radius: 4px;
  color: #9fd9ff;
}

.help-table-wrap {
  overflow-x: auto;
  margin-top: 10px;
  border: 1px solid #25313d;
  border-radius: 8px;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.help-table th,
.help-table td {
  border-bottom: 1px solid #1f2832;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.help-table th {
  background: #121a24;
  color: #9ab0c5;
  font-weight: 600;
}

.help-table tr:last-child td {
  border-bottom: none;
}

.help-template {
  color: #9ab0c5;
  max-width: 320px;
}

.help-chip-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.help-chip-list li {
  margin: 0;
}

.lore-layout {
  display: grid;
  grid-template-columns: 0.9fr 1.4fr;
  gap: 12px;
}

.lore-books {
  max-height: 70vh;
}

.lore-book-item {
  cursor: pointer;
}

.selected-book {
  background: #1a2431;
}

@media (max-width: 700px) {
  .container {
    padding: 12px;
  }

  .header h1 {
    font-size: 1.15rem;
    width: 100%;
  }

  .header-links {
    width: 100%;
    gap: 10px;
  }

  .details-link {
    font-size: 0.93rem;
  }

  .panel {
    padding: 10px;
    margin-bottom: 10px;
  }

  .actions {
    flex-direction: column;
  }

  .player-name-row {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .log,
  .alerts,
  .inventions {
    max-height: 230px;
  }

  .log-top {
    max-height: 210px;
  }

  .map-viewport {
    height: min(62vh, 820px);
    min-height: 240px;
  }

  .lore-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }
}
