:root {
  /* Set from app.js. Black until then, so a dimmed light never flashes white on load. */
  --light: #000;
  --fade: 0ms;
  --accent: #fff;
  --on-accent: #1f1d1a;

  --glass: rgb(31 29 26 / 0.8);
  --ink: #f4f0e8;
  --ink-2: rgb(244 240 232 / 0.62);
  --well: rgb(244 240 232 / 0.09);
  --well-hover: rgb(244 240 232 / 0.16);
  --hairline: rgb(244 240 232 / 0.12);
  --gutter: 16px;

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  background-color: var(--light);
  transition: background-color var(--fade) ease-out;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- The light ---------- */

.stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}

body.idle .stage {
  cursor: none;
}

.softbox {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(farthest-corner at 50% 45%,
      transparent 18%,
      rgb(0 0 0 / 0.22) 55%,
      rgb(0 0 0 / 0.62) 100%);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.softbox.on {
  opacity: 1;
}

.mirror {
  position: absolute;
  left: 50%;
  top: 45%;
  width: min(56vmin, 420px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  clip-path: circle(50%);
  background: #000;
  pointer-events: none;
}

.mirror video,
.mirror canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.mirror video {
  object-fit: cover;
  transform: scaleX(-1);
}

/* The back camera shows the world as it is, not mirrored. */
.mirror.rear video {
  transform: none;
}

/* ---------- Readout ---------- */

.hud {
  position: fixed;
  /* Inset on both sides plus auto margins centers it without capping its width at half the screen. */
  left: var(--gutter);
  right: var(--gutter);
  top: max(24px, env(safe-area-inset-top));
  z-index: 3;
  width: fit-content;
  margin-inline: auto;
  padding: 9px 18px;
  border-radius: 20px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.hud.visible {
  opacity: 1;
  transform: none;
}

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

.panel {
  position: fixed;
  left: 50%;
  bottom: max(var(--gutter), env(safe-area-inset-bottom));
  width: min(440px, calc(100% - 2 * var(--gutter) - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: calc(100% - 2 * var(--gutter) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  /* One size in every mode: the tallest of them, measured by app.js, so switching never resizes it. */
  min-height: min(var(--panel-height, 0px), calc(100% - 2 * var(--gutter) - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
  --pad: 18px;
  padding: 16px var(--pad) 14px;
  border-radius: 26px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
  box-shadow: inset 0 0 0 1px var(--hairline), 0 24px 64px rgb(0 0 0 / 0.35);
  touch-action: manipulation;
  transform: translate(-50%, 0);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0s;
}

.panel:not(.visible) {
  opacity: 0;
  visibility: hidden;
  /* Let touches reach the light while the panel fades out. */
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}

/* Zero specificity, so component rules below override it. */
:where(.panel, .rec-bar, .saved, .install) button {
  appearance: none;
  border: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:where(.panel, .rec-bar, .saved, .install) button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 8px;
  margin-bottom: 16px;
}

/* Light or Studio. Fills the row on phones; the tools wrap below when they don't fit. */
.modes {
  display: flex;
  flex: 1 1 auto;
  max-width: 320px;
  padding: 3px;
  border-radius: 999px;
  background: var(--well);
}

.mode {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink-2);
}

.mode[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

/* Each control lists the modes it belongs to; the rest are hidden. */
.panel[data-mode="light"] [data-modes]:not([data-modes~="light"]),
.panel[data-mode="studio"] [data-modes]:not([data-modes~="studio"]) {
  display: none !important;
}

/* In Studio, temperature, color and presets fold under the Light heading. */
.panel[data-mode="studio"] .light-more:not(.open) {
  display: none;
}

/* While app.js measures the modes, each shows everything it can, folds aside. */
.panel.measuring[data-mode="light"] .control[data-light-only] {
  display: grid !important;
}

.panel.measuring[data-mode="studio"] #fx-body {
  display: block !important;
}

/* Whatever is shorter than the panel, recording sits at its bottom in Studio (and the hint in Light). */
.panel-side {
  margin-top: auto;
}

/* White or colored light. */
.kinds {
  display: inline-flex;
  justify-self: start;
  padding: 2px;
  border-radius: 999px;
  background: var(--well);
}

.kind {
  padding: 4px 11px;
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.kind[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.tools {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.tool {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--well);
}

.tool svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) {
  .tool:hover,
  .preset:hover,
  .chip:hover {
    background: var(--well-hover);
  }
}

.tool[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

/* ---------- Sliders ---------- */

.control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  row-gap: 4px;
  margin-bottom: 10px;
}

.control label {
  font-size: 14px;
  color: var(--ink-2);
}

.control output {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.control input {
  grid-column: 1 / -1;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 14px;
  border-radius: 999px;
  background: var(--track, var(--well));
  box-shadow: inset 0 0 0 1px var(--hairline);
}

input[type="range"]::-moz-range-track {
  height: 14px;
  border-radius: 999px;
  background: var(--track, var(--well));
  box-shadow: inset 0 0 0 1px var(--hairline);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 26px;
  height: 26px;
  margin-top: -6px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--thumb, #fff);
  box-shadow: 0 1px 5px rgb(0 0 0 / 0.5);
}

input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: 26px;
  height: 26px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--thumb, #fff);
  box-shadow: 0 1px 5px rgb(0 0 0 / 0.5);
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 2px var(--glass), 0 0 0 4px var(--ink);
}

input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 2px var(--glass), 0 0 0 4px var(--ink);
}

/* ---------- Presets ---------- */

.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 16px 0 12px;
}

.preset {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: 12px;
  background: var(--well);
  font-size: 13px;
  font-weight: 500;
}

.preset[aria-pressed="true"] {
  box-shadow: inset 0 0 0 2px var(--ink);
}

.preset-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--swatch, transparent);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.3);
}

.slot:not(.filled) {
  color: var(--ink-2);
}

.slot:not(.filled) .swatch {
  box-shadow: none;
  border: 1.5px dashed var(--ink-2);
}

/* ---------- Sections: camera effects, DJ sync, recording ---------- */

.section {
  margin-bottom: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.section-head svg {
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

label.section-title {
  cursor: pointer;
}

.section-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  margin-left: auto;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: var(--well);
  font-size: 13px;
  font-weight: 600;
}

.section-action svg {
  width: 16px;
  height: 16px;
}

@media (hover: hover) {
  .section-action:hover {
    background: var(--well-hover);
  }
}

.section-toggle {
  width: 100%;
  padding: 0;
  background: transparent;
  text-align: left;
}

.section-toggle .chevron {
  margin-left: auto;
  color: var(--ink-2);
  transition: transform 0.2s ease;
}

.section-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.section-value {
  margin-left: auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.section-value + .chevron {
  margin-left: 0;
}

.section-body {
  margin-top: 12px;
}

.section-note {
  margin: 8px 0 6px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-2);
}

.section-note strong {
  font-weight: 600;
  color: var(--ink);
}

/* One row that scrolls sideways, edge to edge. Wide screens wrap instead. */
.chips {
  display: flex;
  gap: 6px;
  /* Room for focus rings, which the scroll box would otherwise clip. */
  margin: -3px calc(-1 * var(--pad));
  padding: 3px var(--pad);
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--well);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.dj-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.beat {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.2;
}

/* While DJ sync listens, the tempo takes the name's place; the name stays for screen readers. */
.dj-section.on .dj-name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The pattern's name opens the patterns and the sensitivity. */
.dj-toggle .chevron {
  margin-left: -2px;
  transition: transform 0.2s ease;
}

.dj-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.dj-body:not(.open) {
  display: none;
}

.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin-left: auto;
  border-radius: 999px;
  background: var(--well-hover);
  transition: background-color 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.switch[aria-checked="true"] {
  background: var(--accent);
}

.switch[aria-checked="true"]::after {
  background: var(--on-accent);
  transform: translateX(18px);
}

/* A section action (Switch camera) sits next to the switch, not between it and the title. */
.section-action:not([hidden]) + .switch {
  margin-left: 0;
}

/* ---------- Recording ---------- */

.shape {
  flex: none;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.rec-options {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.rec-sound {
  margin-left: auto;
  font-size: 14px;
  color: var(--ink-2);
  cursor: pointer;
}

.rec-sound + .switch {
  margin-left: 0;
}

.rec-start {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 18px 0 15px;
  border-radius: 999px;
  background: var(--ink);
  font-weight: 600;
  color: #1f1d1a;
}

/* Shape, quality and sound, summed up next to the Record button; tap to change them. */
.rec-toggle {
  display: inline-flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 6px;
  width: auto;
  min-width: 0;
  height: 40px;
  padding-left: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.rec-summary {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rec-body:not(.open) {
  display: none;
}

.rec-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  /* The universal "recording" red. */
  background: #ff3b30;
}

.crop-guide {
  position: absolute;
  border-radius: 6px;
  pointer-events: none;
  /* While choosing a shape, dim what won't be recorded. */
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.45), inset 0 0 0 1px rgb(255 255 255 / 0.75), 0 0 0 100vmax rgb(0 0 0 / 0.3);
}

/* While recording, only outline the frame: the area outside still lights you. */
.crop-guide.recording {
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.45), inset 0 0 0 1px rgb(255 255 255 / 0.75);
}

.rec-bar,
.saved {
  position: fixed;
  z-index: 2;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: max(var(--gutter), env(safe-area-inset-left));
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: inset 0 0 0 1px var(--hairline), 0 12px 40px rgb(0 0 0 / 0.3);
}

.rec-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 5px 5px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rec-bar .rec-dot {
  animation: rec-blink 1.2s steps(1) infinite;
}

@keyframes rec-blink {
  50% {
    opacity: 0.25;
  }
}

.rec-bar button,
.saved-actions button {
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--well-hover);
  font-size: 13px;
  font-weight: 600;
}

.saved {
  max-width: min(420px, calc(100% - 2 * var(--gutter)));
  padding: 12px 14px;
  border-radius: 18px;
}

.saved p {
  margin: 0 0 10px;
  font-size: 14px;
}

.saved p span {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.saved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.saved-actions .primary {
  background: var(--ink);
  color: #1f1d1a;
}

/* ---------- Add to Home Screen, on iPhone ---------- */

.install {
  width: min(400px, calc(100% - 2 * var(--gutter)));
  max-width: none;
  max-height: calc(100% - 2 * var(--gutter) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
  box-shadow: inset 0 0 0 1px var(--hairline), 0 24px 64px rgb(0 0 0 / 0.35);
  color: var(--ink);
  overscroll-behavior: contain;
}

.install::backdrop {
  background: rgb(0 0 0 / 0.35);
}

.install-card {
  padding: 22px 20px 18px;
}

.install h2 {
  margin: 0 0 8px;
  font-size: 19px;
  line-height: 1.25;
}

.install p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-2);
}

.install ol {
  display: grid;
  gap: 12px;
  margin: 18px 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  font-size: 15px;
  line-height: 1.45;
}

.install li {
  display: grid;
  grid-template-columns: 26px 1fr;
  column-gap: 12px;
  counter-increment: step;
}

.install li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  height: 26px;
  border-radius: 50%;
  background: var(--well-hover);
  font-size: 13px;
  font-weight: 600;
}

.glyph {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-inline: 1px;
  vertical-align: -3px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.install .install-note {
  font-size: 12.5px;
}

.install-close {
  width: 100%;
  height: 46px;
  margin-top: 16px;
  border-radius: 14px;
  background: var(--ink);
  font-weight: 600;
  color: #1f1d1a;
}

/* ---------- Hints ---------- */

.hint {
  margin: auto 0 0; /* At the bottom of the panel, whatever is left over. */
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin-top: 6px;
}

.keys > span {
  white-space: nowrap;
}

kbd {
  display: inline-block;
  min-width: 1.7em;
  margin-right: 2px;
  padding: 0 0.35em;
  border-radius: 5px;
  background: var(--well);
  box-shadow: inset 0 -1px 0 var(--hairline);
  font: inherit;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
}

.hint-keys {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .hint-keys {
    display: block;
  }

  .hint-touch {
    display: none;
  }
}

/* ---------- The project, in the panel's bottom corner ---------- */

/* A finger-sized target around a small mark; its negative margins let the mark
   sit on the content's edges while the target reaches into the padding. */
.github {
  align-self: flex-end;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: 2px -8px -8px 0;
  border-radius: 50%;
  color: var(--ink-2);
}

.github svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

@media (hover: hover) {
  .github:hover {
    color: var(--ink);
  }
}

.github:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Wide screens have room for the chips to wrap. */
@media (min-width: 880px) {
  .chips {
    flex-wrap: wrap;
    margin-inline: 0;
    padding-inline: 0;
    overflow: visible;
  }
}

@media (max-width: 359px) {
  .panel {
    --pad: 14px;
  }

  .mode {
    padding-inline: 6px;
  }

  .preset {
    gap: 6px;
    padding-inline: 8px;
  }
}

/* Phones in landscape: keep as much of the light visible as possible. */
@media (max-height: 460px) {
  .panel {
    padding-block: 12px 10px;
  }

  .panel-head {
    margin-bottom: 8px;
  }

  .control {
    margin-bottom: 4px;
  }

  .presets {
    margin: 10px 0 2px;
  }

  .hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html,
  .softbox,
  .hud,
  .panel,
  .panel:not(.visible) {
    transition: none !important;
  }

  .rec-bar .rec-dot {
    animation: none;
  }
}
