:root {
  --bg: #000000;
  --ink: #000;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  touch-action: manipulation;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ink);
  letter-spacing: 0.02em;
}
body.ui-hidden .hud,
body.ui-hidden #gui,
body.ui-hidden .frame { display: none !important; }

#c {
  display: block;
  position: fixed;
  inset: 0;
  margin: auto;
  background: #000;
  z-index: 1;
}

.frame {
  position: fixed; inset: 12px;
  border: 1px solid var(--ink);
  pointer-events: none;
  z-index: 5;
}

.hud {
  position: fixed;
  pointer-events: none;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  z-index: 10;
  color: #000;
  line-height: 1.4;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 0, 0, 0.35);
}
.hud .title { font-size: 13px; letter-spacing: 0.3em; }
.hud .sub   { opacity: 0.7; margin-top: 4px; }
.tl { top: 24px; left: 28px; }
.tr { top: 24px; right: 28px; text-align: right; }
.bl { bottom: 24px; left: 28px; }
.br { bottom: 24px; right: 28px; text-align: right; }

/* ---------- GUI panel ---------- */
#gui {
  position: fixed;
  top: 24px;
  right: 28px;
  width: 268px;
  pointer-events: auto;
  z-index: 20;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #000;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 0, 0, 0.45);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
#gui::-webkit-scrollbar { width: 4px; }
#gui::-webkit-scrollbar-track { background: transparent; }
#gui::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.35); }
#guiHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 12px 14px;
  font-size: 11px;
  letter-spacing: 0.28em;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(6px);
  z-index: 1;
}
#guiHeader:hover { background: rgba(0, 0, 0, 0.06); }
#guiToggle { opacity: 0.7; font-size: 13px; line-height: 1; }
#guiBody {
  padding: 0 14px 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.25);
  padding-top: 12px;
}
#gui.collapsed #guiBody { display: none; }
#gui.collapsed #guiHeader { border: 0; }
#gui *, #gui *::before, #gui *::after { box-sizing: border-box; }
#gui h4 {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  margin: 0 0 10px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
}
#gui .section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.25);
}
#guiBody > .section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
#gui .row {
  display: grid;
  grid-template-columns: 76px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  min-width: 0;
}
#gui .row label {
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#gui .row .val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}
#gui input[type="range"] {
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 1px;
  background: rgba(0, 0, 0, 0.5);
  outline: none;
  margin: 0;
  padding: 0;
}
#gui input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  background: #000;
  border: 0;
  cursor: pointer;
}
#gui input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: #000;
  border: 0;
  cursor: pointer;
  border-radius: 0;
}
#gui select {
  width: 100%;
  background: rgba(255,255,255,0.7);
  color: #000;
  border: 1px solid rgba(0,0,0,0.45);
  font-family: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 4px 6px;
  outline: none;
  cursor: pointer;
}
#gui button {
  width: 100%;
  height: 22px;
  background: rgba(255,255,255,0.7);
  color: #000;
  border: 1px solid rgba(0,0,0,0.55);
  font-family: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  padding: 0 6px;
  cursor: pointer;
  outline: none;
  transition: background 0.12s ease;
}
#gui button:hover { background: rgba(0,0,0,0.08); }
#gui button.on {
  background: #000;
  color: #fff;
  border-color: #000;
}

/* ---------- start overlay ---------- */
#startOverlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#startOverlay.hidden { display: none; }
#startBtn {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 18px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: #000;
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.7);
  padding: 14px 32px;
  cursor: pointer;
  outline: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
#startBtn:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: #000;
}
#startMsg {
  color: rgba(0,0,0,0.6);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

@media (max-width: 768px) {
  .hud.tl, .hud.bl, .hud.br { display: none !important; }

  #gui {
    top: 14px;
    right: 14px;
    width: min(300px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    font-size: 11px;
  }
  /* When collapsed, shrink to fit the header so it doesn't cover the title */
  #gui.collapsed { width: auto; }

  #guiHeader { padding: 12px 14px; font-size: 11px; }
  #guiBody { padding: 12px 12px 14px; }

  #gui h4 { font-size: 11px; padding-bottom: 8px; margin-bottom: 12px; }

  #gui .row {
    grid-template-columns: 64px 1fr 40px;
    gap: 10px;
    margin-bottom: 12px;
  }

  #gui input[type="range"] { height: 2px; }
  #gui input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; }
  #gui input[type="range"]::-moz-range-thumb    { width: 18px; height: 18px; }

  #gui select { padding: 7px 8px; font-size: 11px; }
  #gui button { height: 32px; font-size: 11px; }
}

/* very small screens: stack rows vertically */
@media (max-width: 380px) {
  #gui .row {
    grid-template-columns: 1fr 44px;
    grid-template-areas:
      "label value"
      "input input";
    row-gap: 4px;
  }
  #gui .row label { grid-area: label; }
  #gui .row .val { grid-area: value; }
  #gui .row input,
  #gui .row select,
  #gui .row button { grid-area: input; width: 100%; }
}
