:root {
  --paper: #f7f3ec;
  --paper-light: #fbf8f2;
  --paper-deep: #f2ecdf;
  --ink: #3a3228;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120vmax 90vmax at 50% 44%, var(--paper-light) 0%, rgba(251, 248, 242, 0) 58%),
    radial-gradient(140% 120% at 50% 50%, rgba(120, 100, 72, 0) 62%, rgba(120, 100, 72, 0.06) 100%),
    linear-gradient(180deg, #faf6ef 0%, var(--paper-deep) 100%);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(58vmax 58vmax at 50% 46%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 62%);
  animation: room-light 14s ease-in-out infinite;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23grain)' opacity='0.05'/%3E%3C/svg%3E");
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.settings-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 21;
  padding: 7px 9px;
  border: 1px solid rgba(58, 50, 40, 0.22);
  border-radius: 2px;
  background: var(--paper-light);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
}

.settings-toggle:hover,
.settings-toggle[aria-expanded="true"] {
  border-color: rgba(58, 50, 40, 0.42);
  background: var(--paper-light);
}

.settings-toggle:focus-visible,
.settings-close:focus-visible,
.settings-panel input:focus-visible,
.settings-panel select:focus-visible {
  outline: 1px solid rgba(58, 50, 40, 0.55);
  outline-offset: 2px;
}

.settings-panel {
  position: fixed;
  top: 54px;
  right: 16px;
  z-index: 20;
  width: min(280px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid rgba(58, 50, 40, 0.22);
  border-radius: 2px;
  background: #fbf8f2;
  box-shadow: 0 14px 34px rgba(40, 33, 24, 0.16);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  max-height: calc(100vh - 70px);
  max-height: calc(100dvh - 76px);
  overflow-y: auto;
  overscroll-behavior: contain;
  isolation: isolate;
}

.settings-panel[hidden] {
  display: none;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.settings-header h2 {
  margin: 0;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.settings-group + .settings-group {
  margin-top: 15px;
  padding-top: 13px;
  border-top: 1px solid rgba(58, 50, 40, 0.14);
}

.settings-group h3 {
  margin: 0 0 9px;
  color: rgba(58, 50, 40, 0.58);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.settings-close {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.setting {
  display: grid;
  gap: 4px;
}

.setting + .setting {
  margin-top: 11px;
}

.setting > span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.setting output {
  color: rgba(58, 50, 40, 0.62);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
}

.setting input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.setting-check {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.setting-check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.setting select {
  width: 100%;
  padding: 4px 5px;
  border: 1px solid rgba(58, 50, 40, 0.22);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font: inherit;
}

@media (max-width: 480px) {
  .settings-toggle {
    top: 10px;
    right: 10px;
  }

  .settings-panel {
    top: 46px;
    right: 10px;
    left: 10px;
    width: auto;
  }
}

@keyframes room-light {
  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 0.9;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage::before {
    animation: none;
  }
}
