:root {
  color-scheme: dark;
  --panel: rgba(13, 18, 24, 0.86);
  --line: rgba(150, 220, 255, 0.18);
  --text: #e8f7ff;
  --muted: #8fa6b6;
  --accent: #2ee6a6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #07090d;
}

.hidden {
  display: none !important;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(5, 8, 12, 0.36), rgba(5, 8, 12, 0.78)),
    radial-gradient(circle at 20% 15%, rgba(46, 230, 166, 0.18), transparent 36%),
    radial-gradient(circle at 80% 75%, rgba(255, 71, 111, 0.16), transparent 38%),
    #07090d;
}

.login > div {
  width: min(560px, 100%);
}

h1 {
  margin: 0 0 12px;
  font-size: 54px;
  line-height: 1;
  letter-spacing: 0;
}

p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  margin: 0 10px 10px 0;
  border: 1px solid rgba(46, 230, 166, 0.45);
  border-radius: 6px;
  color: #03120d;
  background: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.button.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.button.disabled {
  pointer-events: none;
  color: rgba(232, 247, 255, 0.52);
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
}

.authNote {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.game {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#world3d,
#world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#world3d {
  background: #07090d;
}

#world {
  cursor: crosshair;
  image-rendering: pixelated;
}

.hud {
  position: fixed;
  inset: 16px auto 16px 16px;
  width: min(360px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.hud header,
.hud section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.hud header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.hud header strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}

.hud header span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.hud header a {
  color: var(--muted);
  text-decoration: none;
}

.resources {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.resource {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.resource b {
  overflow: hidden;
  text-overflow: ellipsis;
}

.resources.buildInfo {
  display: block;
}

.buildInfoHeader {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(150, 220, 255, 0.12);
}

.buildInfoHeader span,
.buildInfoBlock strong {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.buildInfoHeader strong {
  display: block;
  font-size: 18px;
}

.buildingIcon {
  width: 52px;
  height: 52px;
  padding: 5px;
  border: 1px solid rgba(232, 247, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  overflow: visible;
}

.buildingIcon .iconBase {
  fill: rgba(46, 230, 166, 0.08);
  stroke: rgba(232, 247, 255, 0.12);
}

.buildingIcon path,
.buildingIcon circle {
  fill: color-mix(in srgb, var(--icon-a), #111820 18%);
  stroke: #05080a;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.buildingIcon path:nth-last-child(1),
.buildingIcon circle {
  fill: var(--icon-b);
}

.uiIcon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}

.buildInfoRows {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.buildInfoRows div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
}

.buildInfoRows span,
.buildInfoBlock p {
  color: var(--muted);
}

.buildInfoBlock {
  margin-top: 12px;
}

.buildInfoBlock p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
}

.buildCostList {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.buildCostList span,
.buildCostList em {
  display: inline-flex;
  gap: 6px;
  padding: 5px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-style: normal;
}

.corePortGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.corePortButton {
  min-height: 42px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 800;
  cursor: pointer;
}

.corePortButton > b {
  display: block;
  margin-top: 3px;
}

.corePortButton > span:not(.portIcon) {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.portIcon {
  display: flex;
  justify-content: center;
  gap: 4px;
  color: var(--accent);
}

.corePortButton .portIcon .uiIcon {
  width: 15px;
  height: 15px;
}

.corePortButton.active {
  border-color: rgba(46, 230, 166, 0.75);
  background: rgba(46, 230, 166, 0.14);
}

.portConfigRows {
  display: grid;
  gap: 8px;
}

.portConfigRows div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.portConfigRows span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.portConfigRows select {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(232, 247, 255, 0.14);
  border-radius: 6px;
  color: var(--text);
  background: rgba(5, 9, 12, 0.92);
}

.sectionTitle {
  padding: 12px 12px 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.buildDock {
  position: fixed;
  left: 16px;
  bottom: 16px;
  pointer-events: none;
}

.buildDock > * {
  pointer-events: auto;
}

.buildMenuButton {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid rgba(46, 230, 166, 0.48);
  border-radius: 8px;
  color: #03120d;
  background: var(--accent);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.34);
  font-weight: 800;
  cursor: pointer;
}

.buildMenuButton.open {
  color: var(--text);
  background: rgba(46, 230, 166, 0.18);
}

.buildToolsFrame {
  position: fixed;
  left: 50%;
  bottom: 16px;
  width: min(720px, calc(100vw - 260px));
  min-width: 0;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: stretch;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.buildToolsFrame > * {
  pointer-events: auto;
}

.toolScroll {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.toolScroll:active {
  border-color: rgba(46, 230, 166, 0.72);
  background: rgba(46, 230, 166, 0.16);
}

.tools {
  min-width: 0;
  max-width: none;
  display: flex;
  gap: 8px;
  padding: 10px;
  overflow-x: auto;
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  scrollbar-width: none;
}

.tools::-webkit-scrollbar {
  display: none;
}

.tool {
  min-height: 56px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
  cursor: pointer;
}

.tool {
  flex: 0 0 132px;
}

.tool.active {
  border-color: rgba(46, 230, 166, 0.75);
  background: rgba(46, 230, 166, 0.13);
}

.tool strong,
.tool span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.directionMap {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 180px;
  padding: 10px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.keyHints {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(360px, calc(100vw - 36px));
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.keyHint {
  display: grid;
  grid-template-columns: minmax(64px, auto) 1fr;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  color: var(--muted);
  font-size: 12px;
}

.keyHint kbd {
  min-width: 28px;
  padding: 4px 7px;
  border: 1px solid rgba(232, 247, 255, 0.18);
  border-bottom-color: rgba(232, 247, 255, 0.08);
  border-radius: 5px;
  color: #03120d;
  background: var(--accent);
  font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}

.keyHint.primary {
  color: var(--text);
}

.keyHint.primary kbd {
  background: #f2b84b;
}

.directionMapTitle {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
}

.directionCompass {
  position: relative;
  height: 120px;
}

.directionCompass svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: rgba(46, 230, 166, 0.06);
  stroke: rgba(46, 230, 166, 0.72);
  stroke-width: 2;
  overflow: visible;
}

.directionCompass circle {
  fill: var(--accent);
  stroke: none;
}

.dirLabel {
  position: absolute;
  min-width: 42px;
  padding: 3px 5px;
  border: 1px solid rgba(46, 230, 166, 0.45);
  border-radius: 4px;
  color: #03120d;
  background: var(--accent);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.dirN {
  top: 6px;
  right: 6px;
}

.dirE {
  right: 2px;
  bottom: 14px;
}

.dirS {
  left: 2px;
  bottom: 14px;
}

.dirW {
  top: 6px;
  left: 6px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  opacity: 0;
  transform: translateY(12px);
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .hud {
    inset: 10px 10px auto 10px;
    width: auto;
    max-height: 42vh;
    overflow: auto;
  }

  .resources {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .buildDock {
    left: 10px;
    bottom: 10px;
  }

  .buildMenuButton {
    width: max-content;
  }

  .buildToolsFrame {
    left: 10px;
    right: 10px;
    bottom: 68px;
    width: auto;
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    transform: none;
  }

  h1 {
    font-size: 40px;
  }

  .directionMap {
    top: 10px;
    right: 10px;
    width: 150px;
    padding: 8px;
  }

  .directionCompass {
    height: 100px;
  }

  .dirLabel {
    min-width: 36px;
    font-size: 10px;
  }

  .keyHints {
    right: 10px;
    bottom: 10px;
    width: min(330px, calc(100vw - 20px));
  }
}
