/* Reset + shared controls (buttons, fields, sliders, tabs, menus, dialogs, toasts…). */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--bg-0);
  color: var(--text);
  font: 400 var(--fs-m) / 1.4 var(--font);
  font-feature-settings: "cv11", "ss03", "calt";
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
#app {
  height: 100%;
}
h1,
h2,
h3,
h4,
p {
  margin: 0;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
a {
  color: var(--accent);
}
::selection {
  background: var(--accent-soft);
}
.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;
}
.tnum {
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--text-2);
}
.faint {
  color: var(--text-3);
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.grow {
  flex: 1 1 auto;
  min-width: 0;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:focus {
  outline: none;
}
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-s);
}

/* scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--bg-5) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--bg-5);
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
  background-color: #485062;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

/* ---------------------------------------------------------------- icons */
.icon {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon.fill {
  fill: currentColor;
  stroke: none;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-3);
  color: var(--text);
  font-size: var(--fs-s);
  font-weight: 550;
  white-space: nowrap;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover {
  background: var(--bg-4);
  border-color: #454d5d;
}
.btn:active {
  background: var(--bg-5);
}
.btn[disabled],
.btn[aria-disabled="true"] {
  color: var(--text-disabled);
  background: var(--bg-2);
  border-color: var(--line);
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
}
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn.primary:active {
  background: var(--accent-press);
}
.btn.primary[disabled] {
  background: #33405f;
  border-color: #33405f;
  color: #8792b0;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn.ghost:hover {
  background: var(--bg-3);
  color: var(--text);
}
.btn.danger {
  color: var(--danger);
}
.btn.danger:hover {
  background: var(--danger-soft);
  border-color: rgba(255, 107, 110, 0.4);
}
.btn.large {
  height: 36px;
  padding: 0 16px;
  font-size: var(--fs-m);
}
.btn.small {
  height: 24px;
  padding: 0 8px;
  font-size: var(--fs-xs);
}
.btn.block {
  width: 100%;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  background: transparent;
  color: var(--text-2);
  flex: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}
.icon-btn:active {
  background: var(--bg-4);
}
.icon-btn[aria-pressed="true"],
.icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.icon-btn[disabled] {
  color: var(--text-disabled);
  cursor: not-allowed;
  background: transparent;
}
.icon-btn.small {
  width: 22px;
  height: 22px;
}
.icon-btn.small .icon {
  width: 14px;
  height: 14px;
}

.kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 14px;
  text-align: center;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field > label,
.label {
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 550;
  letter-spacing: 0.01em;
}
.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-0);
  color: var(--text);
  font-size: var(--fs-s);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.textarea {
  height: auto;
  min-height: 64px;
  padding: 6px 8px;
  line-height: 1.45;
  resize: vertical;
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: #485062;
}
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-radius: var(--radius-m);
}
.input[aria-invalid="true"] {
  border-color: var(--danger);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-3);
}
.select {
  appearance: none;
  padding-right: 24px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%23aeb5c2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.select option {
  background: var(--bg-2);
}
input[type="color"].swatch {
  width: var(--control-h);
  height: var(--control-h);
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-0);
  cursor: pointer;
}
input[type="color"].swatch::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"].swatch::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

/* number field with drag-to-scrub label */
.num {
  display: flex;
  align-items: center;
  height: var(--control-h);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-0);
  overflow: hidden;
}
.num:hover {
  border-color: #485062;
}
.num:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.num input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 6px;
  border: 0;
  background: transparent;
  font-size: var(--fs-s);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.num input:focus-visible {
  box-shadow: none;
}
.num .unit {
  padding-right: 7px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  user-select: none;
}
.num .scrub {
  align-self: stretch;
  display: grid;
  place-items: center;
  padding: 0 6px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: ew-resize;
  user-select: none;
  touch-action: none;
}

/* range slider */
.slider {
  appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}
.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) 0 var(--fill), var(--bg-5) var(--fill) 100%);
}
.slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-5);
}
.slider::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}
.slider::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}
.slider:focus-visible {
  box-shadow: none;
}
.slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--accent-line);
}
.slider:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 3px var(--accent-line);
}
.slider:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-s);
  cursor: pointer;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 30px;
  height: 18px;
  margin: 0;
  cursor: pointer;
}
.switch .track {
  width: 30px;
  height: 18px;
  border-radius: 9px;
  background: var(--bg-5);
  transition: background var(--dur-fast) var(--ease);
  flex: none;
  position: relative;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--dur-fast) var(--ease);
}
.switch input:checked + .track {
  background: var(--accent);
}
.switch input:checked + .track::after {
  transform: translateX(12px);
}
.switch input:focus-visible + .track {
  box-shadow: var(--focus-ring);
}

/* segmented control */
.seg {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius-m);
  background: var(--bg-0);
  border: 1px solid var(--line);
}
.seg button {
  height: 22px;
  padding: 0 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.seg button:hover {
  color: var(--text);
}
.seg button[aria-pressed="true"],
.seg button[aria-checked="true"] {
  background: var(--bg-4);
  color: var(--text);
}

/* ---------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 6px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  flex: none;
}
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: var(--fs-s);
  font-weight: 600;
  white-space: nowrap;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--text);
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}
.tab .count {
  padding: 0 5px;
  border-radius: 8px;
  background: var(--bg-4);
  color: var(--text-2);
  font-size: 10px;
  line-height: 15px;
}

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--bg-4);
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.success {
  background: var(--success-soft);
  color: var(--success);
}
.badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
}
.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge.fixture {
  background: repeating-linear-gradient(135deg, rgba(242, 184, 75, 0.22) 0 6px, rgba(242, 184, 75, 0.1) 6px 12px);
  color: var(--warning);
  border: 1px solid rgba(242, 184, 75, 0.45);
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- feedback */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--bg-5);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
.spinner.large {
  width: 28px;
  height: 28px;
  border-width: 3px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--accent);
    border-right-color: var(--accent);
  }
}
.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-4);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
  transition: width var(--dur) linear;
}
.progress.indeterminate > i {
  width: 35%;
  animation: slide 1.2s var(--ease) infinite;
}
@keyframes slide {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(300%);
  }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 20px;
  color: var(--text-2);
  text-align: center;
  min-height: 140px;
}
.empty .icon {
  width: 28px;
  height: 28px;
  color: var(--text-3);
  stroke-width: 1.3;
}
.empty h3 {
  color: var(--text);
  font-size: var(--fs-m);
  font-weight: 650;
}
.empty p {
  max-width: 34ch;
  font-size: var(--fs-s);
  line-height: 1.5;
}

.notice {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-2);
  color: var(--text-2);
  font-size: var(--fs-s);
  line-height: 1.45;
}
.notice .icon {
  margin-top: 1px;
}
.notice.error {
  border-color: rgba(255, 107, 110, 0.4);
  background: var(--danger-soft);
  color: #ffc9ca;
}
.notice.warning {
  border-color: rgba(242, 184, 75, 0.4);
  background: var(--warning-soft);
  color: #f7dca6;
}
.notice.info {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: #d5deff;
}
.notice strong {
  color: var(--text);
  font-weight: 650;
}

/* ---------------------------------------------------------------- menus */
.menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  max-width: 320px;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-l);
  background: var(--bg-2);
  box-shadow: var(--shadow-pop);
  animation: pop var(--dur-fast) var(--ease);
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-3px) scale(0.985);
  }
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-s);
  text-align: left;
  white-space: nowrap;
}
.menu-item .icon {
  color: var(--text-2);
  width: 15px;
  height: 15px;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--accent-soft);
  box-shadow: none;
}
.menu-item[disabled] {
  color: var(--text-disabled);
  cursor: default;
  background: transparent;
}
.menu-item[disabled] .icon {
  color: var(--text-disabled);
}
.menu-item.danger {
  color: var(--danger);
}
.menu-item.danger .icon {
  color: var(--danger);
}
.menu-item .hint {
  margin-left: auto;
  padding-left: 18px;
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.menu-item .check {
  margin-left: auto;
  color: var(--accent);
}
.menu-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--line);
}
.menu-label {
  padding: 6px 8px 3px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- dialogs */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 6, 9, 0.66);
  animation: fade var(--dur) var(--ease);
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.dialog {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: min(86vh, 760px);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg-1);
  box-shadow: var(--shadow-dialog);
  animation: rise var(--dur) var(--ease);
}
.dialog.wide {
  width: min(760px, 100%);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 {
  flex: 1;
  font-size: var(--fs-l);
  font-weight: 650;
}
.dialog-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-m);
  background: var(--bg-3);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-s);
  line-height: 1.45;
  pointer-events: auto;
  animation: rise var(--dur) var(--ease);
}
.toast.error {
  border-left-color: var(--danger);
}
.toast.success {
  border-left-color: var(--success);
}
.toast.warning {
  border-left-color: var(--warning);
}
.toast .body {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.toast .title {
  font-weight: 650;
}
.toast .detail {
  color: var(--text-2);
}

/* tooltips: [data-tip] on any control; shown on hover/focus after a short delay */
[data-tip] {
  position: relative;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 1200;
  left: 50%;
  top: calc(100% + 7px);
  transform: translateX(-50%);
  padding: 4px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #05070a;
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}
[data-tip][data-tip-pos="top"]::after {
  top: auto;
  bottom: calc(100% + 7px);
}
[data-tip][data-tip-pos="left"]::after {
  left: auto;
  right: 0;
  transform: none;
}
[data-tip][data-tip-pos="right"]::after {
  left: 0;
  transform: none;
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transition-delay: 450ms;
}

/* section headings used inside panels */
.section {
  border-bottom: 1px solid var(--line);
}
.section-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
}
button.section-head:hover {
  color: var(--text);
}
.section-head .chev {
  transition: transform var(--dur-fast) var(--ease);
}
.section-head[aria-expanded="false"] .chev {
  transform: rotate(-90deg);
}
.section-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 12px 14px;
}
.prop {
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
  gap: 8px;
  min-height: var(--control-h);
}
.prop > label,
.prop > .label {
  color: var(--text-2);
  font-size: var(--fs-s);
  font-weight: 450;
}
.prop .pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.prop .with-slider {
  display: grid;
  grid-template-columns: 1fr 68px;
  align-items: center;
  gap: 8px;
}
