:root {
  color-scheme: dark;
  font-family: Verdana, Arial, sans-serif;
  --unit: 44px;
  --half-unit: 22px;
  --rail-gap: 4px;
  --screen-width: 1536px;
  --screen-height: 768px;
  --footer-height: 24px;
  --app-width: 1632px;
  --app-height: 792px;
  --line: #d7d7d7;
  --muted-line: #777;
  --active: #b46900;
  --active-green: #39ff14;
  --active-orange: #ff9500;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  background: #000;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  overscroll-behavior: none;
}

@media (pointer: coarse) and (orientation: landscape) {
  body {
    padding-right: 44px;
    padding-left: 44px;
  }
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-stage {
  position: relative;
  width: var(--app-width);
  height: var(--app-height);
}

.sand-app {
  position: absolute;
  inset: 0 auto auto 0;
  width: var(--app-width);
  height: var(--app-height);
  overflow: visible;
  background: #000;
  transform-origin: top left;
  touch-action: none;
  user-select: none;
}

.control-rail,
.brush-rail {
  position: absolute;
  z-index: 5;
  top: 0;
  display: flex;
  width: var(--unit);
  height: var(--app-height);
  flex-direction: column;
  background: #000;
}

.control-rail {
  left: 0;
}

.brush-rail {
  right: 0;
}

.rail-button,
.grain-button {
  position: relative;
  width: var(--unit);
  height: var(--unit);
  min-height: var(--unit);
  margin: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: #fff;
  background: #000;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  cursor: pointer;
}

.brush-rail.edit-active .grain-button,
.brush-rail.edit-active .brush-size {
  border-color: #fff;
}

.brush-rail:not(.edit-active) .grain-button,
.brush-rail:not(.edit-active) .brush-size {
  border-color: #555;
  opacity: 0.38;
  pointer-events: none;
}

.brush-rail:not(.edit-active) .grain-button.selected {
  outline: 0;
}

.control-rail > .rail-button:first-child,
.brush-rail > .rail-button:first-child {
  border-top: 1px solid var(--line);
}

.rail-label + .rail-button,
.rail-label + .rail-picker > .rail-button {
  border-top: 1px solid var(--line);
}

.rail-button:hover,
.rail-button:focus-visible,
.grain-button:hover,
.grain-button:focus-visible,
.rail-button.is-selected,
.grain-button.selected {
  z-index: 1;
  outline: 2px solid #fff;
  outline-offset: -3px;
}

.rail-button:focus-visible,
.grain-button:focus-visible {
  background-color: var(--active);
}

.symbol-button {
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", Arial, sans-serif;
  font-size: 23px;
  line-height: var(--unit);
}

.text-button {
  font-size: 17px;
  line-height: var(--unit);
}

.control-icon {
  background-position: center;
  background-repeat: no-repeat;
  background-size: 44px 44px;
}

#auto {
  font-size: 12px;
}

#resolution,
#density-range {
  font-size: 19px;
}

.rail-label {
  display: flex;
  width: var(--unit);
  height: var(--half-unit);
  min-height: var(--half-unit);
  align-items: center;
  justify-content: center;
  color: #fff;
  background: #000;
  font: 12px/1 "Arial Narrow", "Liberation Sans Narrow", Arial, sans-serif;
}

.rail-picker {
  position: relative;
  width: var(--unit);
  height: var(--unit);
  min-height: var(--unit);
}

.preview-button {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.screen {
  position: absolute;
  z-index: 1;
  top: 0;
  left: calc(var(--unit) + var(--rail-gap));
  width: var(--screen-width);
  height: var(--app-height);
  overflow: hidden;
  background: #000;
}

.viewport {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--screen-width);
  height: var(--screen-height);
  overflow: hidden;
  transform-origin: center;
}

#sand-background,
#sand,
#brush-overlay,
.message-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--screen-width);
  height: var(--screen-height);
}

#sand-background {
  background: #fff;
  pointer-events: none;
}

#sand {
  z-index: 0;
  display: block;
  background: transparent;
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#sand.move-mode {
  cursor: move;
}

#brush-overlay {
  z-index: 1;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#sand.flip-animating,
#brush-overlay.flip-animating {
  transform-origin: 50% 50%;
  animation: sand-screen-flip 300ms cubic-bezier(0.45, 0, 0.55, 1) both;
  will-change: transform, filter;
}

@keyframes sand-screen-flip {
  0% { transform: perspective(1800px) rotateX(0deg); filter: brightness(1); }
  42% { transform: perspective(1800px) rotateX(75deg); filter: brightness(1.75); }
  50% { transform: perspective(1800px) rotateX(90deg); filter: brightness(2.2); }
  58% { transform: perspective(1800px) rotateX(105deg); filter: brightness(1.75); }
  100% { transform: perspective(1800px) rotateX(180deg); filter: brightness(1); }
}

.viewport.quiver-animating {
  animation: sand-viewport-quiver 140ms linear both;
  will-change: transform;
}

@keyframes sand-viewport-quiver {
  0%, 100% { transform: translate(0, 0); }
  16% { transform: translate(-2px, 1px); }
  32% { transform: translate(2px, -1px); }
  48% { transform: translate(-1px, -1px); }
  64% { transform: translate(2px, 1px); }
  80% { transform: translate(-1px, 0); }
}

.viewport.slap-animating {
  animation: sand-viewport-slap 300ms linear both;
  will-change: transform;
}

@keyframes sand-viewport-slap {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  7% { transform: translate(-9px, 4px) rotate(-0.18deg); }
  15% { transform: translate(8px, -4px) rotate(0.16deg); }
  24% { transform: translate(-7px, 3px) rotate(-0.13deg); }
  34% { transform: translate(6px, -3px) rotate(0.11deg); }
  45% { transform: translate(-4px, 2px) rotate(-0.08deg); }
  57% { transform: translate(3px, -2px) rotate(0.06deg); }
  70% { transform: translate(-2px, 1px) rotate(-0.04deg); }
  84% { transform: translate(1px, -1px) rotate(0.02deg); }
}

.message-layer {
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.screen-message {
  position: absolute;
  left: 12px;
  margin: 0;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 600;
  white-space: pre;
  text-rendering: optimizeLegibility;
  -webkit-text-stroke: 1.5px #000;
  paint-order: stroke fill;
  text-shadow: 0 0 2px #000, 0 0 3px #000, 0 0 5px #000, 0 0 8px #000, 0 0 11px #000;
}

.footerbar {
  position: absolute;
  z-index: 3;
  bottom: 0;
  left: 0;
  display: flex;
  width: var(--screen-width);
  height: var(--footer-height);
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 5px;
  overflow: hidden;
  color: #fff;
  background: #000;
  font: 13px/var(--footer-height) Verdana, Arial, sans-serif;
  white-space: nowrap;
}

.footer-link {
  color: #fff;
  text-decoration: none;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: #ffc46b;
  outline: none;
}

.privacy-note {
  color: #888;
}

.effective-fps-readout {
  display: inline-flex;
  flex: 0 0 7.5ch;
  width: 7.5ch;
  align-items: center;
  column-gap: 0.5ch;
}

.effective-fps-label {
  flex: 0 0 3ch;
  color: #aaa;
  text-align: right;
}

.effective-fps {
  flex: 0 0 4ch;
  width: 4ch;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.footer-year,
.footer-email-label {
  color: #aaa;
}

.footer-credits {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.quitaesto {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.grain-palette {
  display: flex;
  width: var(--unit);
  flex: 1 1 auto;
  flex-direction: column;
}

.grain-button {
  flex: 0 0 var(--unit);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font-size: 19px;
  line-height: var(--unit);
  text-shadow:
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000,
    0 0 4px #000,
    0 0 7px #000;
}

.brush-size {
  font-size: 18px;
}

.brush-size::before {
  position: absolute;
  inset: 5px;
  border: 1px solid currentColor;
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.flyout {
  position: absolute;
  z-index: 20;
  top: 0;
  left: calc(var(--unit) + var(--rail-gap));
  padding: 6px;
  border: 1px solid #fff;
  background: #000;
  box-shadow: 4px 4px 0 rgb(0 0 0 / 55%);
}

.flyout[hidden] {
  display: none;
}

.reset-menu {
  display: grid;
  width: auto;
  margin-left: 4px;
  padding: 0;
  border: 0;
  grid-template-columns: repeat(6, 90px);
  gap: 0;
  background: transparent;
  box-shadow: none;
}

.reset-option {
  position: relative;
  display: flex;
  width: 90px;
  min-width: 90px;
  height: 68px;
  margin: 0 0 0 -1px;
  padding: 0;
  border: 1px solid #fff;
  flex-direction: column;
  color: #fff;
  background: #000;
  cursor: pointer;
}

.reset-option:first-child,
.reset-option:nth-child(7) {
  margin-left: 0;
}

.reset-option:nth-child(n + 7) {
  grid-row: 2;
  margin-top: -1px;
}

.reset-option:nth-child(7) {
  grid-column: 1;
}

.reset-option::after {
  position: absolute;
  z-index: 5;
  inset: -1px;
  border: 2px solid transparent;
  content: "";
  pointer-events: none;
}

.reset-option-label {
  display: block;
  width: 88px;
  height: 22px;
  color: #888;
  font: 12px/21px Verdana, Arial, sans-serif;
  text-align: center;
  transition: color 120ms ease;
}

.reset-preview {
  display: block;
  width: 88px;
  height: 44px;
  image-rendering: pixelated;
}

.reset-option:hover,
.reset-option:focus-visible {
  z-index: 3;
  outline: none;
}

.reset-option:hover::after,
.reset-option:focus-visible::after {
  border-color: #fff;
}

.reset-option:hover .reset-option-label,
.reset-option:focus-visible .reset-option-label {
  color: #fff;
}

.reset-option.selected .reset-option-label {
  color: var(--active-green);
}

.density-menu {
  display: flex;
  width: auto;
  margin-left: 4px;
  padding: 0;
  border: 0;
  gap: 0;
  background: transparent;
  box-shadow: none;
}

.density-option {
  position: relative;
  width: var(--unit);
  height: var(--unit);
  min-width: var(--unit);
  margin: 0 0 0 -1px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 0;
  color: #fff;
  background: #000;
  font: 19px/var(--unit) Arial, sans-serif;
  text-align: center;
  cursor: pointer;
}

.density-option:first-child {
  margin-left: 0;
}

.density-option::after {
  position: absolute;
  z-index: 5;
  inset: -1px;
  border: 2px solid transparent;
  content: "";
  pointer-events: none;
}

.density-option:hover,
.density-option:focus-visible {
  z-index: 3;
  outline: none;
}

.density-option:hover::after,
.density-option:focus-visible::after {
  border-color: #fff;
}

.density-option.selected {
  color: var(--active-green);
}

.flyout-option {
  height: 34px;
  margin: 0;
  padding: 0 8px;
  border: 1px solid #fff;
  border-radius: 0;
  color: #fff;
  background: #000;
  font: 13px/32px Verdana, Arial, sans-serif;
  text-align: left;
  cursor: pointer;
}

.flyout-option:hover,
.flyout-option:focus-visible,
.flyout-option.selected {
  outline: 2px solid #fff;
  outline-offset: -3px;
}

.palette-menu,
.background-menu {
  display: flex;
  width: auto;
  margin-left: 4px;
  padding: 0;
  border: 0;
  flex-direction: column;
  gap: 0;
  background: transparent;
  box-shadow: none;
}

.palette-direction-control {
  font-size: 16px;
}

.palette-row,
.background-row {
  display: flex;
  width: max-content;
  margin-top: -1px;
  gap: 0;
}

.palette-option,
.background-option {
  position: relative;
  display: flex;
  width: 90px;
  min-width: 90px;
  height: 68px;
  margin: 0 0 0 -1px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 0;
  flex-direction: column;
  overflow: hidden;
  color: #fff;
  background: #000;
  cursor: pointer;
}

.palette-option:first-child,
.background-option:first-child {
  margin-left: 0;
}

.palette-option::after,
.background-option::after {
  position: absolute;
  z-index: 5;
  inset: -1px;
  border: 2px solid transparent;
  content: "";
  pointer-events: none;
}

.palette-option-label,
.background-option-label {
  display: block;
  width: 88px;
  height: 22px;
  color: #888;
  font: 12px/21px Verdana, Arial, sans-serif;
  text-align: center;
  transition: color 120ms ease;
  white-space: nowrap;
}

.palette-option-preview,
.background-option-preview {
  display: block;
  width: 88px;
  height: 44px;
  flex: 0 0 44px;
  background-position: center;
  background-size: cover;
}

.palette-option:hover,
.palette-option:focus-visible,
.background-option:hover,
.background-option:focus-visible {
  z-index: 3;
  outline: none;
}

.palette-option:hover::after,
.palette-option:focus-visible::after,
.background-option:hover::after,
.background-option:focus-visible::after {
  border-color: #fff;
}

.palette-option:hover .palette-option-label,
.palette-option:focus-visible .palette-option-label,
.background-option:hover .background-option-label,
.background-option:focus-visible .background-option-label {
  color: #fff;
}

.palette-option.selected .palette-option-label,
.background-option.selected .background-option-label {
  color: var(--active-green);
}

@media (prefers-reduced-motion: reduce) {
  #sand.flip-animating,
  #brush-overlay.flip-animating,
  .viewport.quiver-animating,
  .viewport.slap-animating {
    animation-duration: 1ms;
  }
}
