:root {
  --applet-max-width: 1100px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(circle at 20% 20%, rgba(217, 70, 239, 0.12), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(236, 72, 153, 0.12), transparent 40%),
    var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html.is-embedded body {
  display: block;
  padding: 0;
  background: transparent;
}

/* Embedded mode keeps scrolling active, hides scrollbar chrome until interaction,
   and uses the site theme when visible. */
html.is-embedded {
  height: auto;
  min-height: 0;
  overflow: hidden;
}

html.is-embedded body {
  height: auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  -ms-overflow-style: none;
  scrollbar-color: transparent transparent;
}

html.is-embedded::-webkit-scrollbar,
html.is-embedded body::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

html.is-embedded::-webkit-scrollbar-track,
html.is-embedded body::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 9999px;
}

html.is-embedded::-webkit-scrollbar-thumb,
html.is-embedded body::-webkit-scrollbar-thumb {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9999px;
}

html.is-embedded:hover,
html.is-embedded:focus-within,
html.is-embedded body:hover,
html.is-embedded body:focus-within {
  scrollbar-color: rgba(217, 70, 239, 0.92) rgba(15, 23, 42, 0.36);
}

html.is-embedded:hover::-webkit-scrollbar-track,
html.is-embedded:focus-within::-webkit-scrollbar-track,
html.is-embedded body:hover::-webkit-scrollbar-track,
html.is-embedded body:focus-within::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.32);
}

html.is-embedded:hover::-webkit-scrollbar-thumb,
html.is-embedded:focus-within::-webkit-scrollbar-thumb,
html.is-embedded body:hover::-webkit-scrollbar-thumb,
html.is-embedded body:focus-within::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    rgba(217, 70, 239, 0.94),
    rgba(171, 90, 183, 0.88)
  );
  border: 1px solid rgba(15, 23, 42, 0.65);
}

/* Apply the same embedded scrollbar behavior to nested scroll containers. */
html.is-embedded body * {
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  scrollbar-color: transparent transparent;
}

html.is-embedded body *::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

html.is-embedded body *::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 9999px;
}

html.is-embedded body *::-webkit-scrollbar-thumb {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9999px;
}

html.is-embedded body *:hover,
html.is-embedded body *:focus,
html.is-embedded body *:focus-within {
  scrollbar-color: rgba(217, 70, 239, 0.92) rgba(15, 23, 42, 0.36);
}

html.is-embedded body *:hover::-webkit-scrollbar-track,
html.is-embedded body *:focus::-webkit-scrollbar-track,
html.is-embedded body *:focus-within::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.32);
}

html.is-embedded body *:hover::-webkit-scrollbar-thumb,
html.is-embedded body *:focus::-webkit-scrollbar-thumb,
html.is-embedded body *:focus-within::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    rgba(217, 70, 239, 0.94),
    rgba(171, 90, 183, 0.88)
  );
  border: 1px solid rgba(15, 23, 42, 0.65);
  border-radius: 9999px;
}

html.is-embedded .applet {
  width: 100%;
  max-width: 100%;
}

.applet {
  width: min(var(--applet-max-width), 100%);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), var(--panel));
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: 0 18px 42px rgba(1, 4, 9, 0.55);
  overflow: hidden;
  position: relative;
}

.applet::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 10% 80%, rgba(255, 255, 255, 0.06), transparent 35%),
    radial-gradient(circle at 90% 30%, rgba(255, 255, 255, 0.04), transparent 40%);
  opacity: 0.4;
  pointer-events: none;
}

button {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}

button:hover { background: rgba(255,255,255,0.10); }
button:active { transform: translateY(1px); }

input[type="range"] {
  width: 140px;
  height: 8px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  --range-fill: 50%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: linear-gradient(
    90deg,
    rgba(232, 121, 249, 0.92) 0%,
    rgba(217, 70, 239, 0.85) var(--range-fill),
    rgba(255, 255, 255, 0.14) var(--range-fill),
    rgba(255, 255, 255, 0.14) 100%
  );
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 6px rgba(1, 4, 9, 0.35);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(232, 121, 249, 0.95), rgba(217, 70, 239, 0.95));
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 10px rgba(217, 70, 239, 0.5);
  margin-top: -5px;
}

input[type="range"]::-moz-range-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 6px rgba(1, 4, 9, 0.35);
}

input[type="range"]::-moz-range-progress {
  height: 8px;
  background: linear-gradient(135deg, rgba(232, 121, 249, 0.95), rgba(217, 70, 239, 0.95));
  border-radius: 9999px;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(232, 121, 249, 0.95), rgba(217, 70, 239, 0.95));
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 10px rgba(217, 70, 239, 0.5);
}

input[type="range"]::-moz-focus-outer {
  border: 0;
}

input[type="range"]:focus-visible {
  outline: 2px solid rgba(217, 70, 239, 0.55);
  outline-offset: 3px;
}

svg {
  width: 100%;
  height: auto;
  display: block;
}

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