:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #657283;
  --line: #d7dde5;
  --soft-line: #e8edf2;
  --panel: #ffffff;
  --page: #f5f7f9;
  --accent: #d8a414;
  --accent-strong: #b77c00;
  --steel: #6f7881;
  --green: #226857;
  --danger: #b94832;
  --shadow: 0 18px 42px rgba(24, 32, 42, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 360px) minmax(620px, 1fr);
  height: 100vh;
  min-height: 620px;
}

.panel {
  position: relative;
  z-index: 2;
  overflow: hidden;
  background: var(--panel);
  border-color: var(--line);
}

.module-panel {
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--soft-line);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 3px solid var(--steel);
  border-radius: 8px;
  background: linear-gradient(135deg, #f1bd19, #f5d86d);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.55);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.tool-section {
  padding: 10px 16px;
  border-bottom: 1px solid var(--soft-line);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tool-section h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.module-palette {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.module-button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 72px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  user-select: none;
}

.module-button:active {
  cursor: grabbing;
}

.module-button:hover,
.preset-card:hover,
.sequence-item:hover {
  border-color: #aab4c0;
  box-shadow: 0 8px 18px rgba(24, 32, 42, 0.08);
}

.module-number {
  display: grid;
  place-items: center;
  width: 20px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #27313d;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.module-thumb {
  display: grid;
  place-items: center;
  width: 100%;
  height: 42px;
  overflow: hidden;
  border-radius: 6px;
  background: #eef2f5;
}

.module-thumb img,
.module-thumb svg {
  width: 100%;
  height: 100%;
}

.module-thumb img {
  object-fit: cover;
  object-position: center;
}

.module-thumb svg {
  display: block;
  padding: 4px;
}

.module-tile-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.module-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-size,
.module-type {
  color: var(--muted);
  font-size: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-card {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.preset-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #eef2f5;
}

.preset-card span {
  font-size: 11px;
  font-weight: 800;
}

.workspace {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.18)),
    #edf1f4;
}

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

.viewport-toolbar {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.view-actions,
.toolbar-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(140, 151, 163, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.ghost-button,
.toolbar-button,
.icon-button,
.primary-button,
.danger-button,
.sequence-control {
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
}

.toolbar-button {
  min-width: 58px;
  justify-content: center;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-color: var(--soft-line);
  background: #fff;
  font-size: 20px;
  line-height: 1;
}

.ghost-button {
  padding: 6px 9px;
  border-color: var(--line);
  color: var(--muted);
  font-size: 12px;
}

.primary-button {
  width: 100%;
  margin-top: 10px;
  padding: 11px 12px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

.secondary-button {
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.secondary-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.danger-button {
  padding: 8px 12px;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.selection-hud {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 36px);
  padding: 8px 8px 8px 12px;
  border: 1px solid rgba(140, 151, 163, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.selection-hud.is-hidden {
  display: none;
}

.edge-add-button {
  display: none;
  border-color: rgba(34, 104, 87, 0.22);
  background: rgba(34, 104, 87, 0.08);
  color: var(--green);
}

.edge-add-button.is-visible {
  display: inline-grid;
  place-items: center;
}

.selection-hud span {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading-state {
  position: absolute;
  left: 50%;
  bottom: 78px;
  z-index: 3;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(140, 151, 163, 0.26);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  box-shadow: var(--shadow);
}

.loading-state.is-hidden {
  display: none;
}

.drop-hint {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.drop-hint.is-hidden {
  display: none;
}

.drop-hint div {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 110px;
  min-height: 44px;
  padding: 10px 14px;
  border: 2px dashed rgba(34, 104, 87, 0.22);
  border-radius: 8px;
  background: rgba(34, 104, 87, 0.06);
  color: var(--green);
  font-size: 14px;
  font-weight: 900;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  transform: translate(-50%, -50%);
}

.drop-hint [data-drop-side="left"],
.drop-hint [data-drop-side="right"] {
  display: none;
}

.drop-hint [data-drop-side="left"].is-active,
.drop-hint [data-drop-side="right"].is-active {
  display: grid;
}

.drop-hint [data-drop-side="replace"] {
  left: 50%;
  top: 50%;
  display: none;
  min-width: 180px;
  min-height: 76px;
  padding: 18px 24px;
  border-radius: 8px;
  transform: translate(-50%, -50%);
}

.drop-hint.is-replace {
  display: block;
}

.drop-hint.is-replace [data-drop-side="left"],
.drop-hint.is-replace [data-drop-side="right"] {
  display: none;
}

.drop-hint.is-replace [data-drop-side="replace"] {
  display: grid;
}

.drop-hint div.is-active {
  border-color: rgba(34, 104, 87, 0.74);
  background: rgba(34, 104, 87, 0.13);
}

.file-warning {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  display: grid;
  gap: 7px;
  width: min(440px, calc(100% - 48px));
  padding: 18px 20px;
  border: 1px solid #e2b756;
  border-radius: 8px;
  background: rgba(255, 248, 224, 0.96);
  box-shadow: var(--shadow);
  color: #4b3911;
  transform: translate(-50%, -50%);
}

.file-warning.is-hidden {
  display: none;
}

.is-file-mode .file-warning {
  display: grid;
}

.is-file-mode .loading-state {
  display: none;
}

.file-warning strong {
  font-size: 16px;
}

.file-warning span {
  font-size: 13px;
  line-height: 1.6;
}

.sequence-list {
  display: grid;
  gap: 9px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed #bdc6cf;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.sequence-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sequence-item strong {
  display: block;
  font-size: 13px;
}

.sequence-item span {
  color: var(--muted);
  font-size: 12px;
}

.sequence-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sequence-control {
  display: grid;
  place-items: center;
  width: 28px;
  aspect-ratio: 1;
  border-color: var(--soft-line);
  background: #f8fafb;
  color: var(--muted);
  line-height: 1;
}

.sequence-control.remove {
  color: var(--danger);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.metrics div {
  min-width: 0;
  padding: 8px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metrics dt {
  color: var(--muted);
  font-size: 11px;
}

.metrics dd {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: #26313c;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.color-button {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 5px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.color-button.is-active {
  border-color: #17202a;
  box-shadow: inset 0 0 0 2px #17202a;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 2.2;
  border: 1px solid rgba(24, 32, 42, 0.16);
  border-radius: 5px;
}

.fabric-swatch {
  background-image:
    linear-gradient(35deg, rgba(255, 255, 255, 0.24), transparent 38%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.18) 0 1px, rgba(0, 0, 0, 0.08) 1px 3px);
  background-blend-mode: soft-light, multiply;
}

.fabric-picker {
  display: grid;
  gap: 10px;
}

.fabric-selected {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-weight: 800;
}

.fabric-selected-preview {
  display: block;
  width: 58px;
  aspect-ratio: 1.25;
  border: 1px solid rgba(24, 32, 42, 0.14);
  border-radius: 6px;
  background-color: #d5d8da;
  background-position: center;
  background-size: cover;
}

.fabric-selected small {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.fabric-selected strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fabric-categories {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  max-height: 118px;
  overflow-y: auto;
  padding-right: 2px;
}

.fabric-category {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.fabric-category span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fabric-category small {
  color: var(--muted);
  font-size: 10px;
}

.fabric-category.is-active {
  border-color: #17202a;
  background: #17202a;
  color: #fff;
}

.fabric-category.is-active small {
  color: rgba(255, 255, 255, 0.72);
}

.fabric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 2px;
}

.fabric-button {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.fabric-button.is-active {
  border-color: #17202a;
  box-shadow: inset 0 0 0 2px #17202a;
}

.fabric-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1.18;
  border: 1px solid rgba(24, 32, 42, 0.12);
  border-radius: 6px;
  background-color: #d5d8da;
  background-position: center;
  background-size: cover;
}

.fabric-button span:last-child {
  overflow: hidden;
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-button span:last-child {
  overflow: hidden;
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-panel {
  display: grid;
  gap: 10px;
}

.selected-info {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.selected-info.has-selection {
  border-color: rgba(34, 104, 87, 0.32);
  background: rgba(34, 104, 87, 0.07);
  color: var(--ink);
}

.select-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.select-field select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.edit-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .panel {
    max-height: none;
    border: 0;
  }

  .workspace {
    height: 62vh;
    min-height: 420px;
    order: -1;
  }

  .viewport-toolbar {
    flex-wrap: wrap;
  }
}
