:root {
  color-scheme: dark;
  font:
    14px/1.5 system-ui,
    sans-serif;
  color: #dbe5e9;
  background: #0b0f13;
  --accent: #8ce6c5;
  --metal: #c9d3dc;
  --energy: #ffd166;
  --danger: #ff6b5a;
  --muted: #7d8f98;
  --line: #2a3941;
  --panel: #10171ce6;
}
[hidden] {
  display: none !important;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  overflow: hidden;
  background: #0b0f13;
}
#game {
  display: block;
  width: 100vw;
  height: 100dvh;
  outline: none;
  touch-action: none;
  cursor: default;
}
#game.placing {
  cursor: crosshair;
}
#game.targeting {
  cursor: crosshair;
}
#game.locked {
  cursor: none;
}

/* The cursor drawn while the mouse is captured: an arrow, or crosshairs while aiming an order */
#cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  pointer-events: none;
  line-height: 0;
}
#cursor svg {
  display: block;
  overflow: visible;
}
#cursor .arrow {
  fill: #eef4f7;
  stroke: #0b0f13;
  stroke-width: 1.4;
  stroke-linejoin: round;
}
#cursor .cross {
  display: none;
  fill: none;
  stroke: #ffd166;
  stroke-width: 1.8;
  transform: translate(-11px, -11px);
}
#cursor.aim .arrow {
  display: none;
}
#cursor.aim .cross {
  display: inline;
}
button.icon.on {
  border-color: var(--accent);
  color: var(--accent);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
.label {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #91a5ae;
}
.small {
  font-size: 12px;
  color: var(--muted);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* Top bar: the two resources, as stored, income and spending */
.topbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: stretch;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: calc(100vw - 32px);
  flex-wrap: wrap;
  justify-content: center;
}
.res {
  width: 210px;
}
.res-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.res-head .mono {
  font-size: 13px;
}
.bar {
  height: 7px;
  border-radius: 4px;
  background: #1c272d;
  overflow: hidden;
  margin: 3px 0 2px;
}
#metal-fill {
  height: 100%;
  background: var(--metal);
}
#energy-fill {
  height: 100%;
  background: var(--energy);
}
.flow {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.flow .in {
  color: #6fe08a;
}
.flow .out {
  color: #ff9c8a;
}
.res.stalled .bar {
  outline: 1px solid var(--danger);
}
.stats {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 13px;
}
.stats div {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
button.icon {
  font: inherit;
  color: #c4d2d8;
  background: #16212a;
  border: 1px solid #3c515b;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
}

/* Side panel: what's selected, its orders and its build menu */
#side {
  position: fixed;
  left: 12px;
  top: 90px;
  width: 232px;
  max-height: calc(100dvh - 90px - 210px);
  overflow-y: auto;
  padding: 10px;
}
.sel-title {
  font-weight: 600;
  font-size: 15px;
}
.orders {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0;
}
.orders:empty {
  display: none;
}
.orders button {
  font: inherit;
  font-size: 12px;
  color: #c4d2d8;
  background: #16212a;
  border: 1px solid #3c515b;
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}
.orders button.on {
  border-color: var(--accent);
  color: var(--accent);
}
.orders button:disabled {
  opacity: 0.4;
  cursor: default;
}
.orders kbd {
  font-size: 10px;
  margin-left: 4px;
}
#build-head {
  margin: 6px 0 4px;
}
.build {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.build button {
  font: inherit;
  color: inherit;
  text-align: left;
  position: relative;
  display: grid;
  gap: 1px;
  padding: 6px 7px;
  background: #16212a;
  border: 1px solid #3c515b;
  border-radius: 7px;
  cursor: pointer;
  min-height: 52px;
}
.build button:hover {
  border-color: var(--accent);
}
.build button.on {
  border-color: var(--accent);
  background: #1a2a31;
}
.build strong {
  font-size: 12px;
  line-height: 1.2;
}
.build .cost {
  font-size: 11px;
  color: var(--muted);
}
.build .cost .m {
  color: var(--metal);
}
.build .cost .e {
  color: var(--energy);
}
.build .count {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.build .bar-mini {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: #5ef0c0;
  border-radius: 0 0 0 6px;
}
.hint {
  margin-top: 8px;
}
.hint:empty {
  display: none;
}

#mini-wrap {
  position: fixed;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  padding: 4px;
  line-height: 0;
}
#minimap {
  width: 184px;
  height: 184px;
  border-radius: 5px;
  cursor: pointer;
}

#toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 8px;
  background: #1d1414ee;
  border: 1px solid #5a2f2a;
  color: #ffc9bf;
  pointer-events: none;
  font-size: 13px;
}
#toast.good {
  background: #13201aee;
  border-color: #2f5a48;
  color: #bff5df;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #0b0f13b8;
  backdrop-filter: blur(2px);
  overflow-y: auto;
}
.dialog {
  width: min(600px, 100%);
  background: #10171c;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
}
.dialog h1 {
  margin: 0 0 4px;
  font-size: clamp(34px, 8vw, 56px);
  letter-spacing: -0.04em;
  line-height: 1;
}
.dialog h1 span {
  color: #4ea8ff;
  margin-left: 0.2em;
}
.dialog p {
  color: #9bafb8;
  margin: 8px 0 18px;
}
.keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 14px;
  text-align: left;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 18px;
  color: #c4d2d8;
  font-size: 13px;
}
.keys > span:nth-child(odd) {
  color: #91a5ae;
  white-space: nowrap;
}
kbd {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  padding: 1px 6px;
  border: 1px solid #3c515b;
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--energy);
  background: #16212a;
}
.difficulty {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 16px;
}
.difficulty button {
  font: inherit;
  color: #9bafb8;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
}
.difficulty button.on {
  background: #1f2d35;
  color: var(--accent);
}
button.primary {
  display: block;
  margin: 0 auto;
  font: inherit;
  font-weight: 600;
  color: #0b0f13;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 10px 22px;
  cursor: pointer;
}
button.primary:hover {
  filter: brightness(1.1);
}
button.ghost {
  display: block;
  margin: 10px auto 0;
  font: inherit;
  color: #9bafb8;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 16px;
  cursor: pointer;
}
.dialog .small {
  margin-top: 16px;
}
dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 18px;
  width: fit-content;
  margin: 12px auto 20px;
  text-align: left;
}
dt {
  color: var(--muted);
}
dd {
  margin: 0;
}

@media (max-width: 700px) {
  .res {
    width: 150px;
  }
  #side {
    width: 190px;
  }
  #minimap {
    width: 130px;
    height: 130px;
  }
  #side {
    max-height: calc(100dvh - 140px - 160px);
    top: 140px;
  }
}
