.demo {
  position: relative;
  width: 100%;
  min-width: 0;
}

.demo-frame {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid #E2E5EA;
  border-radius: 16px;
  background: linear-gradient(180deg, #D6E6F7 0%, #EEF5FC 100%);
  outline: none;
  isolation: isolate;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.demo-frame--narrow {
  aspect-ratio: 4 / 3;
}

.demo-frame:focus-visible {
  box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 5px #1D5FA8;
}

.demo-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.demo--running .demo-canvas {
  touch-action: none;
}

.demo--hop.demo--running .demo-canvas {
  cursor: pointer;
}

.demo-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.demo-chip {
  padding: 4px 10px 5px;
  border: 1px solid #E2E5EA;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #16181D;
  font-family: "Pixelify Sans", system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.demo-chip--status {
  color: #5A616D;
}

.demo-chip--status[hidden] {
  display: block;
  visibility: hidden;
}

.demo-chip--best {
  color: #B7801A;
}

.demo-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 52px 16px 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease-out, visibility 0s linear 160ms;
}

.demo-overlay.demo-overlay--shown {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease-out;
}

.demo-overlay--pause {
  background: rgba(238, 243, 249, 0.55);
  cursor: pointer;
}

.demo-card {
  box-sizing: border-box;
  max-width: 22rem;
  padding: 18px 22px 20px;
  border: 1px solid #E2E5EA;
  border-radius: 14px;
  background: #FFFFFF;
  box-shadow: 0 10px 30px rgba(22, 24, 29, 0.08), 0 1px 2px rgba(22, 24, 29, 0.06);
  text-align: center;
  transform: translateY(6px) scale(0.98);
  transition: transform 260ms cubic-bezier(0.23, 1, 0.32, 1);
}

.demo-overlay.demo-overlay--shown .demo-card {
  transform: none;
}

.demo-title {
  margin: 0;
  color: #16181D;
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.demo-result {
  margin: 6px 0 0;
  color: #1D5FA8;
  font-family: "Pixelify Sans", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.demo-result[hidden] {
  display: none;
}

.demo-line {
  margin: 6px 0 14px;
  color: #5A616D;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.4;
  text-wrap: balance;
}

.demo-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 10px;
  background: #1D5FA8;
  color: #FFFFFF;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1), background-color 160ms cubic-bezier(0.23, 1, 0.32, 1);
}

.demo-play:active {
  background: #174D8A;
  transform: scale(0.97);
}

.demo-play:focus-visible {
  outline: 2px solid #1D5FA8;
  outline-offset: 3px;
}

.demo-live {
  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;
}

@media (hover: hover) and (pointer: fine) {
  .demo-play:hover {
    background: #174D8A;
  }
}

@media (max-width: 600px) {
  .demo-hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
  }

  .demo-chip {
    padding: 3px 8px 4px;
    font-size: 13px;
  }

  .demo-overlay {
    padding: 40px 12px 12px;
  }

  .demo-card {
    padding: 14px 16px 16px;
  }

  .demo-title {
    font-size: 19px;
  }

  .demo-result {
    font-size: 24px;
  }

  .demo-line {
    margin: 4px 0 12px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .demo-overlay,
  .demo-overlay.demo-overlay--shown,
  .demo-card,
  .demo-play {
    transition: none;
  }

  .demo-card {
    transform: none;
  }
}
