:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.68);
  --panel-border: rgba(17, 24, 39, 0.08);
  --text: rgba(17, 24, 39, 0.92);
  --muted: rgba(17, 24, 39, 0.62);
  --accent: #2563eb;
  --accent-2: #16a34a;
  --warning: #ea580c;
  --shadow: rgba(17, 24, 39, 0.1);
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  font-family: var(--font);
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#viewport {
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hud-title,
.program-panel,
.hud-bottom,
.hud-loading {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 10px 28px var(--shadow);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.hud-title {
  padding: 10px 12px;
  min-width: 160px;
}

.hud-title__main {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}

.hud-title__sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.program-panel {
  width: min(300px, calc(100vw - 28px));
  max-height: calc(100vh - 118px);
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.panel-section {
  display: grid;
  gap: 4px;
  padding-top: 1px;
}

.program-panel__row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.program-panel__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.program-panel__meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

.program-panel__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.program-panel__status {
  min-height: 16px;
  font-size: 11px;
  color: var(--muted);
}

.program-panel__status[data-state="error"] {
  color: var(--warning);
}

.program-list {
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr;
}

.program-list__row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 4px;
}

.program-list__item,
.program-list__empty,
.program-list__share {
  border-radius: 8px;
}

.program-list__item,
.program-list__share {
  appearance: none;
  border: 1px solid rgba(17, 24, 39, 0.08);
  background: rgba(255, 255, 255, 0.62);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.program-list__item {
  min-width: 0;
  text-align: left;
  font-size: 12px;
  padding: 6px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.program-list__share {
  display: grid;
  place-items: center;
  width: 28px;
  min-height: 28px;
  padding: 0;
}

.program-list__item:hover,
.program-list__share:hover {
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.28);
}

.program-list__item:active,
.program-list__share:active {
  transform: translateY(1px);
}

.program-list__item.is-active {
  border-color: rgba(17, 24, 39, 0.34);
  background: rgba(17, 24, 39, 0.06);
}

.program-list__row.is-active .program-list__share {
  border-color: rgba(17, 24, 39, 0.24);
  background: rgba(17, 24, 39, 0.04);
}

.copy-icon {
  position: relative;
  display: block;
  width: 14px;
  height: 14px;
}

.copy-icon::before,
.copy-icon::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
}

.copy-icon::before {
  left: 1px;
  top: 5px;
  opacity: 0.5;
}

.copy-icon::after {
  right: 1px;
  top: 1px;
}

.program-list__empty {
  padding: 8px 10px;
  background: rgba(17, 24, 39, 0.04);
  color: var(--muted);
  font-size: 12px;
}

.view-controls__views {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.view-button {
  appearance: none;
  border: 1px solid rgba(37, 99, 235, 0.24);
  background: rgba(37, 99, 235, 0.08);
  color: var(--text);
  border-radius: 7px;
  min-height: 28px;
  padding: 5px 4px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.view-button:hover {
  background: rgba(37, 99, 235, 0.14);
  border-color: rgba(37, 99, 235, 0.36);
}

.view-button:active {
  transform: translateY(1px);
}

.view-controls__toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.visibility-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  min-height: 28px;
  padding: 5px 7px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.visibility-toggle span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visibility-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.joint-panel {
  display: grid;
  gap: 4px;
  padding-top: 1px;
}

.panel-section__toggle,
.joint-panel__toggle {
  appearance: none;
  border: 1px solid rgba(17, 24, 39, 0.08);
  background: rgba(255, 255, 255, 0.62);
  color: var(--text);
  width: 100%;
  border-radius: 7px;
  padding: 6px 8px;
  text-align: left;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.panel-section__toggle::after,
.joint-panel__toggle::after {
  content: "+";
  float: right;
  color: var(--muted);
}

.panel-section.is-open .panel-section__toggle::after,
.joint-panel.is-open .joint-panel__toggle::after {
  content: "-";
}

.panel-section__body,
.joint-panel__body {
  display: grid;
  gap: 4px;
  padding: 1px 1px 0;
}

.panel-section__body[hidden],
.joint-panel__body[hidden] {
  display: none;
}

.joint-row {
  display: grid;
  grid-template-columns: 28px minmax(110px, 1fr) 46px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}

.joint-row__name {
  font-weight: 700;
  color: var(--text);
}

.joint-row input {
  width: 100%;
}

.joint-panel.is-readonly .joint-row input {
  opacity: 0.45;
  cursor: default;
}

.joint-row__value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.comment-panel {
  display: grid;
  gap: 5px;
  padding-top: 1px;
}

.comment-panel__bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
}

.comment-button,
.comment-toggle,
.comment-save,
.comment-cancel,
.comment-list__delete {
  appearance: none;
  border: 1px solid rgba(17, 24, 39, 0.1);
  background: rgba(255, 255, 255, 0.64);
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
}

.comment-button {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px;
  font-weight: 700;
  cursor: pointer;
}

.comment-icon {
  position: relative;
  width: 14px;
  height: 12px;
  border: 1.6px solid currentColor;
  border-radius: 5px;
}

.comment-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  bottom: -4px;
  width: 5px;
  height: 5px;
  border-left: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  background: rgba(255, 255, 255, 0.64);
  transform: skewY(-28deg);
}

.comment-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 5px 7px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
}

.comment-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #ef4444;
}

.comment-button:hover:not(:disabled),
.comment-save:hover:not(:disabled),
.comment-cancel:hover,
.comment-list__item:hover,
.comment-list__delete:hover {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.28);
}

.comment-button:disabled,
.comment-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.comment-composer {
  display: grid;
  gap: 7px;
}

.comment-composer[hidden],
.comment-list[hidden] {
  display: none;
}

.comment-range-readout {
  font-size: 11px;
  color: #b91c1c;
  font-variant-numeric: tabular-nums;
}

.comment-composer textarea {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px 9px;
}

.comment-composer textarea:focus,
.comment-range-handle:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.35);
  outline-offset: 2px;
}

.comment-composer__actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.comment-save,
.comment-cancel {
  padding: 7px 10px;
  cursor: pointer;
}

.comment-save {
  font-weight: 700;
  border-color: rgba(239, 68, 68, 0.36);
  color: #991b1b;
}

.comment-list {
  display: grid;
  gap: 6px;
  max-height: 150px;
  overflow: auto;
  padding-right: 1px;
}

.comment-list__item,
.comment-list__empty {
  border-radius: 8px;
}

.comment-list__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 7px;
  align-items: center;
  border: 1px solid rgba(17, 24, 39, 0.08);
  background: rgba(255, 255, 255, 0.58);
  padding: 8px;
  cursor: pointer;
}

.comment-list__time {
  font-size: 10px;
  color: #b91c1c;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.comment-list__text {
  margin-top: 2px;
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-list__delete {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
}

.comment-list__empty {
  padding: 9px 10px;
  background: rgba(17, 24, 39, 0.04);
  color: var(--muted);
  font-size: 12px;
}

.hud-bottom {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(17, 24, 39, 0.16);
  background: rgba(17, 24, 39, 0.03);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.hud-bottom .btn {
  width: 58px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  font-size: 12px;
  line-height: 1;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid currentColor;
  margin-left: 3px;
}

.pause-icon {
  width: 13px;
  height: 15px;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
}

.btn:hover:not(:disabled) {
  background: rgba(17, 24, 39, 0.06);
  border-color: rgba(17, 24, 39, 0.24);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-primary {
  border-color: rgba(37, 99, 235, 0.55);
  background: rgba(37, 99, 235, 0.1);
}

.btn-primary:hover:not(:disabled) {
  background: rgba(37, 99, 235, 0.16);
}

.timeline {
  flex: 1;
  min-width: 0;
}

.timeline__row {
  display: grid;
  grid-template-columns: 1fr 96px 78px;
  align-items: center;
  gap: 10px;
}

.timeline-stack {
  position: relative;
  min-width: 0;
  height: 38px;
  display: grid;
  align-items: center;
}

.timeline-stack input[type="range"] {
  position: relative;
  z-index: 2;
  margin: 0;
}

.comment-timeline,
.comment-range-editor {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.comment-timeline {
  z-index: 3;
}

.comment-range-editor {
  z-index: 4;
}

.comment-range-editor[hidden] {
  display: none;
}

.comment-timeline__band,
.comment-selection-fill {
  position: absolute;
  top: 27px;
  height: 5px;
  min-width: 4px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.72);
  box-shadow: 0 0 0 1px rgba(153, 27, 27, 0.12);
}

.comment-selection-fill {
  top: 25px;
  height: 8px;
  background: rgba(239, 68, 68, 0.9);
}

.comment-range-handle {
  position: absolute;
  top: 4px;
  width: 14px;
  height: 30px;
  padding: 0;
  border: 2px solid #ef4444;
  border-radius: 7px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(17, 24, 39, 0.18);
  transform: translateX(-50%);
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

input[type="range"] {
  width: 100%;
}

.select {
  width: 78px;
  appearance: none;
  border: 1px solid rgba(17, 24, 39, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 7px 28px 7px 10px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, rgba(17, 24, 39, 0.65) 50%),
    linear-gradient(135deg, rgba(17, 24, 39, 0.65) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.readout {
  font-size: 12px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.hud-loading {
  position: absolute;
  left: 14px;
  top: 76px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.hud-loading__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.hud-loading__detail {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.comment-runtime-popup {
  position: absolute;
  left: 50%;
  bottom: 82px;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 28px));
  max-height: 180px;
  overflow: auto;
  pointer-events: none;
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-left: 4px solid #ef4444;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 14px 32px rgba(17, 24, 39, 0.16);
  backdrop-filter: blur(10px);
  padding: 10px 12px;
  color: var(--text);
}

.comment-runtime-popup[hidden] {
  display: none;
}

.comment-runtime-popup__item + .comment-runtime-popup__item {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(17, 24, 39, 0.08);
}

.comment-runtime-popup__time {
  font-size: 11px;
  color: #b91c1c;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.comment-runtime-popup__text {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(17, 24, 39, 0.16);
  border-top-color: rgba(37, 99, 235, 0.85);
  animation: spin 0.9s linear infinite;
}

.hidden {
  display: none !important;
}

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

@media (max-width: 760px) {
  .hud-top {
    flex-direction: column;
    align-items: stretch;
  }

  .program-panel {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .hud-top {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .hud-title {
    padding: 10px 12px;
  }

  .hud-title__main {
    font-size: 13px;
  }

  .program-panel {
    padding: 10px;
  }

  .program-panel__row {
    flex-direction: column;
  }

  .program-panel__actions {
    width: 100%;
    justify-content: stretch;
  }

  .program-panel__actions .btn {
    flex: 1 1 0;
  }

  .comment-panel__bar {
    grid-template-columns: 1fr;
  }

  .comment-toggle {
    justify-content: center;
  }

  .hud-bottom {
    left: 10px;
    right: 10px;
    bottom: 10px;
    gap: 10px;
    padding: 10px;
  }

  .hud-bottom .btn {
    width: 54px;
    height: 38px;
  }

  .timeline__row {
    grid-template-columns: minmax(0, 1fr) 86px 76px;
    gap: 8px;
  }

  .select {
    width: 76px;
    padding-left: 8px;
  }

  .readout {
    font-size: 11px;
  }
}
