:root {
  --bg: #000;
  --fg: #fff;
  --muted: rgba(255, 255, 255, 0.7);
  --shield: rgba(0, 0, 0, 0.9);
  --focus: rgba(255, 255, 255, 0.9);
  --container-border: rgba(255, 255, 255, 0.85);
  --container-border-width: 1px;
  --topbar-h: clamp(84px, 9vh, 110px);
  --topbar-w: min(90ch, calc(100vw - 2rem));
  color-scheme: dark;
}

[data-mode='light'] {
  --bg: #fff;
  --fg: #000;
  --muted: rgba(0, 0, 0, 0.68);
  --shield: rgba(255, 255, 255, 0.92);
  --focus: rgba(0, 0, 0, 0.9);
  --container-border: rgba(0, 0, 0, 0.85);
  color-scheme: light;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    'Segoe UI', sans-serif;
  line-height: 1.45;
  letter-spacing: 0.01em;
  transition: background-color 320ms ease, color 320ms ease;
}

body.controls-open {
  overflow: hidden;
}

.header,
.noscript,
.controls-panel,
.shield {
  transition: background-color 320ms ease, border-color 320ms ease, filter 320ms ease;
}

.theme-button,
.restart-controls,
.pause-controls,
.gravity-drop,
.export-image,
.cta {
  transition: background-color 320ms ease, color 320ms ease, border-color 320ms ease, filter 320ms ease;
}

.toggle-switch,
.help {
  transition: border-color 320ms ease, color 320ms ease, background-color 320ms ease;
}

.toggle-switch::after {
  transition: transform 140ms linear, background-color 320ms ease;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.noscript {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  max-width: 46ch;
  padding: 0.75rem 0.9rem;
  background: var(--shield);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
  color: var(--muted);
  z-index: 9;
}

[data-mode='light'] .noscript {
  border-color: rgba(0, 0, 0, 0.08);
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--fg);
  color: var(--bg);
  border-radius: 0.4rem;
  transform: translateY(-200%);
  transition: transform 120ms linear;
  z-index: 10;
}

.skip-link:focus {
  transform: translateY(0);
  outline: none;
}

#dotfield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.page {
  position: relative;
  z-index: 2;
  min-height: 100%;
}

.header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 0.75rem clamp(1rem, 5vw, 3rem);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.controls-panel {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 4;
  box-sizing: border-box;
  padding: 0.75rem 0.85rem;
  border-radius: 1rem;
  border: var(--container-border-width) solid var(--container-border);
  background: var(--shield);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.controls-panel {
  opacity: 1;
  transform: none;
}

.controls-panel-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  left: 0;
  margin: -0.75rem -0.85rem 0.75rem -0.85rem;
  padding: 0.85rem 0.85rem 0.75rem 0.85rem;
  background: var(--shield);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 1;
}

.sheet-handle {
  display: none;
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 10px;
}

[data-mode='light'] .sheet-handle {
  background: rgba(0, 0, 0, 0.18);
}

[data-mode='light'] .controls-panel-header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

.controls-panel-title {
  margin: 0;
}

.controls-close {
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 40px;
}

.controls-close:hover,
.controls-close:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.controls-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3;
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

[data-mode='light'] .controls-backdrop {
  background: rgba(0, 0, 0, 0.26);
}

.controls-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.hero .controls-panel {
  max-width: none;
  width: auto;
}

.controls-panel .theme-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.controls-panel .presets-title {
  margin: 0 0 0.6rem 0;
}

.controls-panel .settings-title {
  margin: 0 0 0.6rem 0;
}

.theme-button {
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  border-radius: 0.85rem;
  padding: 0.45rem 0.55rem;
  min-height: 34px;
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.1;
}

.theme-button:hover,
.theme-button:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.theme-button.is-active {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}

.theme-button.is-active:hover,
.theme-button.is-active:focus-visible {
  color: var(--bg);
  filter: brightness(0.92);
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 44px;
}

.controls {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.9rem;
}

.controls-panel .controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem 1.2rem;
  align-items: start;
  min-width: 0;
}

.controls-panel .toggle-group,
.controls-panel .button-group {
  grid-column: 1 / -1;
  display: grid;
  gap: 0.9rem 1.2rem;
  align-items: start;
  min-width: 0;
}

.controls-panel .toggle-group {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.controls-panel .button-group {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.controls-panel .control-input {
  width: 100%;
  max-width: 260px;
  min-width: 0;
}

.controls-panel .button-group > button {
  width: 100%;
  justify-content: center;
}

@media (max-width: 980px) {
  .controls-panel .theme-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .controls-panel .controls {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

@media (max-width: 640px) {
  .controls {
    gap: 0.85rem;
  }

  .controls-panel .controls {
    gap: 0.85rem;
  }

  .control {
    width: 100%;
  }

  .controls-panel .control-input {
    max-width: none;
  }

  .section {
    padding: clamp(3rem, 8svh, 6rem) max(1rem, env(safe-area-inset-left)) clamp(4rem, 10svh, 7rem)
      max(1rem, env(safe-area-inset-right));
  }

  .shield {
    padding: 1.05rem 1.05rem;
  }

  .controls-panel {
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    top: auto;
    bottom: max(1rem, env(safe-area-inset-bottom));
    width: auto !important;
    max-height: min(calc(100vh - 2rem), 78vh);
    border-radius: 1.1rem;
    opacity: 0;
    transform: translateY(14px);
    pointer-events: none;
    transition: transform 220ms ease, opacity 220ms ease, background-color 320ms ease, border-color 320ms ease,
      filter 320ms ease;
  }

  .controls-panel.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .controls-panel-header {
    display: flex;
  }

  .sheet-handle {
    display: block;
  }

  .controls-panel .theme-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls-panel .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls-panel .toggle-group {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .controls-panel .button-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Center FREEZE on its own row. */
  .controls-panel .button-group > .pause-controls {
    grid-column: 1 / -1;
    justify-self: center;
    width: auto;
    min-width: min(260px, 75%);
  }

  .theme-button {
    min-height: 44px;
  }

  .help {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.9rem;
  }

  .toggle-row {
    width: 2.75rem;
    height: 1.55rem;
  }

  .toggle-switch::after {
    width: 1.15rem;
    height: 1.15rem;
  }

  .toggle-row input:checked + .toggle-switch::after {
    transform: translate(1.25rem, -50%);
  }
}

@media (max-width: 900px) and (max-height: 520px) {
  .controls-panel {
    max-height: calc(100vh - 1.25rem);
  }

  .hero {
    min-height: auto;
    padding-top: 3rem;
    padding-bottom: 3rem;
  }
}

@supports (height: 100dvh) {
  .controls-panel {
    max-height: calc(100dvh - 2rem);
  }

  @media (max-width: 640px) {
    .controls-panel {
      max-height: min(calc(100dvh - 2rem), 78dvh);
    }
  }
}

.reset-controls,
.restart-controls,
.pause-controls,
.gravity-drop {
  align-self: center;
}

.toggle-row {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 1.25rem;
}

.toggle-row input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.toggle-switch {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  border: 1px solid var(--muted);
  position: relative;
  flex: 0 0 auto;
  pointer-events: none;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  background: var(--muted);
  border-radius: 999px;
  transform: translateY(-50%);
  transition: transform 140ms linear, background-color 140ms linear;
}

.toggle-row input:checked + .toggle-switch {
  border-color: var(--fg);
}

.toggle-row input:checked + .toggle-switch::after {
  background: var(--fg);
  transform: translate(1.0rem, -50%);
}

.toggle-row:focus-within .toggle-switch {
  border-color: var(--fg);
}

.control {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  user-select: none;
  transition: color 320ms ease;
  min-width: 0;
}

.control.toggle {
  align-items: center;
}

.control.grouped {
  gap: 0.5rem;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--muted);
  border-radius: 999px;
  overflow: hidden;
}

.segmented-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

.segmented-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-option span {
  font-size: 0.85rem;
}

.segmented-option:has(input:checked) {
  background: var(--fg);
  color: var(--bg);
}

.segmented:has(.segmented-option input:focus-visible) {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

[aria-disabled='true'] {
  opacity: 0.5;
  pointer-events: none;
}

.control-label {
  line-height: 1.1;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.help {
  width: 1.15rem;
  height: 1.15rem;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0;
  cursor: help;
}

.help:hover,
.help:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.control-input {
  width: min(220px, 40vw);
  accent-color: var(--fg);
}

.control-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  line-height: 1.1;
}

.brand {
  color: var(--fg);
  text-decoration: none;
  font-weight: 550;
  letter-spacing: 0.02em;
  transition: color 320ms ease;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 320ms ease;
}

.nav a:hover,
.nav a:focus-visible {
  color: var(--fg);
}

.reset-controls,
.restart-controls,
.pause-controls {
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}

.gravity-drop {
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}

.export-image {
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-radius: 0.85rem;
  cursor: pointer;
  grid-column: 1 / -1;
}

.gravity-drop:hover,
.gravity-drop:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.reset-controls:hover,
.reset-controls:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.restart-controls:hover,
.restart-controls:focus-visible,
.pause-controls:hover,
.pause-controls:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.export-image:hover,
.export-image:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.pause-controls[aria-pressed='true'] {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}

.pause-controls[aria-pressed='true']:hover,
.pause-controls[aria-pressed='true']:focus-visible {
  color: var(--bg);
  filter: brightness(0.92);
}

.content {
  outline: none;
}

.section {
  padding: clamp(4rem, 10vh, 8rem) clamp(1rem, 5vw, 3rem);
  display: grid;
  justify-items: start;
}

.hero {
  min-height: clamp(520px, 92vh, 860px);
  align-content: center;
  gap: 1.4rem;
  position: relative;
}

@supports (height: 100svh) {
  .hero {
    min-height: clamp(520px, 92svh, 860px);
  }
}

.copy {
  max-width: 60ch;
  width: min(60ch, 100%);
}

.shield {
  background: var(--shield);
  border: var(--container-border-width) solid var(--container-border);
  border-radius: 0.9rem;
  padding: 1.25rem 1.25rem;
  box-sizing: border-box;
}

.cta.cta-muted {
  border-color: var(--muted);
  color: var(--muted);
}

.cta.cta-muted:hover,
.cta.cta-muted:focus-visible {
  border-color: var(--fg);
  color: var(--fg);
}

.show-hero {
  position: fixed;
  left: max(1rem, env(safe-area-inset-left));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 6;
  background: var(--shield);
  border-color: var(--container-border);
  color: var(--fg);
}

[data-mode='light'] .show-hero {
  background: var(--shield);
  border-color: var(--container-border);
}

@media (min-width: 641px) {
  #hideHero,
  #showHero {
    display: none;
  }
}

.eyebrow {
  margin: 0 0 0.6rem 0;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
  transition: color 320ms ease;
}

h1 {
  margin: 0 0 0.9rem 0;
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  font-weight: 550;
  letter-spacing: -0.02em;
  line-height: 1.1;
  transition: color 320ms ease;
}

h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.4rem;
  font-weight: 550;
  letter-spacing: -0.01em;
  transition: color 320ms ease;
}

p {
  margin: 0.6rem 0;
  color: var(--muted);
  transition: color 320ms ease;
}

.lede {
  font-size: 1.05rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 1rem;
}

.cta,
.secondary,
.text-link {
  color: var(--fg);
  text-decoration: none;
}

.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0.95rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

[data-mode='light'] .cta {
  border-color: rgba(0, 0, 0, 0.22);
}

.cta.is-active {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.cta.is-active:hover,
.cta.is-active:focus-visible {
  color: var(--bg);
  filter: brightness(0.92);
}

.cta:hover,
.cta:focus-visible,
.secondary:hover,
.secondary:focus-visible,
.text-link:hover,
.text-link:focus-visible {
  color: var(--focus);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }

  .skip-link {
    transition: none;
  }
}
