html,
body {
  margin: 0;
  overflow: hidden;
  height: 100%;
  font-size: calc(16px * var(--tv-scale-multiplier) * var(--ui-scale));
  font-family: var(--font-family-base);
  color: var(--text-color);
  line-height: var(--line-height-normal);
  -webkit-tap-highlight-color: transparent;
}

/* All design tokens now live in tokens.css — loaded before this file. */

html {
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  overscroll-behavior: none;
}

::selection {
  background: color-mix(in srgb, var(--accent-color) 50%, transparent);
  color: var(--text-color);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent-color) 40%, transparent);
  border-radius: var(--radius-pill);
  border: 0;
  min-height: 32px;
}

::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent-color) 60%, transparent);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

input,
textarea,
[contenteditable] {
  caret-color: var(--accent-color, #5fc0b5);
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--text-muted) 72%, transparent);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    /* biome-ignore lint/complexity/noImportantStyles: respect user motion preference */
    animation-duration: 0.01ms !important;
    /* biome-ignore lint/complexity/noImportantStyles: respect user motion preference */
    animation-iteration-count: 1 !important;
    /* biome-ignore lint/complexity/noImportantStyles: respect user motion preference */
    transition-duration: 0.01ms !important;
    /* biome-ignore lint/complexity/noImportantStyles: respect user motion preference */
    scroll-behavior: auto !important;
  }
}

@media print {
  html,
  body {
    /* biome-ignore lint/complexity/noImportantStyles: force print colors */
    background: white !important;
    /* biome-ignore lint/complexity/noImportantStyles: force print colors */
    color: black !important;
  }

  .control-panel {
    /* biome-ignore lint/complexity/noImportantStyles: hide chrome when printing */
    display: none !important;
  }
}

/* TV mode tokens now in tokens.css */
canvas {
  display: block;
  user-select: none;
}

a,
button,
input,
select,
textarea,
[role="button"] {
  touch-action: manipulation;
}

body.gamepad-active :focus:not(:focus-visible) {
  outline: var(--tv-focus-outline-width) solid
    var(--accent-color, rgba(96, 165, 250, 0.95));
  outline-offset: var(--tv-focus-outline-offset);
}

body {
  background:
    radial-gradient(
      circle at 18% 12%,
      color-mix(in srgb, var(--accent-color) 12%, transparent),
      transparent 30%
    ),
    radial-gradient(
      circle at 85% 18%,
      color-mix(in srgb, var(--accent-magenta) 12%, transparent),
      transparent 24%
    ),
    var(--bg-color);
}

@media (prefers-contrast: more) {
  .active-toy-status__content {
    border-color: rgba(233, 251, 255, 0.95);
    box-shadow:
      0 18px 36px rgba(0, 0, 0, 0.55),
      0 0 0 2px rgba(233, 251, 255, 0.6);
  }
}

.active-toy-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #e9fbff;
  text-align: center;
  padding: 24px;
  isolation: isolate;
}

.active-toy-status__content {
  contain: layout style;
  background: var(--stims-panel-strong);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-xl) var(--space-2xl);
  max-width: 460px;
  width: min(90vw, 480px);
  overscroll-behavior: contain;
}

.active-toy-status h2 {
  margin: var(--space-md) 0 var(--space-sm);
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.01em;
  text-shadow: 0 0 18px color-mix(in srgb, var(--accent-color) 18%, transparent);
}

.active-toy-status p {
  margin: 0;
  color: var(--text-muted);
  line-height: var(--line-height-normal);
  font-size: var(--text-base);
  letter-spacing: 0.01em;
}

.active-toy-status.is-error .active-toy-status__content {
  border-color: color-mix(in srgb, #db7878 55%, transparent);
  box-shadow:
    var(--shadow-surface),
    0 0 18px color-mix(in srgb, #db7878 25%, transparent);
}

.stims-icon-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  line-height: 0;
}

.stims-icon-slot > svg {
  display: block;
  width: 100%;
  height: 100%;
}

.stims-icon-slot--sm {
  width: 1rem;
  height: 1rem;
}

.stims-icon-slot--md {
  width: 1.15rem;
  height: 1.15rem;
}

.rendering-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: var(--z-error-overlay);
  pointer-events: auto;
}

.rendering-overlay__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      circle at 20% 30%,
      rgba(148, 165, 180, 0.18),
      transparent 30%
    ),
    radial-gradient(
      circle at 80% 70%,
      rgba(161, 124, 106, 0.16),
      transparent 28%
    ),
    linear-gradient(135deg, rgba(4, 6, 14, 0.85), rgba(6, 10, 20, 0.9));
  filter: blur(12px);
  opacity: 0.9;
}

.rendering-overlay__panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(220px, 0.85fr);
  grid-template-areas:
    "eyebrow preview"
    "title preview"
    "description preview"
    "steps preview"
    "links preview"
    "actions actions";
  gap: 14px 20px;
  pointer-events: auto;
  width: min(760px, calc(100vw - 32px));
  padding: 28px 30px 26px;
  border-radius: var(--radius-2xl);
  background:
    radial-gradient(
      circle at top right,
      rgba(124, 232, 255, 0.16),
      transparent 32%
    ),
    radial-gradient(
      circle at 0% 100%,
      rgba(255, 159, 104, 0.14),
      transparent 34%
    ),
    linear-gradient(180deg, rgba(7, 12, 22, 0.98), rgba(9, 15, 28, 0.98));
  border: 1px solid rgba(208, 226, 255, 0.14);
  box-shadow:
    0 36px 80px rgba(0, 0, 0, 0.52),
    inset 0 1px 0 var(--stims-white-05);
  color: #e9fbff;
  overscroll-behavior: contain;
}

.rendering-overlay__panel::before {
  content: "";
  position: absolute;
  left: 30px;
  right: 30px;
  top: 12px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #c8ff74, #7ce8ff 54%, #ff9f68);
  opacity: 0.58;
}

.rendering-overlay__panel h1 {
  grid-area: title;
  margin: 0;
  font-size: clamp(1.7rem, 2vw, 2.2rem);
  line-height: 1.04;
  letter-spacing: 0.02em;
}

.rendering-overlay__eyebrow {
  grid-area: eyebrow;
  margin: 0;
  text-transform: uppercase;
  font-stretch: var(--font-stretch-legend);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: rgba(200, 255, 116, 0.88);
}

.rendering-overlay__description {
  grid-area: description;
  margin: 0;
  max-width: 42ch;
  color: rgba(233, 251, 255, 0.82);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.rendering-overlay__steps {
  grid-area: steps;
  margin: 0;
  padding: 14px 0 0 20px;
  border-top: 1px solid var(--stims-border-08);
  padding-left: 20px;
  color: rgba(233, 251, 255, 0.82);
  display: grid;
  gap: 8px;
  font-size: 0.9375rem;
}

.rendering-overlay__links {
  grid-area: links;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
}

.rendering-overlay__actions {
  grid-area: actions;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--stims-border-08);
}

.rendering-overlay__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(208, 226, 255, 0.16);
  background:
    linear-gradient(180deg, var(--stims-white-05), transparent 44%),
    rgba(12, 22, 36, 0.74);
  color: #e9fbff;
  text-decoration: none;
  font-weight: 700;
  transition:
    transform 160ms ease,
    box-shadow 200ms ease,
    border-color 200ms ease;
  touch-action: manipulation;
}

.rendering-overlay__button:hover {
  transform: translateY(-1px);
  border-color: rgba(124, 232, 255, 0.28);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.28);
}

.rendering-overlay__button:focus-visible {
  outline: 2px solid var(--stims-cool);
  outline-offset: 3px;
}

.rendering-overlay__links a {
  color: #0ff4f9;
  text-decoration: none;
  border: 1px solid rgba(208, 226, 255, 0.12);
  padding: 7px 11px;
  border-radius: var(--radius-pill);
  background: var(--stims-white-04);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

.rendering-overlay__links a:hover,
.rendering-overlay__links a:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(124, 232, 255, 0.24);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.18);
}

.rendering-overlay__preview {
  grid-area: preview;
  align-self: stretch;
  display: grid;
  gap: 10px;
  border: 1px solid rgba(208, 226, 255, 0.12);
  border-radius: var(--radius-xl);
  padding: 14px;
  background:
    linear-gradient(180deg, var(--stims-white-05), transparent 44%),
    rgba(8, 16, 28, 0.78);
}

.rendering-overlay__preview p {
  margin: 0;
  color: rgba(233, 251, 255, 0.72);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.rendering-overlay__preview-pane {
  min-height: 220px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 25% 40%, var(--stims-muted-35), transparent 45%),
    radial-gradient(
      circle at 70% 60%,
      rgba(161, 124, 106, 0.4),
      transparent 40%
    ),
    linear-gradient(135deg, rgba(12, 18, 35, 0.85), rgba(10, 14, 26, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    inset 0 0 22px rgba(0, 0, 0, 0.45),
    0 0 18px rgba(148, 165, 180, 0.2);
  position: relative;
  overflow: hidden;
}

.rendering-overlay__preview-pane::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: conic-gradient(
    from 90deg,
    rgba(148, 165, 180, 0.18),
    rgba(161, 124, 106, 0.12),
    rgba(148, 165, 180, 0.18),
    rgba(161, 124, 106, 0.12)
  );
  filter: blur(28px);
  opacity: 0.9;
  animation: hueShift 12s linear infinite;
}

@media (max-width: 720px) {
  .rendering-overlay__panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "eyebrow"
      "title"
      "description"
      "preview"
      "steps"
      "links"
      "actions";
    width: min(560px, calc(100vw - 24px));
    padding: 24px 20px 22px;
  }

  .rendering-overlay__panel::before {
    left: 20px;
    right: 20px;
  }

  .rendering-overlay__preview-pane {
    min-height: 150px;
  }
}

.control-panel {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  width: min(312px, 88vw);
  color: #e9fbff;
  padding: 12px;
  background: linear-gradient(
    180deg,
    rgba(10, 16, 22, 0.98),
    rgba(12, 18, 24, 0.97)
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 18px 42px var(--stims-shadow-34);
  border-radius: var(--radius-xl);
  z-index: var(--z-control-panel);
  overflow: hidden;
  overscroll-behavior: contain;
}

.control-panel--floating {
  bottom: auto;
  left: auto;
  top: max(
    var(--toy-nav-floating-offset, 102px),
    calc(env(safe-area-inset-top) + 96px)
  );
  right: max(10px, env(safe-area-inset-right));
  width: min(390px, 92vw);
  max-height: min(
    calc(
      100dvh -
      20px -
      env(safe-area-inset-top) -
      env(safe-area-inset-bottom)
    ),
    90vh
  );
  overflow: auto;
}

.control-panel::before,
.control-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.control-panel::before {
  background: linear-gradient(180deg, var(--stims-white-04), transparent);
  opacity: 0.7;
}

.control-panel::after {
  inset: 6px;
  border: 1px solid var(--stims-white-04);
  border-radius: var(--radius-lg);
}

.control-panel__heading {
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-bottom: 2px;
}

.control-panel__description {
  margin: 0 0 8px;
  font-size: 0.8125rem;
  color: rgba(245, 245, 245, 0.76);
}

.control-panel__pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 2px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(148, 165, 180, 0.24);
  font-size: 0.6875rem;
  letter-spacing: 0.01em;
  color: rgba(233, 251, 255, 0.9);
  background: var(--stims-white-05);
}

.control-panel__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 10px 0;
  border-top: 1px solid var(--stims-white-08);
}

.control-panel__row--toggle {
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
}

.control-panel__row:first-of-type {
  border-top: none;
}

.control-panel__text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.control-panel__microcopy {
  font-size: 0.75rem;
  color: rgba(233, 251, 255, 0.6);
  line-height: 1.35;
}

.control-panel__actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.control-panel__actions--inline {
  align-items: center;
  margin-top: 0;
}

.control-panel__label {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
  font-size: 0.9375rem;
}

.control-panel small {
  color: rgba(245, 245, 245, 0.82);
  line-height: 1.3;
}

.control-panel input[type="checkbox"] {
  width: 28px;
  height: 28px;
  accent-color: #70f0ff;
  filter: drop-shadow(0 0 6px rgba(148, 165, 180, 0.5));
  border: 1px solid rgba(148, 165, 180, 0.55);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.control-panel select {
  background: rgba(11, 17, 29, 0.92);
  color: #e9fbff;
  border: 1px solid rgba(148, 165, 180, 0.5);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  min-width: 150px;
  min-height: 44px;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: none;
  font-size: 1rem;
}

.control-panel select:focus {
  outline: 2px solid rgba(161, 124, 106, 0.65);
  outline-offset: 2px;
  box-shadow:
    0 0 18px rgba(161, 124, 106, 0.4),
    0 0 10px var(--stims-muted-35);
}

.control-panel input[type="range"] {
  appearance: none;
  width: 100%;
  height: 44px;
  border-radius: var(--radius-pill);
  background: var(--stims-white-04);
  border: 1px solid rgba(148, 165, 180, 0.36);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  cursor: pointer;
  flex: 1;
}

.control-panel input[type="range"]:focus-visible {
  outline: 2px solid rgba(161, 124, 106, 0.65);
  outline-offset: 3px;
  box-shadow:
    0 0 18px rgba(161, 124, 106, 0.4),
    0 0 10px var(--stims-muted-35);
}

.control-panel input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: var(--radius-pill);
  background: rgba(148, 165, 180, 0.18);
  border: 1px solid rgba(148, 165, 180, 0.34);
}

.control-panel input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(233, 251, 255, 0.92);
  border: 1px solid rgba(148, 165, 180, 0.6);
  box-shadow: none;
  margin-top: -4px;
}

.control-panel input[type="range"]::-moz-range-track {
  height: 12px;
  border-radius: var(--radius-pill);
  background: rgba(148, 165, 180, 0.18);
  border: 1px solid rgba(148, 165, 180, 0.34);
}

.control-panel input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(233, 251, 255, 0.92);
  border: 1px solid rgba(148, 165, 180, 0.6);
  box-shadow: none;
}

@media (max-width: 720px) {
  .control-panel--floating {
    top: max(
      var(--toy-nav-floating-offset, 108px),
      calc(env(safe-area-inset-top) + 84px)
    );
    max-height: min(
      34svh,
      calc(
        100dvh -
        var(--toy-nav-floating-offset, 108px) -
        env(safe-area-inset-bottom) -
        10px
      )
    );
  }

  .control-panel {
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    width: auto;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    clip-path: none;
    border-radius: var(--radius-xl);
    max-height: min(
      44svh,
      calc(
        100dvh -
        12px -
        env(safe-area-inset-top) -
        env(safe-area-inset-bottom)
      )
    );
    overflow-y: auto;
  }

  .control-panel__description {
    display: none;
  }

  .control-panel__row {
    margin: 4px 0;
    padding: 6px 0;
  }

  .control-panel::after {
    clip-path: none;
  }

  .control-panel__row {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
    padding: 4px 0;
  }

  .control-panel__heading {
    font-size: 0.875rem;
  }

  .control-panel__text {
    min-width: 0;
    gap: 2px;
  }

  .control-panel__label {
    min-height: auto;
    font-size: 0.875rem;
    line-height: 1.2;
  }

  .control-panel__microcopy {
    font-size: 0.6875rem;
  }

  .control-panel__description {
    font-size: 0.75rem;
    margin-bottom: 6px;
  }

  .control-panel__actions {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }
}

@media (max-width: 520px) {
  .control-panel--floating {
    top: max(
      var(--toy-nav-floating-offset, 108px),
      calc(env(safe-area-inset-top) + 72px)
    );
    max-height: min(
      40svh,
      calc(
        100dvh -
        var(--toy-nav-floating-offset, 108px) -
        env(safe-area-inset-bottom) -
        8px
      )
    );
  }

  .control-panel {
    padding: 8px;
    max-height: min(
      40svh,
      calc(
        100dvh -
        var(--toy-nav-floating-offset, 102px) -
        env(safe-area-inset-bottom) -
        10px
      )
    );
  }

  .control-panel__actions--inline {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 920px) and (max-height: 520px) and (orientation: landscape) {
  .control-panel__row {
    gap: 10px;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

#error-message {
  position: fixed;
  top: 20px;
  left: 20px;
  display: none;
  color: #ff7b7b;
  background: rgba(0, 0, 0, 0.78);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 123, 123, 0.35);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  z-index: var(--z-active-nav);
  font-weight: 600;
}

body.tv-mode .control-panel {
  right: max(calc(env(safe-area-inset-right) + var(--tv-safe-padding)), 24px);
  bottom: max(calc(env(safe-area-inset-bottom) + var(--tv-safe-padding)), 24px);
}

body.tv-mode .control-panel button,
body.tv-mode .control-panel select,
body.tv-mode .control-panel input {
  min-height: 56px;
  min-width: 56px;
  font-size: 1rem;
}

body {
  background:
    radial-gradient(
      circle at 14% 12%,
      rgba(111, 125, 255, 0.18),
      transparent 24%
    ),
    radial-gradient(
      circle at 82% 18%,
      rgba(255, 179, 71, 0.14),
      transparent 22%
    ),
    linear-gradient(180deg, #10182a 0%, #09111f 36%, #050a12 100%);
}

.active-toy-status__content {
  background:
    linear-gradient(
      180deg,
      var(--toy-shell-highlight),
      rgba(255, 255, 255, 0.02) 18%
    ),
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.035) 0 2px,
      transparent 2px 10px
    ),
    var(--toy-shell-metal);
  border: 1px solid rgba(211, 224, 255, 0.28);
  box-shadow:
    0 18px 32px rgba(0, 0, 0, 0.46),
    0 2px 0 rgba(255, 255, 255, 0.12) inset,
    0 -2px 0 var(--toy-shell-shadow) inset;
  border-radius: var(--radius-lg);
}

.active-toy-status__content::before {
  content: "";
  display: block;
  width: 100%;
  height: 3px;
  margin-bottom: 14px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #80d84f, #ffb347 48%, #6f7dff);
  opacity: 0.9;
}

.active-toy-status h2 {
  color: #eff5ff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.active-toy-status p {
  color: rgba(230, 236, 245, 0.8);
}

.active-toy-status__content {
  border-radius: var(--radius-sm);
  box-shadow:
    0 18px 32px rgba(0, 0, 0, 0.46),
    0 1px 0 rgba(255, 255, 255, 0.18) inset,
    0 -1px 0 rgba(11, 16, 28, 0.72) inset,
    1px 0 0 var(--stims-white-08) inset,
    -1px 0 0 rgba(11, 16, 28, 0.42) inset;
}

.active-toy-status__content::before {
  height: 2px;
  margin-bottom: 12px;
}

.milkdrop-overlay__preview-capture-host {
  position: fixed;
  top: -9999px;
  left: -9999px;
  width: 360px;
  height: 203px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.milkdrop-overlay__preview-capture-canvas {
  display: block;
  width: 360px;
  height: 203px;
}

/* Prevent iOS Safari involuntary auto-zoom on input focus */
@media (max-width: 767px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}
