:root {
  --bg: #0a0c11;
  --fg: #e7ecf5;
  --muted: #8d97ab;
  --line: rgba(255, 255, 255, 0.1);
  --panel: rgba(16, 20, 28, 0.66);
  --accent: #6aa9ff;
  --pad: 16px;
  --font: ui-sans-serif, system-ui, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* `hidden` musí vyhrát i nad `display: grid` u polí panelu – výchozí pravidlo
   prohlížeče má nižší prioritu a schované ovladače by zůstaly vidět */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.45 var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;

  /* ať se to chová jako aplikace, ne jako stránka:
     žádné označování textu, žádná lupa a menu po přidržení prstu */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

input,
textarea {
  user-select: auto;
  -webkit-user-select: auto;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- boot / error ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 20;
  transition: opacity .5s ease;
}

.boot__inner {
  display: grid;
  gap: 14px;
  justify-items: center;
  max-width: min(520px, calc(100vw - 32px));
  text-align: center;
}

.boot__spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 720ms linear infinite;
}

.boot__text {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .04em;
  white-space: pre-wrap;
}

body.is-ready .boot {
  opacity: 0;
  pointer-events: none;
}

body.has-error .boot__spinner {
  display: none;
}

body.has-error .boot__text {
  color: #ff8a7a;
  text-align: left;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- hud ---------- */

.hud {
  position: fixed;
  z-index: 10;
  transition: opacity .25s ease, transform .25s ease;
}

body.hud-hidden .hud {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

.hud--top {
  top: max(var(--pad), env(safe-area-inset-top, 0px));
  left: var(--pad);
  right: var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: .02em;
}

.brand__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.brand__version {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  opacity: 0.7;
}

.focus {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12px;
  color: var(--fg);
  white-space: nowrap;
}

.toast {
  max-width: min(520px, 60vw);
  white-space: normal;
  text-align: center;
}

.toast--error {
  border-color: rgba(255, 138, 122, 0.5);
  color: #ffb4a8;
}

/* tvoření: kurzor ukazuje, že kliknutí něco vytvoří */
/* vypouštění tělesa: šipka a popisek u kurzoru */
.launch {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  color: #8fd0ff;
  overflow: visible;
}

.launch--bad {
  color: #ff6b5e;
}

.launch line {
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.launch polygon {
  fill: currentColor;
}

.launch circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.launch-label {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 15; /* nad panelem – kurzor může být u jeho okraje */
  max-width: min(22rem, calc(100vw - 16px));
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  background: rgba(8, 12, 20, 0.94);
  border: 1px solid rgba(143, 208, 255, 0.35);
  color: #dbeeff;
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-line;
  pointer-events: none;
}

.info {
  font-variant-numeric: tabular-nums;
}

.info::first-line {
  font-weight: 600;
  color: #fff;
}

.launch-label--bad {
  border-color: rgba(255, 107, 94, 0.6);
  color: #ffd2cc;
}

body.is-creating #scene {
  cursor: crosshair;
}

.field-button {
  width: 100%;
}

.field-button--danger {
  border-color: rgba(255, 138, 122, 0.35);
  color: #ffb4a8;
}

.field-button--danger:hover {
  background: rgba(255, 138, 122, 0.12);
}

/* čeká na potvrzení druhým klikem */
.field-button--armed {
  background: rgba(255, 138, 122, 0.22);
  border-color: rgba(255, 138, 122, 0.8);
  color: #fff;
}

.panel__section {
  margin: 6px 0 -2px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.panel__section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.stats {
  display: flex;
  gap: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.hud--panel {
  right: var(--pad);
  bottom: max(var(--pad), env(safe-area-inset-bottom, 0px));
  width: 246px;
  display: grid;
  /* nadpis / seznam ovladačů / tlačítka / nápověda –
     prostřední řádek se smí smrsknout, jinak panel přeteče přes obrazovku */
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 14px;
  max-height: min(82vh, 720px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.panel__title {
  margin: 0;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel__body {
  display: grid;
  gap: 9px;
  min-height: 0; /* bez tohohle grid položku nezmenší a panel přeteče */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  margin-right: -4px;
}

.panel__body::-webkit-scrollbar { width: 6px; }
.panel__body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 3px;
}

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

.field__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.field__label {
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}

/* hodnota je zároveň políčko na přesné zadání čísla */
input.field__value {
  width: 74px;
  padding: 1px 4px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 11px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input.field__value:hover {
  border-color: var(--line);
}

input.field__value:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
}

select {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

option {
  background: #11151d;
  color: var(--fg);
}

.field--toggle {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

input[type="range"] {
  width: 100%;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="color"] {
  width: 100%;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

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

button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}

button:hover { background: rgba(255, 255, 255, 0.1); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.05);
  font-family: var(--mono);
  font-size: 10px;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 30;
  padding: 24px;
  text-align: center;
}

@media (max-width: 640px) {
  .hud--panel {
    left: var(--pad);
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .boot__spinner { animation-duration: 3s; }
}
