:root {
  --bg: #07090d;
  --panel: #101722;
  --panel-2: #141d2a;
  --line: #243247;
  --ink: #e8f1ff;
  --muted: #91a4bc;
  --accent: #63d6ff;
  --good: #83f7a6;
  --warn: #ffd166;
  --bad: #ff7c7c;
  --gold: #ffe6a1;
}

* {
  box-sizing: border-box;
  user-select: none;
  scrollbar-color: #334865 #0b111a;
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: #0b111a;
  border-left: 1px solid rgba(45, 62, 88, 0.55);
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #334865, #243247);
  border: 2px solid #0b111a;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #52779f, #334865);
}

*::-webkit-scrollbar-corner {
  background: #0b111a;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: #07090d;
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
}

button,
select {
  border: 1px solid #2d3e58;
  background: #192435;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}

select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, #9fb8d4 50%) calc(100% - 17px) 50% / 6px 6px no-repeat,
    linear-gradient(135deg, #9fb8d4 50%, transparent 50%) calc(100% - 12px) 50% / 6px 6px no-repeat,
    linear-gradient(180deg, #182233, #111a27);
  border-color: #334865;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.025) inset;
  padding-right: 34px;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 214, 255, 0.16);
}

select option {
  background: #111a27;
  color: var(--ink);
}

button {
  cursor: pointer;
}

button:hover:not(:disabled):not([aria-disabled="true"]) {
  border-color: #52779f;
}

button:disabled,
button[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

button.danger-btn {
  background: linear-gradient(180deg, rgba(70, 28, 35, 0.58), rgba(38, 18, 23, 0.66));
  border-color: rgba(255, 124, 124, 0.34);
  color: rgba(255, 226, 226, 0.84);
}

button.danger-btn:hover:not(:disabled):not([aria-disabled="true"]) {
  background: linear-gradient(180deg, rgba(88, 32, 40, 0.68), rgba(48, 20, 26, 0.76));
  border-color: rgba(255, 150, 150, 0.48);
  box-shadow: 0 0 14px rgba(255, 124, 124, 0.08);
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
  color: #cfe1ff;
}

.row,
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.subtle,
.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pill {
  border: 1px solid #29384f;
  background: #0d131c;
  color: #cfe1ff;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.good {
  color: var(--good);
}

.warn {
  color: var(--warn);
}

.bad {
  color: var(--bad);
}

.app-shell {
  height: 100%;
  display: block;
  padding: 0;
}

.card {
  background: var(--panel);
  border: 1px solid #1d2839;
  border-radius: 8px;
}

.map-panel {
  height: 100%;
  min-height: 0;
  display: block;
  overflow: hidden;
  position: relative;
  background: #080c12;
}

#galaxyCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
  background:
    radial-gradient(circle at 25% 30%, rgba(99, 214, 255, 0.055), transparent 30%),
    radial-gradient(circle at 70% 65%, rgba(255, 209, 102, 0.035), transparent 28%),
    #080c12;
}

.map-panel {
  cursor: none;
}

.popup,
.popup *,
button,
select {
  cursor: auto;
}

button,
select {
  cursor: pointer;
}

button:disabled,
button[aria-disabled="true"] {
  cursor: not-allowed;
}

.top-hud {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.8;
}

.gibbs-hud button,
.research-hud button {
  color: #e8f1ff;
  background: rgba(13, 19, 28, 0.78);
  border: 1px solid rgba(99, 214, 255, 0.34);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28), 0 0 18px rgba(99, 214, 255, 0.08);
  backdrop-filter: blur(10px);
  padding: 7px 10px;
  font-weight: 700;
}

.research-hud button {
  border-color: rgba(255, 230, 161, 0.38);
}

.gibbs-hud button:hover,
.research-hud button:hover {
  border-color: rgba(255, 230, 161, 0.54);
  color: #fff3c4;
}

.custom-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  pointer-events: none;
  opacity: 0;
  z-index: 4;
  transform: translate(-50%, -50%);
  transition: opacity 0.12s ease, width 0.12s ease, height 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.custom-cursor::before,
.custom-cursor::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(147, 200, 236, 0.82);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(99, 214, 255, 0.20);
}

.custom-cursor::after {
  inset: 9px;
  background: rgba(147, 200, 236, 0.86);
  border: 0;
  box-shadow: 0 0 10px rgba(147, 200, 236, 0.42);
}

.custom-cursor.visible {
  opacity: 1;
}

.custom-cursor.pan::before {
  border-color: rgba(147, 200, 236, 0.76);
}

.custom-cursor.pan::after {
  inset: 11px;
  border-radius: 50%;
  box-shadow:
    -6px 0 0 rgba(147, 200, 236, 0.72),
    6px 0 0 rgba(147, 200, 236, 0.72),
    0 -6px 0 rgba(147, 200, 236, 0.72),
    0 6px 0 rgba(147, 200, 236, 0.72),
    0 0 10px rgba(147, 200, 236, 0.30);
}

.custom-cursor.route {
  width: 34px;
  height: 34px;
}

.custom-cursor.route::before {
  border-color: rgba(255, 230, 161, 0.95);
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.35);
}

.custom-cursor.route::after {
  inset: 13px;
  background: rgba(255, 230, 161, 0.95);
}

.custom-cursor.dragging {
  width: 38px;
  height: 38px;
}

.custom-cursor.dragging::before {
  border-color: rgba(131, 247, 166, 0.95);
  box-shadow: 0 0 20px rgba(131, 247, 166, 0.30);
}

.custom-cursor.dragging::after {
  inset: 11px;
  background: rgba(131, 247, 166, 0.86);
}

.tabs {
  padding: 10px;
  border-bottom: 1px solid #1d2839;
  background: #0d131c;
}

.tabs button {
  padding: 7px 9px;
}

.tabs button.active {
  border-color: var(--accent);
  color: #ddf7ff;
}

.tabs button.farm-marker {
  border-color: rgba(131, 247, 166, 0.58);
  color: #d8ffe3;
  background: linear-gradient(180deg, rgba(36, 83, 54, 0.58), rgba(18, 43, 31, 0.82));
  box-shadow: 0 0 0 1px rgba(131, 247, 166, 0.10) inset, 0 0 18px rgba(131, 247, 166, 0.08);
}

.tabs button.farm-marker.active {
  border-color: var(--good);
  box-shadow: 0 0 0 1px rgba(131, 247, 166, 0.18) inset, 0 0 22px rgba(131, 247, 166, 0.14);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.popup {
  position: absolute;
  right: 14px;
  top: 14px;
  width: min(460px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  overflow: auto;
  display: none;
  background: rgba(13, 19, 28, 0.96);
  border: 1px solid #2d3d55;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
  z-index: 3;
}

.popup.open {
  display: block;
}

.popup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid #223149;
  background: #0d131c;
  position: sticky;
  top: 0;
  z-index: 2;
}

.popup-body {
  padding: 12px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.drag-hint {
  position: absolute;
  pointer-events: none;
  left: 0;
  top: 0;
  color: #e8f1ff;
  background: rgba(13, 19, 28, 0.82);
  border: 1px solid #2d3d55;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  display: none;
  transform: translate(10px, 10px);
}

.drag-hint.show {
  display: block;
}

.recenter-hint {
  position: absolute;
  left: 16px;
  bottom: 12px;
  display: none;
  color: #e8f1ff;
  opacity: 0.9;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.72);
  z-index: 4;
}

.recenter-hint.show {
  display: block;
}

.system-label {
  position: absolute;
  pointer-events: none;
  left: 0;
  top: 0;
  display: none;
  max-width: 260px;
  transform: translate(14px, 18px);
  color: #e8f1ff;
  background: rgba(13, 19, 28, 0.82);
  border: 1px solid rgba(99, 214, 255, 0.38);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.34), 0 0 18px rgba(99, 214, 255, 0.10);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(10px);
  z-index: 5;
}

.system-label.source {
  width: max-content;
  min-width: 190px;
  max-width: 320px;
  padding: 9px 10px;
  white-space: normal;
  text-overflow: clip;
}

.system-label-title {
  color: #ffe6a1;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 6px;
}

.system-label-section {
  display: grid;
  gap: 4px;
  padding-top: 7px;
  margin-top: 7px;
  border-top: 1px solid rgba(99, 214, 255, 0.16);
}

.system-label-heading {
  color: #83f7a6;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.system-label-list {
  display: grid;
  gap: 2px;
  justify-items: stretch;
}

.system-label-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  font-size: 11px;
  line-height: 1.25;
  color: #dfeeff;
  font-weight: 700;
  text-align: left;
}

.system-label-item span {
  min-width: 0;
}

.system-label-item b {
  color: #ffffff;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  text-align: right;
}

.system-label-empty {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
}

.system-label.show {
  display: block;
}

.system-label.left {
  transform: translate(calc(-100% - 14px), 18px);
}

.system-label.above {
  transform: translate(14px, calc(-100% - 14px));
}

.system-label.left.above {
  transform: translate(calc(-100% - 14px), calc(-100% - 14px));
}

.route-tooltip,
.action-tooltip {
  position: absolute;
  pointer-events: none;
  left: 0;
  top: 0;
  min-width: 230px;
  max-width: 320px;
  display: none;
  transform: translate(16px, 14px);
  color: var(--ink);
  background: rgba(13, 19, 28, 0.94);
  border: 1px solid rgba(255, 230, 161, 0.48);
  border-radius: 8px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.38), 0 0 24px rgba(255, 209, 102, 0.10);
  padding: 9px 10px;
  backdrop-filter: blur(10px);
  z-index: 5;
}

.route-tooltip.show,
.action-tooltip.show {
  display: grid;
  gap: 5px;
}

.route-tooltip.left,
.action-tooltip.left {
  transform: translate(calc(-100% - 16px), 14px);
}

.route-tooltip.above,
.action-tooltip.above {
  transform: translate(16px, calc(-100% - 14px));
}

.route-tooltip.left.above,
.action-tooltip.left.above {
  transform: translate(calc(-100% - 16px), calc(-100% - 14px));
}

.tooltip-title {
  color: #ffe6a1;
  font-size: 12px;
  font-weight: 700;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 230, 161, 0.18);
}

.tooltip-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  font-size: 12px;
}

.tooltip-line span {
  color: var(--muted);
}

.tooltip-line b {
  color: #dfeeff;
  font-weight: 600;
}

.stack {
  display: grid;
  gap: 10px;
}

.card {
  padding: 10px;
}

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

.stat-line,
.resource-line,
.machine-row,
.route-row,
.quest-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed #263449;
}

.stat-line:last-child,
.resource-line:last-child,
.machine-row:last-child,
.route-row:last-child,
.quest-row:last-child {
  border-bottom: 0;
}

.machine-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.machine-row.locked {
  opacity: 0.52;
}

.research-goal-card {
  display: grid;
  gap: 6px;
  border-color: rgba(255, 230, 161, 0.28);
  background: linear-gradient(180deg, rgba(35, 32, 23, 0.72), rgba(16, 23, 34, 0.96));
}

.research-kicker {
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.research-signal-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.research-machine-block,
.research-candidates {
  display: grid;
  gap: 6px;
}

.research-machine-name {
  color: var(--good);
}

.research-candidates {
  margin-top: 3px;
  padding-top: 7px;
  border-top: 1px solid rgba(99, 214, 255, 0.14);
}

.research-inputs {
  display: grid;
  gap: 4px;
  margin-top: 3px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 230, 161, 0.14);
}

.research-input-row {
  display: grid;
  grid-template-columns: minmax(72px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  font-size: 12px;
}

.research-input-row span {
  color: #dfeeff;
  font-weight: 700;
}

.research-input-row b {
  min-width: 0;
  color: var(--muted);
  font-weight: 600;
}

.research-source-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed #263449;
}

.research-source-row:last-child {
  border-bottom: 0;
}

.route-editor {
  display: grid;
  gap: 10px;
}

.route-danger-zone {
  display: grid;
  gap: 8px;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: #adc0d8;
  font-size: 12px;
}

.field select,
.field input {
  width: 100%;
}

.ship-queue {
  display: grid;
  gap: 9px;
  margin-top: 8px;
}

.queue-item {
  display: grid;
  gap: 5px;
}

.queue-item .stat-line {
  padding: 0;
  border-bottom: 0;
}

.progress-bar {
  width: 100%;
  height: 7px;
  overflow: hidden;
  background: #0b111a;
  border: 1px solid #253751;
  border-radius: 999px;
}

.progress-bar span {
  display: block;
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  box-shadow: 0 0 12px rgba(99, 214, 255, 0.22);
}

.log {
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  max-height: 100%;
}

.log-entry {
  border-bottom: 1px solid #1d2839;
  padding-bottom: 6px;
  color: #c8d8ec;
}

@media (max-width: 980px) {
  .app-shell {
    height: 100%;
  }

  .map-panel {
    height: 100%;
  }
}
