:root {
  --panel-w: 300px;
  --backdrop: #000000;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000000;
}

body[data-ui="off"] { --panel-w: 0px; }

/* Embedded, the backdrop fills the box round the stage too. */
body[data-embed] .view { background: var(--backdrop); }

/* Without WebGL 2 (webgl.js), a still of the wallpaper in its place. */
body[data-fallback] #wall { visibility: hidden; }
body[data-fallback] .stage { background: #000 url("media/pro.jpg") center / cover no-repeat; }

/* The space left of the panel; the stage is fitted into it. */
.view {
  position: fixed;
  inset: 0 var(--panel-w) 0 0;
  display: grid;
  place-items: center;
  container-type: size;
  background: #0b0c0e;
}

/* The chosen proportions (--ratio, width over height), as large as fits. */
.stage {
  --ratio: 1.5468;
  position: relative;
  width: min(100cqw, calc(100cqh * var(--ratio)));
  aspect-ratio: var(--ratio);
  background: var(--backdrop);
}

#wall {
  display: block;
  width: 100%;
  height: 100%;
}

/* The original, laid over the canvas for comparison (R toggles it). */
.reference {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}

body[data-reference] .reference { opacity: 1; z-index: 1; }

/* The settings, docked on the right. */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  box-sizing: border-box;
  padding: 12px;
  overflow-y: auto;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  background: #111215;
  scrollbar-width: thin;
  /* Keep room for the scrollbar, so folding the panel doesn't change its width. */
  scrollbar-gutter: stable;
}

body[data-ui="off"] .sidebar { display: none; }

/* Tweakpane, a little roomier and in the wallpaper's greys. */
.sidebar .tp-rotv {
  --tp-base-background-color: #1a1c21;
  --tp-container-background-color: rgba(255, 255, 255, 0.06);
  --tp-input-background-color: rgba(255, 255, 255, 0.07);
  --tp-label-foreground-color: #a8aebb;
  --tp-monitor-background-color: rgba(0, 0, 0, 0.35);
  --cnt-usz: 22px;
  font-size: 12px;
}

/* Phones: the scene on top, the settings in a sheet below it. */
@media (max-width: 720px) {
  :root {
    --panel-w: 0px;
    --sheet-h: min(56dvh, 520px);
  }

  body[data-ui="off"] { --sheet-h: 0px; }

  .view { inset: 0 0 var(--sheet-h) 0; }

  .sidebar {
    top: auto;
    left: 0;
    width: auto;
    height: var(--sheet-h);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 0;
    overscroll-behavior: contain;
  }
}

/* Fingers: taller rows, and text fields large enough that the page doesn't zoom in on them. */
@media (pointer: coarse) {
  .sidebar .tp-rotv { --cnt-usz: 30px; font-size: 13px; }
  .sidebar input { font-size: 16px; }
}
