/* R2 Lava Lamp — light study
   Dark studio layout, hand-built (no framework, no CDN, fully offline). */

:root {
  --ink: #f4effa;
  --muted: #a99cbe;
  --faint: #7b6f92;
  --line: rgba(255, 255, 255, 0.085);
  --line-strong: rgba(255, 255, 255, 0.16);
  --panel: rgba(22, 17, 34, 0.72);
  --purple: #b78cff;
  --amber: #ffb469;
  --radius: 20px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: #07050c;
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 40;
  padding: 10px 16px;
  border-radius: 10px;
  background: #f4effa;
  color: #120c1e;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 12px; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  min-height: 480px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 2.4vw, 30px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(14, 10, 22, 0.9), rgba(10, 7, 16, 0.55));
  backdrop-filter: blur(14px);
  z-index: 3;
}

.brand { display: flex; align-items: center; gap: 11px; }

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 46% 46% / 44% 44% 56% 56%;
  background: radial-gradient(60% 60% at 34% 30%, #d9bcff, #7f4fd0 58%, #331a5e);
  box-shadow: 0 0 18px rgba(150, 96, 255, 0.5), inset 0 1px 2px rgba(255, 255, 255, 0.5);
}

.brand-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
}
.brand-sub {
  display: block;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.pill {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ghost {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), transform 0.2s var(--ease);
}
.ghost:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.07); }
.ghost:active { transform: scale(0.97); }

/* ---------- main layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 27vw, 392px);
  min-height: 0;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #07050c;
}

#lamp {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: pan-y;
  outline: none;
}
#lamp:active { cursor: grabbing; }
#lamp:focus-visible { box-shadow: inset 0 0 0 2px rgba(183, 140, 255, 0.65); }

.stage-top {
  position: absolute;
  inset: 16px 18px auto auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  text-align: right;
}

.stage-label {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--faint);
}

.stage-quality {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  background: rgba(10, 7, 17, 0.5);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  max-width: 250px;
}

.stage-bottom {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  padding: 26px clamp(16px, 2.4vw, 30px) clamp(16px, 2vw, 22px);
  background: linear-gradient(0deg, rgba(6, 4, 11, 0.82), rgba(6, 4, 11, 0));
  pointer-events: none;
}

.now-playing { min-width: 0; }

.now-eyebrow {
  margin: 0 0 4px;
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
}

.now-title {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: clamp(22px, 2.5vw, 31px);
  font-weight: 400;
  letter-spacing: 0.005em;
  line-height: 1.05;
}

.loop {
  margin: 10px 0 8px;
  width: min(260px, 46vw);
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.loop span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.35), var(--amber));
  transition: background 0.6s var(--ease);
}

.now-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.now-meta span:last-child { color: var(--faint); font-variant-numeric: tabular-nums; }

.rotation-help {
  margin: 0;
  font-size: 11.5px;
  color: var(--faint);
  white-space: nowrap;
}
.rotation-help kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: inherit;
  font-size: 10.5px;
  text-align: center;
  color: var(--muted);
}

/* ---------- control rail ---------- */

.rail {
  min-height: 0;
  border-left: 1px solid var(--line);
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(120, 70, 210, 0.14), transparent 60%),
    linear-gradient(180deg, rgba(19, 14, 30, 0.96), rgba(11, 8, 18, 0.98));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  overscroll-behavior: contain;
}

.rail-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px clamp(16px, 1.8vw, 24px) 24px;
}

.block { display: flex; flex-direction: column; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.block:last-of-type { border-bottom: 0; padding-bottom: 0; }

.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.block-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
}
.block-note { margin: 0; font-size: 11px; color: var(--faint); }

.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 2px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}
.group-title span { letter-spacing: 0.06em; text-transform: none; color: rgba(255, 255, 255, 0.28); }

.scene-scroll {
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: min(28vh, 232px);
  padding-right: 4px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  overscroll-behavior: contain;
  mask-image: linear-gradient(180deg, #000 0, #000 calc(100% - 14px), transparent 100%);
}

.scene-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }

.scene-chip {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.022);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
.scene-chip:hover { border-color: var(--line-strong); color: var(--ink); background: rgba(255, 255, 255, 0.055); }
.scene-chip:active { transform: scale(0.985); }
.scene-chip[aria-pressed="true"] {
  border-color: rgba(196, 158, 255, 0.65);
  background: linear-gradient(180deg, rgba(160, 110, 255, 0.22), rgba(120, 80, 210, 0.1));
  color: #fff;
  box-shadow: 0 0 0 1px rgba(196, 158, 255, 0.18), 0 6px 18px -10px rgba(160, 110, 255, 0.9);
}

.chip-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot, #fff);
  box-shadow: 0 0 9px var(--dot, #fff), inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.row-label output { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 12px; }


.range {
  appearance: none;
  width: 100%;
  height: 22px;
  margin: -4px 0 0;
  background: none;
  cursor: pointer;
}
.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--purple) var(--fill, 50%), rgba(255, 255, 255, 0.13) var(--fill, 50%));
}
.range::-moz-range-track { height: 4px; border-radius: 3px; background: rgba(255, 255, 255, 0.13); }
.range::-moz-range-progress { height: 4px; border-radius: 3px; background: var(--purple); }
.range::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: #f7f2ff;
  box-shadow: 0 0 0 4px rgba(183, 140, 255, 0.16), 0 2px 8px rgba(0, 0, 0, 0.6);
}
.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: #f7f2ff;
  box-shadow: 0 0 0 4px rgba(183, 140, 255, 0.16);
}
.range:focus-visible { outline: 2px solid rgba(183, 140, 255, 0.8); outline-offset: 4px; border-radius: 6px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }

.button {
  appearance: none;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.15s var(--ease);
}
.button:hover { background: rgba(255, 255, 255, 0.1); }
.button:active { transform: scale(0.98); }
.button:focus-visible,
.ghost:focus-visible,
.reset:focus-visible,
.scene-chip:focus-visible,
.bg-chip:focus-visible,
.tint-chip:focus-visible,
.color-input:focus-visible,
summary:focus-visible {
  outline: 2px solid rgba(196, 158, 255, 0.9);
  outline-offset: 2px;
}
.button[aria-pressed="true"] {
  border-color: rgba(196, 158, 255, 0.6);
  background: linear-gradient(180deg, rgba(160, 110, 255, 0.3), rgba(120, 80, 210, 0.16));
}

.details summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.details summary::-webkit-details-marker { display: none; }
.details summary::before {
  content: "＋";
  margin-right: 8px;
  font-weight: 400;
  color: var(--purple);
}
.details[open] summary::before { content: "－"; }
.summary-note { flex: 1; text-align: right; font-weight: 400; letter-spacing: 0.05em; text-transform: none; color: var(--faint); }
.details[open] { gap: 10px; }
.details[open] summary { margin-bottom: 2px; }

.fineprint, .caption { margin: 0; font-size: 11px; line-height: 1.5; color: var(--faint); }

/* diffuser colour chips + native colour picker */
.tint-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.tint-chip {
  appearance: none;
  height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: var(--chip, #fff);
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.tint-chip:hover { transform: translateY(-1px); }
.tint-chip[aria-pressed="true"] {
  box-shadow: 0 0 0 2px rgba(196, 158, 255, 0.9), 0 0 14px rgba(196, 158, 255, 0.4);
}
.color-input {
  appearance: none;
  width: 100%;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 3px; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color-input::-moz-color-swatch { border: 0; border-radius: 6px; }
.tint-custom {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.tint-custom output { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 12px; }
.tint-custom .color-input { width: 62px; flex: 0 0 auto; height: 28px; margin-left: auto; }

/* selector reused for the wax-pattern picker */
.select {
  appearance: none;
  width: 100%;
  padding: 9px 34px 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 18px) 50% / 5px 5px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 13px) 50% / 5px 5px no-repeat,
    rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.select:hover { border-color: var(--line-strong); }
.select:focus-visible { outline: 2px solid rgba(196, 158, 255, 0.9); outline-offset: 2px; }

.bg-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.bg-chip {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.022);
  color: var(--muted);
  font: inherit;
  font-size: 10.5px;
  line-height: 1.15;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease), background 0.18s var(--ease);
}
.bg-chip i {
  display: block;
  height: 26px;
  border-radius: 7px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.bg-chip:hover { border-color: var(--line-strong); color: var(--ink); }
.bg-chip[aria-pressed="true"] { border-color: rgba(196, 158, 255, 0.6); color: #fff; background: rgba(160, 110, 255, 0.14); }

.switch { display: flex; align-items: flex-start; gap: 11px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  flex: 0 0 auto;
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.2s var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cfc3e4;
  transition: transform 0.22s var(--ease), background 0.22s var(--ease);
}
.switch input:checked + .switch-track { background: rgba(160, 110, 255, 0.55); }

/* ---------- dialog ---------- */

dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, #1a1428, #100b1b);
  color: var(--ink);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.9);
}
dialog::backdrop { background: rgba(4, 3, 8, 0.72); backdrop-filter: blur(6px); }
dialog form { display: flex; flex-direction: column; gap: 12px; padding: 26px clamp(20px, 4vw, 30px) 24px; }
dialog h2 {
  margin: 0 0 2px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 24px;
  font-weight: 400;
}
dialog p { margin: 0; font-size: 13px; line-height: 1.6; color: var(--muted); }
dialog code { font-size: 12px; color: var(--amber); }
.dialog-note { padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }
.dialog-close { align-self: flex-start; margin-top: 6px; }

.noscript {
  position: fixed;
  inset: auto 16px 16px 16px;
  margin: 0;
  padding: 14px 18px;
  border-radius: 12px;
  background: #2a1a2e;
  color: #ffd9c2;
  font-size: 13px;
}

/* ---------- responsive ---------- */

@media (max-width: 1040px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(300px, 340px); }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; grid-template-rows: auto auto; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(320px, 56dvh) auto; }
  .stage { min-height: 320px; }
  .rail {
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 24px 24px 0 0;
    margin-top: -18px;
    overflow: visible;
    background:
      radial-gradient(120% 40% at 50% 0%, rgba(120, 70, 210, 0.16), transparent 70%),
      linear-gradient(180deg, rgba(19, 14, 30, 0.99), rgba(11, 8, 18, 0.99));
  }
  .rail-inner { padding-bottom: 40px; }
  .scene-scroll { max-height: none; mask-image: none; overflow: visible; }
  .scene-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-bottom { padding-bottom: 30px; }
  .rotation-help { display: none; }
  .stage-quality { max-width: 180px; }
}

@media (max-width: 520px) {
  .topbar-actions .pill { display: none; }
  .now-title { font-size: 22px; }
  .loop { width: 100%; }
  .stage-bottom { flex-direction: column; align-items: flex-start; gap: 10px; }
  .bg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid rgba(183, 140, 255, 0.8); outline-offset: 3px; }
.switch-text { font-size: 12.5px; color: var(--muted); padding-top: 1px; }

.rail-foot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.reset {
  appearance: none;
  align-self: flex-start;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.reset:hover { color: var(--ink); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.05); }



/* ---------- diagnostics (not visible, used by local checks) ---------- */

.diag {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  font-size: 0;
}

/* ---------- clean mode (screenshots / deep-link study) ---------- */

body.clean .topbar,
body.clean .rail,
body.clean .stage-top,
body.clean .stage-bottom { display: none; }
body.clean .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100dvh; }
body.clean .app { height: 100dvh; grid-template-rows: minmax(0, 1fr); }
body.clean .stage { min-height: 0; }

/* ---------- graceful poster when WebGL2 is unavailable ---------- */

.stage.no-webgl {
  background:
    radial-gradient(60% 45% at 50% 45%, rgba(120, 80, 200, 0.20), transparent 70%),
    linear-gradient(180deg, #120d1e, #07050c);
}
.stage.no-webgl #lamp { display: none; }
.stage.no-webgl::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(28vw, 190px);
  height: min(64vh, 520px);
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg,
    #6c4499 0 12.5%,
    #efe8f7 12.5% 70%,
    #5e3a87 70% 100%);
  clip-path: polygon(33% 0, 67% 0, 71% 13%, 95.5% 70%, 100% 70%, 84% 86%,
    87% 100%, 13% 100%, 16% 86%, 0 70%, 4.5% 70%, 29% 13%);
  box-shadow: 0 0 90px rgba(150, 110, 255, 0.22);
}

.button:disabled,
.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

