*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c1220;
  color: #f1f3f5;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#gl-canvas,
#hud-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud-canvas {
  pointer-events: none;
  z-index: 2;
}

.hidden {
  display: none !important;
}

#top-actions {
  position: absolute;
  top: 34px;
  right: 12px;
  z-index: 5;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hud-chip {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(12, 16, 24, 0.62);
  color: #f1f3f5;
  font: 600 12px/1 system-ui, -apple-system, sans-serif;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.hud-chip:hover {
  background: rgba(34, 44, 64, 0.85);
  border-color: rgba(255, 255, 255, 0.45);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 12, 22, 0.56);
  backdrop-filter: blur(5px);
}

.modal-card {
  background: rgba(16, 22, 34, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  color: #f8f9fa;
}

.welcome-card {
  width: min(500px, 100%);
  padding: 26px 26px 22px;
}

.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.09em;
  color: #74c0fc;
  background: rgba(51, 154, 240, 0.15);
  border: 1px solid rgba(116, 192, 252, 0.3);
  border-radius: 999px;
  padding: 4px 10px;
  margin-bottom: 10px;
}

.welcome-card h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
}

.subtitle {
  margin: 6px 0 18px;
  font-size: 14px;
  color: #ced4da;
  line-height: 1.45;
}

.welcome-form {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #adb5bd;
  margin-bottom: 6px;
}

.name-row {
  display: flex;
  gap: 10px;
}

.text-input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(6, 10, 18, 0.85);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.text-input:focus {
  border-color: #69db7c;
  box-shadow: 0 0 0 2px rgba(105, 219, 124, 0.25);
}

.primary-btn {
  appearance: none;
  border: 1px solid #8ce99a;
  background: linear-gradient(180deg, #40c057, #2b8a3e);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  padding: 11px 22px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(6, 10, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #dee2e6;
}

kbd {
  display: inline-block;
  padding: 2px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  color: #fff3bf;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 4px;
}

.error-banner {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(201, 42, 42, 0.25);
  border: 1px solid #ff6b6b;
  color: #ffc9c9;
  font-size: 13px;
  font-weight: 600;
}

.block-card-modal {
  width: min(760px, 100%);
  max-height: min(86vh, 680px);
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.modal-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: #adb5bd;
}

.icon-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #f8f9fa;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.menu-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.tab-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #dee2e6;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 7px;
  cursor: pointer;
}

.tab-btn.active {
  background: #228be6;
  border-color: #74c0fc;
  color: #ffffff;
}

.search-input {
  max-width: 210px;
  padding: 7px 11px;
  font-size: 13px;
}

.block-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  padding: 4px 2px;
  touch-action: pan-y;
}

.block-item {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(8, 12, 20, 0.72);
  color: #f1f3f5;
  cursor: pointer;
  text-align: center;
}

.block-item:hover,
.block-item:focus-visible {
  background: rgba(34, 139, 230, 0.24);
  border-color: #74c0fc;
  outline: none;
}

.block-item.selected {
  background: rgba(64, 192, 87, 0.24);
  border-color: #69db7c;
}

.block-icon {
  width: 44px;
  height: 44px;
  image-rendering: pixelated;
}

.block-name {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.block-tag {
  font-size: 10px;
  font-weight: 700;
  color: #ffd43b;
}

.preset-bar {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.preset-label {
  font-size: 12px;
  font-weight: 700;
  color: #adb5bd;
}

.chip-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #f1f3f5;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.chat-bar {
  position: absolute;
  left: 10px;
  bottom: 72px;
  z-index: 12;
  width: min(560px, calc(100% - 20px));
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 9px;
  background: rgba(10, 14, 24, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: #ffffff;
  font-size: 14px;
  padding: 6px 8px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.chat-send-btn,
.chat-cancel-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chat-send-btn {
  background: #2b8a3e;
  color: #ffffff;
}

.chat-cancel-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #dee2e6;
}

#touch-controls {
  position: absolute;
  right: 14px;
  bottom: 76px;
  z-index: 6;
}

.touch-cluster {
  display: grid;
  grid-template-columns: repeat(2, 66px);
  gap: 8px;
}

.touch-btn {
  appearance: none;
  height: 54px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(14, 20, 32, 0.65);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.touch-btn.active {
  background: rgba(51, 154, 240, 0.6);
  border-color: #a5d8ff;
}

.touch-primary {
  background: rgba(43, 138, 62, 0.68);
}

.touch-warn {
  background: rgba(217, 72, 15, 0.68);
}

@media (max-width: 600px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
  .welcome-card {
    padding: 18px;
  }
  #top-actions {
    top: 32px;
    right: 8px;
  }
}
