:root {
  --ui-bg: rgba(14, 16, 22, 0.88);
  --ui-line: rgba(255, 255, 255, 0.12);
  --ui-soft: rgba(255, 255, 255, 0.08);
  --ui-text: #d8e3f1;
  --ui-muted: rgba(216, 227, 241, 0.64);
  --blue: #4c8cff;
  --green: #5ae12a;
  --purple: #a03dde;
  --red: #f04747;
  --gold: #bb8619;
  --cyan: #19bdd0;
  --olive: #b3aa00;
  --orange: #ff6f0f;
  --indigo: #6667d9;
  --violet: #9b59d0;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse 120% 80% at 50% 100%, #0a1528 0%, #020308 45%, #010205 100%);
}

body {
  font-family: "Trebuchet MS", Verdana, sans-serif;
  color: var(--ui-text);
}

* {
  box-sizing: border-box;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

button,
input,
textarea {
  font: inherit;
}

#hud,
#buildPanel,
#hammerPanel,
#chatPanel {
  position: fixed;
  z-index: 10;
}

#hud {
  right: 22px;
  bottom: 128px;
  width: min(530px, calc(100vw - 44px));
  padding: 18px 24px;
  border: 1px solid var(--ui-line);
  background: linear-gradient(180deg, rgba(20, 22, 29, 0.82), rgba(10, 11, 16, 0.86));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  color: rgba(255, 255, 255, 0.92);
  text-align: center;
  backdrop-filter: blur(10px);
}

.hud-main {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.hud-main strong {
  display: block;
  width: 100%;
  margin-bottom: 6px;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #a8c8ff;
  text-shadow: 0 0 18px rgba(100, 160, 255, 0.35);
}

.hud-actions {
  display: contents;
}

.hud-actions button {
  position: fixed;
  left: 12px;
  width: 94px;
  height: 94px;
  border-radius: 8px;
  border: 3px solid currentColor;
  background: rgba(8, 10, 14, 0.82);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  color: white;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

#buildToggleButton {
  top: 164px;
  color: var(--blue);
}

#hammerToggleButton {
  top: 276px;
  color: var(--green);
}

.hud-actions button.is-active {
  background: rgba(24, 34, 54, 0.92);
}

#buildPanel,
#chatPanel {
  border: 1px solid var(--ui-line);
  background: linear-gradient(180deg, rgba(15, 16, 20, 0.9), rgba(9, 10, 14, 0.88));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(12px);
}

#buildPanel {
  top: 30px;
  left: 124px;
  width: min(380px, calc(100vw - 148px));
  max-height: calc(100vh - 60px);
  padding: 18px;
  overflow: auto;
}

#buildPanel.is-hidden {
  display: none;
}

#chatPanel {
  left: 22px;
  bottom: 22px;
  width: min(280px, calc(100vw - 44px));
  overflow: hidden;
}

#hammerPanel {
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(960px, calc(100vw - 220px));
  background: transparent;
  box-shadow: none;
}

#hammerPanel.is-hidden {
  display: none;
}

#hammerPanel .panel-head {
  display: none;
}

#hammerPanel .panel-section {
  margin: 0;
}

#hammerPanel .section-label {
  display: none;
}

#hammerPanel .panel-section + .panel-section {
  margin-top: 14px;
}

#configFields {
  display: grid;
  gap: 10px;
}

.section-label--spaced {
  margin-top: 10px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head.compact {
  margin-top: 10px;
}

.panel-head h1,
.panel-head h2,
.panel-head p {
  margin: 0;
}

.panel-head h1,
.panel-head h2 {
  color: #f7f0d8;
  font-size: 24px;
}

.panel-head p,
.panel-head span {
  font-size: 12px;
  color: var(--ui-muted);
}

.doc-warning {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(240, 71, 71, 0.45);
  border-radius: 8px;
  background: rgba(40, 12, 14, 0.55);
  font-size: 12px;
  line-height: 1.45;
  color: #f0d6d8;
}

.doc-warning strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: #ffb4b4;
  letter-spacing: 0.03em;
}

.doc-warning p {
  margin: 0 0 8px;
}

.doc-warning p:last-child {
  margin-bottom: 0;
}

.doc-warning-more {
  margin-top: 6px !important;
  margin-bottom: 0 !important;
}

.doc-warning-more a {
  color: #9ec8ff;
}

.doc-downloads {
  padding-bottom: 4px;
}

.doc-download-row {
  margin-bottom: 8px;
}

.doc-download-split {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-dl {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: rgba(255, 255, 255, 0.05);
  color: #c5daf7;
  font-size: 12px;
  text-decoration: none;
}

.doc-dl:hover {
  background: rgba(76, 140, 255, 0.18);
  border-color: rgba(76, 140, 255, 0.35);
  color: #fff;
}

.doc-dl-primary {
  width: 100%;
  text-align: center;
  font-weight: 700;
  border-color: rgba(76, 140, 255, 0.45);
  background: rgba(76, 140, 255, 0.12);
}

.doc-download-hint {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--ui-muted);
}

.doc-warning-more code {
  font-size: 11px;
  color: #b8d0ff;
}

#screenToolsSection label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 12px;
}

.screen-tools-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--ui-muted);
  line-height: 1.4;
}

.screen-clear-btn {
  margin-top: 12px;
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: rgba(255, 100, 80, 0.12);
  color: #ffb4a8;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.screen-clear-btn:hover {
  background: rgba(255, 100, 80, 0.22);
}

.panel-section {
  margin-bottom: 16px;
}

.section-label {
  margin-bottom: 8px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #93b0d4;
}

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

.part-palette button,
.preset-grid button,
.action-row button,
#chatSend,
#applyConfigButton {
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ui-text);
  padding: 10px 12px;
  cursor: pointer;
}

.part-palette button.active {
  background: linear-gradient(180deg, rgba(36, 134, 255, 0.95), rgba(18, 76, 153, 0.95));
  color: white;
}

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

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

@media (max-width: 420px) {
  .preset-grid--rockets {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.doc-warning kbd {
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  border: 1px solid var(--ui-line);
  background: rgba(0, 0, 0, 0.25);
}

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

#fireButton {
  background: rgba(255, 255, 255, 0.06);
  color: #e2e2e2;
}

#duplicateButton {
  color: #d5a9ff;
}

#deleteButton {
  color: #ff8a8a;
}

label {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}

input[type="range"],
input[type="text"],
input[type="number"],
input[type="color"] {
  width: 100%;
}

.readout,
.console-box,
#chatLog {
  border: 1px solid var(--ui-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ui-text);
}

.readout {
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
}

#scriptEditor {
  width: 100%;
  min-height: 124px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--ui-line);
  background: rgba(0, 0, 0, 0.3);
  color: white;
}

.console-box {
  min-height: 96px;
  max-height: 180px;
  overflow: auto;
  padding: 10px;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
}

#pcCanvasHost {
  min-height: 110px;
  margin-top: 10px;
  background: radial-gradient(circle at top, rgba(44, 60, 98, 0.46), rgba(7, 10, 18, 0.92));
  border: 1px solid var(--ui-soft);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.62);
}

#chatLog {
  height: 96px;
  overflow: auto;
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
}

.chat-msg + .chat-msg {
  margin-top: 6px;
}

.chat-name {
  color: #91d0ff;
  font-weight: 700;
}

#chatForm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
}

#chatInput {
  border: 1px solid var(--ui-line);
  background: rgba(255, 255, 255, 0.06);
  color: white;
  padding: 10px 12px;
}

.hammer-modes {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 6px;
  align-items: stretch;
}

.hammer-modes button {
  min-height: 92px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  background: rgba(18, 18, 20, 0.94);
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(18px, 2vw, 26px);
  text-transform: none;
  letter-spacing: 0.02em;
}

.hammer-modes button[data-hammer-mode="drag"] {
  border-color: #7099f1;
  background: linear-gradient(180deg, rgba(165, 114, 28, 0.92), rgba(116, 73, 8, 0.96));
}

.hammer-modes button[data-hammer-mode="scale"] {
  border-color: #7de9ff;
  background: linear-gradient(180deg, rgba(33, 167, 196, 0.92), rgba(9, 99, 124, 0.96));
}

.hammer-modes button[data-hammer-mode="paint"] {
  border-color: #83ff4a;
  background: linear-gradient(180deg, rgba(55, 187, 0, 0.92), rgba(20, 99, 0, 0.96));
}

.hammer-modes button[data-hammer-mode="config"] {
  border-color: #b39bff;
  background: linear-gradient(180deg, rgba(92, 88, 199, 0.92), rgba(55, 47, 145, 0.96));
}

.hammer-modes button.is-active {
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12) inset;
}

#hammerPanel .panel-section:nth-of-type(2),
#hammerPanel .panel-section:nth-of-type(3) {
  width: min(500px, calc(100vw - 44px));
  margin-left: auto;
  margin-right: auto;
  padding: 14px 16px;
  border: 1px solid var(--ui-line);
  background: linear-gradient(180deg, rgba(18, 19, 25, 0.9), rgba(9, 10, 14, 0.88));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.34);
}

@media (max-width: 1180px) {
  #hammerPanel {
    width: calc(100vw - 220px);
  }
}

@media (max-width: 900px) {
  #hud {
    width: min(420px, calc(100vw - 24px));
  }

  #hammerPanel {
    width: calc(100vw - 40px);
  }

  .hammer-modes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.starmap-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}

.starmap-modal.is-hidden {
  display: none;
}

.starmap-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 10, 0.72);
  backdrop-filter: blur(6px);
}

.starmap-dialog {
  position: relative;
  z-index: 1;
  max-width: min(440px, 100vw - 24px);
  padding: 18px 20px 20px;
  border: 1px solid var(--ui-line);
  border-radius: 14px;
  background: linear-gradient(165deg, rgba(22, 26, 36, 0.96), rgba(10, 12, 18, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
}

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

.starmap-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #a8c8ff;
  letter-spacing: 0.04em;
}

.starmap-head button {
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ui-text);
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}

.starmap-head button:hover {
  background: rgba(255, 255, 255, 0.12);
}

#starmapCanvas {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  border-radius: 10px;
  border: 1px solid rgba(100, 140, 200, 0.25);
  cursor: crosshair;
}

.starmap-hint {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ui-muted);
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  canvas {
    position: fixed;
    inset: 0;
  }

  #buildToggleButton,
  #hammerToggleButton {
    position: static;
    width: auto;
    height: auto;
    min-height: 56px;
  }

  #hud,
  #buildPanel,
  #hammerPanel,
  #chatPanel {
    position: absolute;
    left: 12px;
    right: 12px;
    width: auto;
    transform: none;
  }

  #hud {
    top: 12px;
    bottom: auto;
  }

  #buildPanel {
    top: 124px;
  }

  #hammerPanel {
    top: 650px;
    bottom: auto;
  }

  #chatPanel {
    top: 1040px;
    bottom: 12px;
  }
}
