:root {
  --primary: #08aeea;
  --primary-hover: #0798d0;
  --toolbar-bg: #f5f9fd;
  --toolbar-border: #dbe6f2;
  --control-border: #d7e1ee;
  --control-text: #52647a;
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #243242;
  color: #172033;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #2d3b4c;
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  background: #2d3b4c;
}

.topbar {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 14px 132px 16px 18px;
  border-bottom: 1px solid var(--toolbar-border);
  background: var(--toolbar-bg);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.8);
}

.controls {
  position: relative;
  z-index: 2;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.scene-controls {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.scene-picker {
  position: relative;
  width: min(360px, 42vw);
  min-width: 240px;
}

.scene-picker-control {
  position: relative;
  display: flex;
  min-width: 0;
}

.scene-search {
  width: 100%;
  height: 36px;
  padding: 0 42px 0 12px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: #ffffff;
  color: #172033;
  outline: none;
  box-shadow: 0 2px 8px rgba(36, 61, 92, 0.04);
}

.scene-search:focus,
.scene-search[aria-expanded="true"] {
  border-color: #8fd9f6;
  box-shadow: 0 0 0 3px rgba(8, 174, 234, 0.15);
}

.scene-search:disabled {
  color: #78889c;
  cursor: wait;
  background: #f8fafc;
}

.scene-picker-toggle {
  position: absolute;
  inset: 1px 1px 1px auto;
  width: 36px;
  border: 0;
  border-radius: 0 7px 7px 0;
  background: transparent;
  color: #63748b;
  cursor: pointer;
  font-size: 18px;
}

.scene-picker-toggle:focus-visible,
.scene-page-button:focus-visible,
.scene-retry:focus-visible,
.scene-option:focus-visible,
.manual-mode summary:focus-visible {
  outline: 3px solid rgba(8, 174, 234, 0.28);
  outline-offset: 2px;
}

.scene-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 80;
  width: min(420px, calc(100vw - 24px));
  overflow: hidden;
  border: 1px solid #d7e1ee;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.2);
}

.scene-list-state {
  min-height: 44px;
  padding: 13px 14px;
  color: #63748b;
  font-size: 13px;
  line-height: 1.4;
}

.scene-list-state[data-tone="error"] {
  color: #a92f2f;
  background: #fff7f7;
}

.scene-list-state:empty {
  display: none;
}

.scene-options {
  max-height: min(360px, 52vh);
  max-height: min(360px, 52dvh);
  overflow-y: auto;
  padding: 5px;
}

.scene-option {
  width: 100%;
  min-height: 58px;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: #172033;
  cursor: pointer;
  text-align: left;
}

.scene-option:hover,
.scene-option[aria-selected="true"] {
  background: #eef8fd;
}

.scene-option[aria-selected="true"] {
  box-shadow: inset 3px 0 0 var(--primary);
}

.scene-thumbnail,
.scene-thumbnail-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  object-fit: cover;
  background: linear-gradient(145deg, #e7eef7, #d7e3ef);
}

.scene-thumbnail-placeholder {
  display: grid;
  place-items: center;
  color: #8797aa;
  font-size: 17px;
}

.scene-option-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.scene-option-name {
  overflow: hidden;
  color: #263b55;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-option-meta {
  color: #78889c;
  font-size: 12px;
}

.scene-option-check {
  color: var(--primary-hover);
  font-weight: 800;
}

.scene-retry {
  margin: 0 14px 13px;
  padding: 7px 12px;
  border: 1px solid #d7e1ee;
  border-radius: 7px;
  background: #ffffff;
  color: #36506c;
  cursor: pointer;
}

.scene-pagination {
  min-height: 42px;
  padding: 6px 10px;
  border-top: 1px solid #edf1f5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #63748b;
  font-size: 12px;
}

.scene-page-button {
  width: 30px;
  height: 30px;
  border: 1px solid #d7e1ee;
  border-radius: 7px;
  background: #ffffff;
  color: #52647a;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.scene-page-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.manual-mode {
  position: relative;
  color: #63748b;
  font-size: 12px;
}

.manual-mode > summary {
  cursor: pointer;
  white-space: nowrap;
}

.manual-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 75;
  width: min(390px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid #d7e1ee;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
}

.manual-panel p {
  margin: 0 0 10px;
  color: #63748b;
  line-height: 1.45;
}

.development-token {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #edf1f5;
}

.development-warning {
  color: #9a6518 !important;
}

.development-token-row {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.development-token-row .scene-input {
  flex: 1 1 auto;
}

.scene-field {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--control-text);
  font-size: 13px;
  font-weight: 700;
}

.scene-input {
  width: 220px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: #ffffff;
  color: #172033;
  outline: none;
  box-shadow: 0 2px 8px rgba(36, 61, 92, 0.04);
}

.scene-input:focus {
  border-color: #8fd9f6;
  box-shadow: 0 0 0 3px rgba(8, 174, 234, 0.15);
}

.button {
  height: 36px;
  min-width: 74px;
  padding: 0 17px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--control-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 650;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(36, 61, 92, 0.06);
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.button:hover:not(:disabled) {
  border-color: #b6c8dc;
  background: #f9fcff;
  color: #263b55;
  box-shadow: 0 4px 12px rgba(36, 61, 92, 0.1);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.button-primary {
  min-width: 78px;
  padding-inline: 18px;
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 5px 14px rgba(8, 174, 234, 0.24);
}

.button-primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
  color: #ffffff;
}

.button-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 16px;
  font-size: 16px;
  line-height: 1;
  transform: none;
}

.button[data-stop] {
  border-color: #f1b8b8;
  background: #fff7f7;
  color: #c24141;
}

.button[data-stop]:hover:not(:disabled) {
  border-color: #e68c8c;
  background: #fff0f0;
  color: #a92f2f;
}

.button[data-stop] .button-icon {
  color: #c24141;
  font-size: 14px;
}

.button[data-reload] {
  border-color: #a9ddc0;
  background: #f1fbf6;
  color: #138a51;
}

.button[data-reload]:hover:not(:disabled) {
  border-color: #79c99d;
  background: #e8f8ef;
  color: #0f7043;
}

.button[data-reload] .button-icon {
  color: #138a51;
  font-size: 17px;
}

.help-control {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.help-button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: 50%;
  background: #ffffff;
  color: #63748b;
  cursor: help;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(36, 61, 92, 0.06);
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.help-button:hover,
.help-button:focus-visible {
  border-color: #b6c8dc;
  background: #f9fcff;
  color: #263b55;
  outline: none;
  box-shadow: 0 4px 12px rgba(36, 61, 92, 0.1);
}

.help-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  z-index: 40;
  width: 236px;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 8px;
  background: rgba(18, 29, 43, 0.97);
  color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 16px 36px rgba(14, 29, 46, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
}

.help-popover::before {
  content: "";
  position: absolute;
  top: -6px;
  left: calc(50% - 5px);
  width: 10px;
  height: 10px;
  border-left: 1px solid rgba(148, 163, 184, 0.28);
  border-top: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(18, 29, 43, 0.97);
  transform: rotate(45deg);
}

.help-control:hover .help-popover,
.help-control:focus-within .help-popover {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.help-popover-title {
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.2;
}

.help-popover-list {
  display: grid;
  gap: 4px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  line-height: 1.55;
}

.topbar-meta {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
}

.version {
  position: absolute;
  right: 18px;
  bottom: 7px;
  z-index: 3;
  color: #66758d;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

.status {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #d7e5f6;
  font-size: 18px;
  font-weight: 750;
  line-height: 1.25;
  text-align: center;
  letter-spacing: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.32);
}

.status[data-tone] {
  color: #d7e5f6;
  box-shadow: none;
}

.viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  padding: 0;
  background: #2d3b4c;
}

.preview-surface {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 0;
  overflow: hidden;
  background: #2d3b4c;
  clip-path: none;
}

.preview-frame {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 0;
  display: block;
  background: #2d3b4c;
}

.fullscreen-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 9;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(215, 225, 238, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: #52647a;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14);
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.fullscreen-button:hover {
  border-color: #b6c8dc;
  background: #ffffff;
  color: #263b55;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.18);
}

.viewer:fullscreen {
  padding: 0;
  background: #101821;
}

.viewer:fullscreen .preview-surface,
.viewer:fullscreen .idle-hint {
  inset: 0;
  border-radius: 0;
  clip-path: none;
}

.viewer:fullscreen .fullscreen-button {
  top: 16px;
  right: 16px;
}

.idle-hint {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border-radius: 0;
  background: #101821;
}

.idle-hint[hidden] {
  display: none !important;
}

.idle-logo {
  width: 118px;
  height: 118px;
  background: url("../TemplateData/unity-logo-dark.png") center / contain no-repeat;
  opacity: 0.92;
}

.idle-stack {
  display: grid;
  justify-items: center;
  gap: 28px;
  transform: translateY(-10px);
}

.idle-stack .status {
  max-width: min(420px, calc(100vw - 48px));
}

.loading-progress {
  width: 178px;
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-top: -12px;
}

.idle-stack:has(.status[data-tone="ready"]) .loading-progress {
  display: none;
}

.loading-progress-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.42);
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.86);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.24);
}

.loading-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #08aeea, #42d7a8);
  transition: width 0.18s ease;
}

.loading-progress[data-mode="indeterminate"] .loading-progress-bar {
  width: 42%;
  animation: loading-progress-sweep 1.15s ease-in-out infinite;
}

.loading-progress[data-mode="indeterminate"] .loading-progress-text {
  display: none;
}

@keyframes loading-progress-sweep {
  0% {
    transform: translateX(-115%);
  }

  100% {
    transform: translateX(245%);
  }
}

.loading-progress-text {
  color: #c9d7e8;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1;
}

.loading-shield {
  position: absolute;
  inset: 0;
  z-index: 12;
  background: transparent;
  cursor: wait;
}

.loading-shield[hidden] {
  display: none !important;
}

.loading-panel {
  width: min(620px, 100%);
  border: 1px solid rgba(151, 192, 244, 0.5);
  border-radius: 8px;
  padding: 14px 18px;
  background: rgba(18, 29, 43, 0.97);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
  text-align: center;
}

.loading-title {
  font-size: 18px;
  font-weight: 700;
}

.loading-detail {
  margin-top: 8px;
  color: #c9d7e8;
  font-size: 13px;
  line-height: 1.55;
}

.runner-error {
  position: absolute;
  left: 50%;
  bottom: 32px;
  z-index: 18;
  width: min(520px, calc(100% - 48px));
  padding: 16px;
  border: 1px solid rgba(248, 113, 113, 0.6);
  border-radius: 12px;
  display: grid;
  gap: 8px;
  background: rgba(31, 41, 55, 0.97);
  color: #ffffff;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  transform: translateX(-50%);
}

.runner-error code {
  color: #fca5a5;
  font-size: 12px;
}

.runner-error-actions {
  margin-top: 4px;
  display: flex;
  gap: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 700px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    align-items: stretch;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .scene-controls {
    grid-column: 1 / -1;
    align-items: start;
    flex-direction: column;
  }

  .scene-picker {
    width: 100%;
    min-width: 0;
  }

  .scene-popover,
  .manual-mode {
    width: 100%;
  }

  .scene-field {
    grid-column: 1 / -1;
  }

  .scene-input {
    width: 100%;
  }

  .status {
    width: 100%;
    min-width: 0;
  }

  .version {
    right: 0;
    bottom: -2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
