:root {
  --bg: #05040a;
  --cyan: #38e8ff;
  --magenta: #ff3ea5;
  --violet: #9d6bff;
  --ink: #dfe9ff;
  --dim: #7f8ba8;
  --line: rgba(56, 232, 255, .28);
  --panel: rgba(6, 8, 18, .82);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "DejaVu Sans Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

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

canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
canvas#hud { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }

#ui { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#ui > * { pointer-events: auto; }

button {
  font-family: var(--mono); font-size: 12px; letter-spacing: .06em;
  color: var(--ink); background: rgba(10, 16, 28, .78);
  border: 1px solid var(--line); padding: 8px 12px; cursor: pointer;
  text-transform: uppercase; transition: background .15s, border-color .15s, color .15s;
}
button:hover { border-color: var(--cyan); color: #fff; background: rgba(20, 40, 60, .9); }
button:focus-visible { outline: 1px solid var(--cyan); outline-offset: 2px; }
button.on { border-color: var(--cyan); color: #04121a; background: var(--cyan); }
button.primary {
  border: 1px solid var(--cyan); background: linear-gradient(180deg, rgba(56,232,255,.16), rgba(56,232,255,.04));
  color: #d9faff; padding: 12px 18px; font-size: 13px; letter-spacing: .12em;
}
button.primary:hover { background: var(--cyan); color: #04121a; }
button.ghost { border-style: dashed; }
.hidden { display: none !important; }

/* ---------------- boot ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 45%, rgba(20, 8, 40, .72), rgba(3, 2, 8, .94) 70%);
  backdrop-filter: blur(3px); padding: 18px; overflow: auto;
}
.panel {
  width: min(560px, 100%); border: 1px solid var(--line);
  background: var(--panel); padding: 26px 24px;
  box-shadow: 0 0 60px rgba(56, 232, 255, .08), inset 0 0 40px rgba(157, 107, 255, .05);
}
.panel h1 {
  margin: 0 0 6px; font-size: 44px; letter-spacing: .34em; font-weight: 500;
  color: #fff; text-shadow: 0 0 18px rgba(56, 232, 255, .55);
}
.panel h1 span { color: var(--cyan); }
.panel .tag { margin: 0 0 20px; color: var(--dim); font-size: 12px; letter-spacing: .08em; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 11px; letter-spacing: .18em; color: var(--dim); margin-bottom: 6px; text-transform: uppercase; }
.field input {
  width: 100%; padding: 10px 12px; background: rgba(2, 6, 14, .9); color: var(--ink);
  border: 1px solid var(--line); font-family: var(--mono); font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--cyan); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.status { margin: 0 0 16px; color: var(--dim); font-size: 11px; min-height: 1.4em; }
.status b { color: var(--cyan); font-weight: 500; }
.keys { list-style: none; padding: 12px 0 0; margin: 0; border-top: 1px solid rgba(127, 139, 168, .2); display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px 12px; font-size: 11px; color: var(--dim); }
.keys b { color: var(--ink); font-weight: 500; }

/* ---------------- hud ---------------- */
.stats {
  position: absolute; top: 10px; left: 12px; padding: 8px 10px;
  font-size: 11px; line-height: 1.5; color: var(--dim);
  background: rgba(4, 6, 14, .62); border-left: 2px solid var(--cyan);
  white-space: pre; pointer-events: none; max-width: 46vw;
}
.stats b { color: var(--ink); font-weight: 500; }
.stats .ok { color: var(--cyan); }
.stats .warn { color: #ffb04a; }

#tools { position: absolute; top: 10px; right: 12px; display: flex; gap: 6px; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; max-width: 40vw; }
#tools .tool { padding: 7px 10px; font-size: 11px; }

.buildinfo {
  position: absolute; left: 50%; bottom: 88px; transform: translateX(-50%);
  padding: 7px 12px; font-size: 11px; color: var(--cyan);
  background: rgba(4, 8, 16, .8); border: 1px solid var(--line); white-space: nowrap;
}

#chatlog {
  position: absolute; left: 12px; bottom: 52px; width: min(430px, 62vw);
  max-height: 32vh; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end;
  gap: 3px; font-size: 12px; line-height: 1.4; pointer-events: none;
}
#chatlog div { text-shadow: 0 1px 3px #000; }
#chatlog .who { font-weight: 600; }
#chatlog .sys { color: var(--dim); font-style: italic; }

#chatform {
  position: absolute; left: 12px; bottom: 14px; width: min(430px, 62vw);
  display: flex; align-items: center; gap: 6px;
  background: rgba(4, 8, 16, .9); border: 1px solid var(--line); padding: 6px 10px;
}
#chatform .prompt { color: var(--cyan); }
#chatform input { flex: 1; background: none; border: none; color: var(--ink); font-family: var(--mono); font-size: 13px; outline: none; }

.help {
  position: absolute; right: 12px; top: 62px; width: min(420px, 88vw);
  background: var(--panel); border: 1px solid var(--line); padding: 14px 16px;
  font-size: 12px; line-height: 1.7; color: var(--dim);
}
.help h2 { margin: 0 0 8px; font-size: 12px; letter-spacing: .2em; color: var(--cyan); font-weight: 500; text-transform: uppercase; }
.help p { margin: 0 0 8px; }
.help b { color: var(--ink); font-weight: 500; }
.help .dim { color: #5d6780; font-size: 11px; }

.touch {
  position: absolute; left: 12px; bottom: 14px; right: 12px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.stick {
  width: 116px; height: 116px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(6, 10, 20, .5);
  position: relative; touch-action: none; flex: 0 0 auto;
}
.knob {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%; background: rgba(56, 232, 255, .22);
  border: 1px solid var(--cyan); transition: transform .06s linear;
}
.tbtns { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
@media (min-width: 900px) { .touch { display: none !important; } }

.toast {
  position: absolute; left: 50%; top: 18px; transform: translate(-50%, -20px);
  padding: 9px 14px; background: rgba(6, 10, 20, .92); border: 1px solid var(--line);
  color: var(--ink); font-size: 12px; opacity: 0; transition: opacity .25s, transform .25s;
  pointer-events: none; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.lockhint {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  font-size: 11px; letter-spacing: .1em; color: var(--dim);
  background: rgba(4, 6, 14, .7); padding: 6px 12px; border: 1px solid var(--line);
  pointer-events: none;
}
.vrnote {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  font-size: 11px; color: var(--dim); background: rgba(4, 6, 14, .7); padding: 6px 12px;
  pointer-events: none;
}

@media (pointer: coarse) {
  .lockhint { display: none !important; }
  #chatlog { bottom: 152px; max-height: 20vh; width: 60vw; }
  #chatform { bottom: 150px; width: 60vw; }
  .stats { font-size: 10px; max-width: 54vw; }
}

@media (max-width: 820px) {
  .panel h1 { font-size: 32px; letter-spacing: .24em; }
  .keys { grid-template-columns: repeat(2, 1fr); }
  .stats { font-size: 10px; max-width: 56vw; }
  #chatlog { width: 78vw; max-height: 24vh; }
  #chatform { width: 78vw; }
  #tools .tool { padding: 6px 8px; font-size: 10px; }
}
