html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}
body.shake {
  animation: shake 0.5s ease;
}
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, -6px); }
  20% { transform: translate(9px, 5px); }
  30% { transform: translate(-7px, 7px); }
  40% { transform: translate(8px, -8px); }
  50% { transform: translate(-9px, 4px); }
  60% { transform: translate(6px, -5px); }
  70% { transform: translate(-5px, 6px); }
  80% { transform: translate(5px, 5px); }
  90% { transform: translate(-3px, -3px); }
}
/* "TV frame" view: the whole scene (#screen) renders at full logical size
   as always, then gets visually perspective-warped (by app.js, via the
   measured screenCorners) to sit inside the CRT's screen in a real photo
   of a TV-on-a-cart. Off by default; #screen has no transform and the
   photo is hidden, so nothing here changes normal behavior. */
#tvStage {
  display: none;
}
#tvFrame.framed #tvStage {
  display: flex;
}
#tvStage {
  position: fixed;
  inset: 0;
  z-index: 1;
  align-items: center;
  justify-content: center;
  background: #000;
  pointer-events: none;
}
#tvPhotoWrap {
  position: relative;
  height: 92vh;
  aspect-ratio: 1095 / 1436;
}
#tvPhoto {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#screen {
  position: fixed;
  inset: 0;
  z-index: 2;
  transform-origin: 0 0;  
}
#trail {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
#bouncer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  will-change: transform;
}
#bouncer.hit {
  animation: wallHitPulse 0.18s ease-out;
}
@keyframes wallHitPulse {
  0% { filter: brightness(2.4); }
  100% { filter: brightness(1); }
}
#bouncer.text {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  font-style: italic;
  font-size: 128px;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 0 8px currentColor;
  user-select: none;
  white-space: nowrap;
}
#bouncer.photo .tint {
  display: block;
  max-width: 95vw;
  max-height: 95vh;
  background-color: var(--accent);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-position: center;
  mask-position: center;
  filter: drop-shadow(0 0 14px var(--accent));
  pointer-events: none;
}
#bouncer.photo .plainPhoto {
  display: block;
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  filter: drop-shadow(0 0 14px var(--accent));
  pointer-events: none;
}
#fx {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}
#flash {
  position: fixed;
  inset: 0;
  z-index: 7;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
#flash.active {
  animation: flashPulse 0.6s ease-out;
}
@keyframes flashPulse {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}
#cornerText {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 8;
  transform: translate(-50%, -50%) scale(0.3);
  opacity: 0;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  font-style: italic;
  font-size: 56px;
  color: #fff;
  text-shadow: 0 0 18px currentColor, 0 0 40px currentColor;
  letter-spacing: 1px;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
#cornerText.active {
  animation: cornerPop 1.6s ease-out;
}
@keyframes cornerPop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  25% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* CRT overlay: scanlines + vignette, opacity-scaled by --crt-intensity
   (set by app.js from the slider). Sits above everything else so it reads
   as a screen effect, not part of the scene - which is also why it lives
   in index.html as a sibling of #screen rather than inside it: #screen
   gets warped by a matrix3d transform in TV-frame mode, and a `position:
   fixed` descendant of a transformed element is positioned/painted
   relative to *that* element instead of the real viewport. Nesting this
   inside #screen used to drag its vh/vmax-sized scanlines and vignette
   through the same perspective warp, crushing them into a moire mess
   instead of a flat effect over the whole page. */
#crtOverlay {
  position: fixed;
  inset: 0;
  /* Below the HUD (#controls/#countdown are z-index 10) so the settings
     menu reads clearly and doesn't get scanlines/vignette over it. */
  z-index: 9;
  pointer-events: none;
  opacity: var(--crt-intensity, 0);
  /* Scanline period is set in vh, not px, so line density looks the same
     at 1080p and at 4K instead of turning into near-invisible hairlines or
     shimmer on very tall viewports. */
  background-image:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.35) 0%,
      rgba(0, 0, 0, 0.35) 50%,
      transparent 50%,
      transparent 100%
    ),
    radial-gradient(ellipse 80% 80% at center, transparent 55%, rgba(0, 0, 0, 0.97) 100%);
  background-size: 100% 0.45vh, 100% 100%;
  /* A curved-tube screen: rounding the overlay's own corners, then a huge
     box-shadow spread fills in the rounded-off corners with solid black -
     the classic "picture doesn't reach the corner" old-TV look - plus an
     inset shadow for the softer bulge along the edges. */
  border-radius: 2.5vmin / 5vmin;
  box-shadow:
    0 0 0 100vmax #000,
    inset 0 0 8vmax 2vmax rgba(0, 0, 0, 0.8);
}
#crtOverlay[hidden] {
  display: none;
}

/* Old TV/VCR-style on-screen badge (channel number, input label) in the
   corner of a "no signal"-looking classic CRT idle screen. */
#bgBadge {
  position: fixed;
  top: 3vh;
  right: 4vw;
  z-index: 2;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  /* Real 90s TV channel OSDs were never spec'd to an exact ratio (it was
     manufacturer-specific), but the digits were consistently huge - on the
     order of 1/10 to 1/8 of the screen height. Sized in vh, not px, so
     that holds true on any display instead of looking tiny on a big one. */
  font-size: 11vh;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #2ee62e;
  text-shadow: 0 0 0.6vh rgba(46, 230, 46, 0.8), 0 0 1.6vh rgba(46, 230, 46, 0.5);
  pointer-events: none;
}
#bgBadge[hidden] {
  display: none;
}
/* The classic green phosphor glow reads as noise against the 90s "no
   signal" blue, which real tuner OSDs rendered in a plain light-grey
   instead - so swap to that grey on that background specifically. Keep
   a (colorless) soft glow rather than dropping the shadow entirely: in
   TV-frame mode this badge gets shrunk a lot by the perspective warp,
   and hard-edged, shadow-less text falls apart into illegible fragments
   at that scale - the blur is load-bearing, not just decorative. */
body[data-bg-color="blue90s"] #bgBadge {
  color: #e8e8e8;
  text-shadow: 0 0 0.6vh rgba(232, 232, 232, 0.8), 0 0 1.6vh rgba(232, 232, 232, 0.5);
}

/* --- Settings panel: rounded card UI in a warm, legible, Atkinson
   Hyperlegible face - readability and easy targets come first here. Its
   accent color is still always whatever color the bouncer currently is
   (var(--glow), set on <html> by setColor()), so the panel still reads as
   part of the show rather than an independent brand, even though its shape
   language no longer matches the sharp-cornered monospace HUD of the rest
   of #controls (the settings button itself, and the on-screen countdown,
   keep that original look). --accent is defined once here and referenced
   everywhere below instead of repeating the var(--glow, #ff3b30) fallback
   per rule. */
:root {
  --accent: var(--glow, #ff3b30);
}
#controls {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  opacity: 0.35;
  transition: opacity 1s ease;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
#controls:hover, #controls:focus-within {
  opacity: 1;
}
body.idle #controls {
  opacity: 0;
  pointer-events: none;
}

#settingsBtn {
  width: 30px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: rgba(12, 12, 15, 0.72);
  border: 1px solid var(--accent);
  border-radius: 0;
  cursor: pointer;
}
#settingsBtn:hover {
  background: rgba(12, 12, 15, 0.9);
}
#settingsBtn .bars {
  display: block;
  width: 14px;
  height: 10px;
  background: linear-gradient(
    currentColor 0 2px, transparent 2px 4px,
    currentColor 4px 6px, transparent 6px 8px,
    currentColor 8px 10px
  );
}

#trailControls {
  margin-top: 8px;
  width: 320px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  color: #f2ede6;
  font-family: 'Atkinson Hyperlegible', system-ui, sans-serif;
  background: #1a1816;
  border: 1px solid #3a3632;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
#trailControls[hidden] {
  display: none;
}

.panelHead {
  padding: 2px 4px 14px;
}
.panelTitle {
  font-size: 18px;
  font-weight: 700;
}
.panelSubtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: #c9c0b6;
}

.panelSection {
  background: #242220;
  border: 1px solid #3a3632;
  border-radius: 14px;
  padding: 14px;
}
.panelSection + .panelSection {
  margin-top: 10px;
}
.sectionHead {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.sectionIcon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}
.sectionIcon svg {
  width: 17px;
  height: 17px;
}
.sectionHeadText {
  padding-top: 1px;
}
.sectionLabel {
  font-size: 15.5px;
  font-weight: 700;
  color: #f2ede6;
}

/* A short plain-language line under each section's label, so what a toggle
   or slider actually does doesn't have to be inferred from its name alone. */
.sectionHint {
  margin: 2px 0 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: #c9c0b6;
}

.paletteRow {
  position: relative;
}
#paletteButton {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 14px;
  color: #f2ede6;
  background: #2c2925;
  border: 1px solid #4a453f;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
#paletteButton:hover {
  border-color: var(--accent);
}
.swatchStrip {
  display: inline-block;
  width: 40px;
  height: 12px;
  flex-shrink: 0;
  border-radius: 4px;
}
#paletteButtonLabel {
  flex: 1;
  text-align: left;
}
.paletteList {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #242220;
  border: 1px solid var(--accent);
  border-radius: 10px;
}
.paletteList[hidden] {
  display: none;
}
.paletteList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  font-size: 13.5px;
  border-radius: 6px;
  cursor: pointer;
}
.paletteList li:hover, .paletteList li[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.1);
}

#photoRow {
  display: flex;
  gap: 8px;
}
#pickBtn, #clearBtn, #resetDefaultsBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #f2ede6;
  background: #2c2925;
  border: 1px solid #4a453f;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
#pickBtn:hover, #clearBtn:hover, #resetDefaultsBtn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
#resetDefaultsBtn {
  width: 100%;
  margin-top: 4px;
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}
#resetDefaultsBtn svg {
  width: 17px;
  height: 17px;
}
#clearBtn[hidden] {
  display: none;
}
#fileInput {
  display: none;
}

/* label rows shared by the switch (checkbox) rows and the trail sliders */
#trailControls label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  min-height: 30px;
}
#trailControls label + label {
  margin-top: 14px;
}
.switchRow {
  justify-content: space-between;
}
.trailRow > span:first-child {
  width: 60px;
  flex-shrink: 0;
  color: #c9c0b6;
}

/* checkbox/select/range all replace native browser chrome with the pill/
   rounded look below, so they share one appearance reset. */
#trailControls input[type="checkbox"],
#trailControls select,
#trailControls input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
}

/* checkbox restyled as a pill toggle switch with a sliding knob, matching
   the rest of the card UI - and sized well past the 16x16 native default
   so it's an easy target to hit, not just to see. */
#trailControls input[type="checkbox"] {
  position: relative;
  width: 52px;
  height: 30px;
  margin: 0;
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  background: #3a3632;
  cursor: pointer;
  transition: background 0.15s ease;
}
#trailControls input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}
#trailControls input[type="checkbox"]:checked {
  background: var(--accent);
}
#trailControls input[type="checkbox"]:checked::before {
  transform: translateX(22px);
}

#trailControls select {
  color-scheme: dark;
  flex: 1;
  min-height: 44px;
  font-family: inherit;
  font-size: 14px;
  background-color: #2c2925;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 14px) center,
    calc(100% - 9px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid #4a453f;
  border-radius: 10px;
  padding: 6px 26px 6px 10px;
}
#trailControls select:hover {
  border-color: var(--accent);
}

/* range sliders as a filled pill track in the live accent color, with a
   round thumb. --fill is kept in sync with each input's value by app.js. */
#trailControls input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--accent) 0 var(--fill, 50%),
    #3a3632 var(--fill, 50%) 100%
  );
}
#trailControls input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
#trailControls input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
#trailControls input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: transparent;
}

#trailControls .trailVal {
  min-width: 44px;
  text-align: right;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

#controls :is(button, select, input):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

#countdown {
  position: fixed;
  left: 16px;
  bottom: 14px;
  z-index: 10;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  color: #e4e4e8;
  padding: 4px 8px;
  border-radius: 0;
  background: rgba(12, 12, 15, 0.72);
  border: 1px solid var(--accent);
  opacity: 0.35;
  transition: opacity 1s ease;
  font-variant-numeric: tabular-nums;
}
body.idle #countdown {
  opacity: 0;
  pointer-events: none;
}
#countdown[hidden] {
  display: none;
}
#countdown .spoiler {
  display: inline-block;
  box-sizing: border-box;
  width: 4.5em;
  text-align: center;
  cursor: pointer;
  color: transparent;
  background: #8b8b93;
}
#countdown .spoiler:empty {
  display: none;
}
#countdown .spoiler.revealed {
  background: transparent;
  color: var(--accent);
}
#countdown:hover {
  opacity: 1;
}

/* Corner-hit celebration (viewport shake, white flash, pulses) is a lot of
   sudden motion layered on top of the core bounce, which itself stays
   untouched here - dampening that would defeat the point of a DVD-logo
   screensaver. These extras are just garnish, so they're what
   prefers-reduced-motion turns off. */
@media (prefers-reduced-motion: reduce) {
  body.shake, #bouncer.hit, #flash.active, #cornerText.active {
    animation: none;
  }
  #cornerText.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  #controls, #countdown, #trailControls input[type="checkbox"],
  #trailControls input[type="checkbox"]::before {
    transition: none;
  }
}
