:root {
  color-scheme: dark;
  --bg: #05060d;
  --panel: #0f111d;
  --panel-strong: #15182a;
  --border: #1b1f33;
  --accent: #4bd1a0;
  --accent-2: #5ac8fa;
  --text-muted: #9ca4bc;
  --danger: #ff6b81;
  font-family: 'Inter', 'Segoe UI', Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, rgba(36, 51, 93, 0.35), transparent 50%), var(--bg);
  color: #f5f7ff;
  min-height: 100vh;
}

h1, h2, h3, h4, p {
  margin: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hud {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 7, 12, 0.92);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-right: 1rem;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #5b6bff, #63ffd4);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #05060d;
  font-size: 1.4rem;
}

.hud-metric {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hud-metric strong {
  font-size: 1.2rem;
  color: #fff;
}

.hud-metric.direction {
  margin-left: auto;
  align-items: flex-start;
}

.dir-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

button {
  font: inherit;
}

.hud button {
  background: #1a1d30;
  border: 1px solid var(--border);
  color: #fff;
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
}

.main-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 300px minmax(700px, 1fr) 360px;
  gap: 1.2rem;
  padding: 1.2rem 2rem 2rem 2rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.info-panel section,
.control-panel section {
  background: var(--panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 0.9rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

ol, ul {
  padding-left: 1.1rem;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.4rem;
}

.legend-grid div {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.grid-wrapper {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 1rem;
  gap: 0.8rem;
}

.grid-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-strong);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.toggle-group {
  display: flex;
  gap: 0.9rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toggle-group input {
  margin-right: 0.3rem;
}

#gridCanvas {
  width: 100%;
  max-width: 860px;
  align-self: center;
  background: #05070f;
  border-radius: 14px;
  border: 1px solid #1b2137;
}

.grid-footnotes {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.2rem 0.3rem;
}

.hover-readout {
  color: #fff;
}

.power-panel .bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #0b0d15;
  border: 1px solid #1f2740;
  margin-top: 0.2rem;
  overflow: hidden;
}

.power-panel .bar div {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  width: 30%;
}

.power-panel #loadBar {
  background: var(--danger);
}

.power-panel p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.4rem;
}

.resource-panel .chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
}

.resource-panel .chips li {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.tools-panel {
  gap: 0.6rem;
}

#toolGroups {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.tool-group h4 {
  margin-bottom: 0.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tool-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.35rem;
}

.tool-list button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.02);
  color: #fff;
  border-radius: 10px;
  padding: 0.55rem;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  transition: border 0.2s, transform 0.1s;
}

.tool-list button.active {
  border-color: var(--accent);
  background: rgba(75, 209, 160, 0.15);
  box-shadow: 0 0 10px rgba(75, 209, 160, 0.25);
}

.selected-info {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 0.9rem;
  gap: 0.7rem;
}

.selected-info p {
  color: var(--text-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.6rem;
  font-size: 0.85rem;
}

.stat-grid div {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 0.5rem;
}

.io-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  font-size: 0.85rem;
}

.io-grid ul {
  list-style: none;
  padding: 0;
  gap: 0.2rem;
}

.log-panel {
  max-height: 220px;
  overflow-y: auto;
}

#logEntries {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

#logEntries li {
  padding: 0.25rem 0.35rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

@media (max-width: 1400px) {
  .main-layout {
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
      'grid grid'
      'panel panel';
  }
  .info-panel {
    grid-column: span 2;
    order: 2;
  }
  .control-panel {
    grid-column: span 2;
    order: 3;
  }
}

@media (max-width: 980px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .info-panel,
  .control-panel {
    order: initial;
  }
}
