:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-2: #101820;
  --line: #243141;
  --line-strong: #3a4c60;
  --text: #eaf0f7;
  --muted: #95a3b5;
  --accent: #2fb4a9;
  --accent-2: #f2b84b;
  --danger: #e45f5f;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  font-family: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #17212b;
  color: var(--text);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--line-strong);
  background: #1d2a36;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel-2);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.15;
}

.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(47, 180, 169, 0.45);
  color: #9ee4dd;
  background: rgba(47, 180, 169, 0.1);
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.drop-zone {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 108px;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #101923;
}

.drop-zone.is-over {
  border-color: var(--accent);
  background: rgba(47, 180, 169, 0.08);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.drop-copy strong {
  font-size: 16px;
}

.drop-copy span {
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.primary {
  position: relative;
  z-index: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: #061112;
  font-weight: 700;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.compact {
  box-shadow: none;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 14px;
}

.layer-master-toggle {
  display: inline-grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101923;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 18px;
}

.text-button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.file-list,
.layer-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.file-row,
.layer-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101923;
}

.layer-row > div {
  min-width: 0;
  overflow: hidden;
}

.file-row {
  grid-template-columns: 1fr auto;
}

.layer-group-heading {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 4px 10px 0;
  color: #8aa1b6;
  font-size: 12px;
  letter-spacing: 0;
  cursor: pointer;
}

.layer-group-heading span {
  text-align: center;
}

.layer-order-controls {
  display: grid;
  grid-template-columns: repeat(2, 22px);
  gap: 4px;
}

.layer-order-button {
  display: inline-grid;
  place-items: center;
  width: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 4px;
  font-size: 10px;
  line-height: 1;
}

.file-row strong,
.layer-row strong {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
}

.layer-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-cn-alias {
  flex: 0 0 auto;
  color: #9fc3da;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.file-row span,
.layer-row .layer-meta {
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.22);
}

.swatch:hover,
.swatch:focus-visible {
  border-color: #ffffff;
  outline: 2px solid rgba(47, 180, 169, 0.28);
  outline-offset: 2px;
}

.layer-style-popover {
  position: fixed;
  z-index: 50;
  display: grid;
  gap: 12px;
  width: 220px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #111a23;
  box-shadow: var(--shadow);
}

.layer-style-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.layer-style-heading strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.layer-style-close {
  display: inline-grid;
  place-items: center;
  width: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 4px;
  font-size: 16px;
}

.layer-style-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.layer-style-field span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.layer-style-field b {
  color: var(--text);
  font-weight: 600;
}

.layer-style-field input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b1118;
}

.layer-style-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.layer-style-reset {
  width: 100%;
}

.layer-context-menu {
  position: fixed;
  z-index: 32;
  min-width: 128px;
  padding: 5px;
  border: 1px solid rgba(137, 156, 178, 0.45);
  border-radius: 6px;
  background: #f8fafc;
  color: #111827;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

.layer-context-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.layer-context-menu button:hover:not(:disabled) {
  background: #2d7df0;
  color: #fff;
}

.layer-context-menu button:disabled {
  color: #9ca3af;
  cursor: default;
}

.layer-toggle {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  box-shadow: none;
  background: var(--line);
}

.metrics div {
  display: grid;
  gap: 4px;
  padding: 12px;
  background: var(--panel);
}

.metrics span,
.inspector span {
  color: var(--muted);
  font-size: 12px;
}

.metrics strong,
.inspector strong {
  font-size: 14px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #0f151d;
  overflow-x: auto;
}

.tool-group {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.segmented {
  gap: 0;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111a23;
  white-space: nowrap;
}

.segmented button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.segmented button.is-active {
  background: var(--accent);
  color: #061112;
  font-weight: 700;
}

.export-group {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

.canvas-wrap.is-cam {
  background: #000;
}

.canvas-wrap.light {
  background: #f4f7f9;
}

.canvas-wrap.light.is-cam {
  background:
    linear-gradient(rgba(15, 30, 40, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 30, 40, 0.07) 1px, transparent 1px),
    #f4f7f9;
  background-size: 36px 36px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 20, 27, 0.92);
  text-align: center;
  pointer-events: none;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 8, 12, 0.58);
  backdrop-filter: blur(2px);
}

.loading-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  width: min(420px, calc(100% - 32px));
  padding: 16px;
  border: 1px solid rgba(124, 153, 184, 0.42);
  border-radius: 8px;
  background: rgba(15, 23, 32, 0.94);
  box-shadow: var(--shadow);
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(149, 163, 181, 0.28);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

.loading-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.loading-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.loading-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.loading-track {
  grid-column: 1 / -1;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(149, 163, 181, 0.18);
}

.loading-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.18s ease;
}

body.is-busy .drop-zone,
body.is-busy .toolbar {
  opacity: 0.72;
}

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

.canvas-empty strong {
  font-size: 20px;
}

.canvas-empty span,
.empty {
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}

.feature-tooltip {
  position: absolute;
  z-index: 3;
  max-width: min(340px, calc(100% - 28px));
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  background: rgba(11, 15, 20, 0.94);
  color: #f4f8fb;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.36);
  font-size: 12px;
  line-height: 1.55;
  pointer-events: none;
  white-space: normal;
}

.feature-tooltip strong {
  display: block;
  margin-bottom: 3px;
  color: #ffffff;
  font-size: 13px;
}

.hidden {
  display: none;
}

.inspector {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(560px, 4.6fr) minmax(200px, 1.4fr);
  gap: 1px;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.inspector div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  background: #0f151d;
}

.inspector strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspector div:nth-child(3) {
  justify-content: flex-start;
}

.inspector div:nth-child(3) strong {
  flex: 1;
  text-align: left;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}

.modal-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 96vw);
  max-height: min(760px, 88vh);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #101820;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.48);
  overflow: hidden;
}

.component-drawer,
.aperture-dialog {
  place-items: stretch end;
  padding: 0;
  pointer-events: none;
}

.component-drawer .modal-backdrop,
.aperture-dialog .modal-backdrop {
  background: rgba(0, 0, 0, 0.22);
  pointer-events: auto;
}

.component-drawer .component-panel,
.aperture-dialog .aperture-panel {
  width: min(560px, 92vw);
  height: 100vh;
  max-height: none;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-radius: 0;
  pointer-events: auto;
}

.aperture-dialog .aperture-panel {
  width: min(620px, 94vw);
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #131d27;
}

.modal-heading h2 {
  margin: 0;
  font-size: 16px;
}

.modal-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.component-table-wrap {
  min-height: 0;
  overflow: auto;
}

.aperture-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #101820;
  color: var(--text);
}

.aperture-panel .modal-heading {
  background: #131d27;
  border-bottom-color: var(--line);
}

.aperture-panel .modal-heading h2 {
  color: var(--text);
}

.aperture-panel .modal-heading p {
  color: var(--muted);
}

.aperture-table-wrap {
  min-height: 0;
  border: 0;
  overflow: auto;
  background: #101820;
}

.component-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.component-table th,
.component-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(58, 76, 96, 0.55);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.component-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #17212b;
  color: #dfe8f2;
  font-weight: 700;
}

.component-table td:last-child,
.component-table th:last-child {
  min-width: 280px;
  white-space: normal;
}

.component-table tbody tr:hover {
  background: rgba(47, 180, 169, 0.08);
}

.aperture-table th,
.aperture-table td {
  border-bottom-color: rgba(58, 76, 96, 0.55);
  color: var(--text);
}

.aperture-table th {
  background: #17212b;
  color: #dfe8f2;
}

.aperture-table td:last-child,
.aperture-table th:last-child {
  min-width: 72px;
  white-space: nowrap;
}

.component-row {
  cursor: pointer;
}

.component-row:focus {
  outline: 2px solid rgba(69, 233, 255, 0.72);
  outline-offset: -2px;
}

.component-row.is-selected {
  background: rgba(69, 233, 255, 0.14);
}

.component-row.is-selected td:first-child {
  color: #7ff4ff;
}

.component-empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.aperture-panel .component-empty {
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: #131d27;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 72vh;
  }

  .toolbar,
  .inspector {
    grid-template-columns: 1fr;
  }

  .inspector {
    display: grid;
  }
}
