:root {
  --bg: #090b13;
  --panel: rgba(16, 19, 30, 0.82);
  --panel-line: rgba(255, 255, 255, 0.09);
  --text: #e8eaf2;
  --muted: #99a0b5;
  --accent: #f9ca20;
  --accent-dim: rgba(249, 202, 32, 0.16);
  --danger: #ff8271;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.fallback {
  position: fixed;
  inset: auto 0 0 0;
  top: 50%;
  transform: translateY(-50%);
  margin: 0 auto;
  max-width: 30rem;
  padding: 1.25rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  text-align: center;
  line-height: 1.5;
  z-index: 40;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  pointer-events: none;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  pointer-events: auto;
}

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background:
    linear-gradient(135deg, var(--accent) 0%, var(--accent) 45%, rgba(249, 202, 32, 0.25) 46%, rgba(255,255,255,0.12) 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14), 0 6px 18px rgba(0, 0, 0, 0.5);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 0.95rem; letter-spacing: 0.01em; }
.brand-text small { font-size: 0.68rem; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.topbar-actions { display: flex; gap: 0.4rem; pointer-events: auto; }

.icon-button {
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  backdrop-filter: blur(14px);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.icon-button svg { width: 19px; height: 19px; }
.icon-button:hover { border-color: rgba(249, 202, 32, 0.6); color: var(--accent); }
.icon-button:active { transform: scale(0.94); }
#btn-info span[aria-hidden] { font-style: italic; font-weight: 700; }

/* ----------------------------------------------------------------- panel */

.panel {
  position: fixed;
  top: 3.6rem;
  right: 1rem;
  width: 17.5rem;
  max-height: calc(100% - 5rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  z-index: 15;
  scrollbar-width: thin;
}
.panel[hidden] { display: none; }

.transport { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.35rem; }

button, select, input[type="text"] {
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  padding: 0.42rem 0.55rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
button:hover, select:hover { border-color: rgba(255, 255, 255, 0.28); }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary {
  background: var(--accent-dim);
  border-color: rgba(249, 202, 32, 0.45);
  color: var(--accent);
  font-weight: 600;
}
button.wide { width: 100%; }

.group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--panel-line);
}

.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.row > span:first-child { flex: 0 0 4.1rem; }
.row select, .row input[type="text"] { flex: 1 1 auto; min-width: 0; }
.row.slider input[type="range"] { flex: 1 1 auto; min-width: 0; }
.row.slider output {
  flex: 0 0 2.9rem;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.row.check { cursor: pointer; color: var(--text); }
.row.check input { accent-color: var(--accent); cursor: pointer; }

input[type="range"] {
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 0 3px rgba(249, 202, 32, 0.18);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

.hint {
  margin: 0.1rem 0 0;
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--muted);
}
.hint code, kbd {
  font-family: var(--mono);
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}
kbd { border: 1px solid var(--panel-line); }

.error {
  margin: 0;
  font-size: 0.7rem;
  color: var(--danger);
}
.error[hidden] { display: none; }

.stats {
  margin: 0;
  padding-top: 0.65rem;
  border-top: 1px solid var(--panel-line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 0.6rem;
  font-size: 0.7rem;
}
.stats div { display: flex; flex-direction: column; }
.stats dt { color: var(--muted); letter-spacing: 0.03em; }
.stats dd {
  margin: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.drag-hint {
  position: fixed;
  left: 1rem;
  bottom: 0.9rem;
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  z-index: 12;
  transition: opacity 0.6s;
  pointer-events: none;
}
.drag-hint.faded { opacity: 0; }

/* ----------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 10, 0.72);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  max-width: 40rem;
  max-height: min(86vh, 46rem);
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  padding: 1.9rem 2.2rem 1.5rem 2rem;
  background: #12151f;
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  line-height: 1.62;
  font-size: 0.9rem;
  animation: rise 0.22s ease-out;
}
.modal-card::-webkit-scrollbar { width: 10px; }
.modal-card::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border: 3px solid #12151f;
  border-radius: 6px;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .modal-card { animation: none; }
}

.modal-card h2 {
  margin: 0 0 0.6rem;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}
.modal-card h3 {
  margin: 1.5rem 0 0.4rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
}
.modal-card p { margin: 0 0 0.85rem; color: #cfd3e0; }
.modal-card p.lede { font-size: 1.02rem; color: var(--text); }
.modal-card ul { margin: 0 0 0.9rem; padding-left: 1.15rem; color: #cfd3e0; }
.modal-card li { margin-bottom: 0.4rem; }
.modal-card code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.modal-card a { color: var(--accent); }
.modal-card .foot {
  margin: 1.4rem 0 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--panel-line);
  font-size: 0.78rem;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 0.72em; height: 0.72em;
  border-radius: 2px;
  margin-right: 0.15em;
  vertical-align: baseline;
}
.swatch-live { background: #f9ca20; }
.swatch-fade { background: #8b8b8b; }

.keys { border-collapse: collapse; font-size: 0.82rem; }
.keys td { padding: 0.22rem 0.9rem 0.22rem 0; color: #cfd3e0; vertical-align: top; }
.keys td:first-child { white-space: nowrap; }

.modal-close {
  position: absolute;
  top: 0.7rem; right: 1.1rem;
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.modal-close:hover { color: var(--text); border-color: var(--panel-line); }

/* --------------------------------------------------------------- responsive */

@media (max-width: 640px) {
  .panel {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    top: auto;
    bottom: 0.5rem;
    max-height: 56%;
  }
  .drag-hint { display: none; }
  .modal-card { padding: 1.6rem 1.2rem 1.2rem; }
}
