:root {
  --ink: #10213f;
  --muted: #60708f;
  --navy: #082a57;
  --blue: #126eeb;
  --green: #10b981;
  --orange: #f97316;
  --paper: #ffffff;
  --soft: #f5f7fb;
  --line: #dfe7f2;
  --shadow: 0 18px 50px rgba(15, 35, 70, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--soft);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", Arial, sans-serif;
}

.topbar {
  height: 88px;
  background: linear-gradient(90deg, #061f43, #0b3972);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  box-shadow: 0 8px 22px rgba(6, 31, 67, .22);
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #ff8a2a, #ffbd61);
  color: #082a57;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, .12);
}

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

.brand p {
  margin: 4px 0 0;
  color: #d8e6f7;
  font-size: 14px;
}

.top-actions,
.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  min-height: 38px;
  padding: 0 16px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--blue);
  box-shadow: 0 8px 20px rgba(18, 110, 235, .14);
}

button:active,
button.pulse {
  transform: translateY(1px) scale(.98);
}

.primary-btn {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
}

.success-btn {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.ghost-btn {
  background: rgba(255, 255, 255, .08);
  color: white;
  border-color: rgba(255, 255, 255, .25);
}

.wide { width: 100%; }
.hidden { display: none !important; }

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  padding: 22px;
}

.editor-panel,
.showcase,
.part-panel,
.viewer-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  max-height: calc(100vh - 132px);
  overflow: auto;
}

.panel-section {
  border: 1px solid var(--line);
  padding: 14px;
  background: #fff;
}

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

.section-title small,
.hint {
  color: var(--muted);
  font-weight: 500;
}

label {
  display: grid;
  gap: 7px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(18, 110, 235, .12);
}

.page-list {
  display: grid;
  gap: 10px;
}

.page-card {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #f9fbfe;
  cursor: grab;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.page-card:hover,
.page-card.active {
  border-color: var(--blue);
  background: #edf5ff;
}

.page-card.dragging {
  opacity: .55;
  transform: scale(.98);
}

.page-index {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--navy);
  color: white;
  border-radius: 6px;
  font-weight: 900;
}

.page-card strong,
.texture-chip strong,
.part-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-page {
  position: absolute;
  right: -8px;
  top: -8px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 8px 18px rgba(239, 68, 68, .25);
  cursor: pointer;
}

.texture-shelf {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.texture-chip {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  background: #f9fbfe;
  cursor: grab;
}

.texture-thumb {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #e5e7eb, #fff);
  object-fit: cover;
}

.showcase {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  gap: 14px;
  padding: 18px;
  min-width: 0;
}

.hero-info {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-weight: 900;
  font-size: 12px;
  text-transform: uppercase;
}

.hero-info h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.hero-info p {
  margin: 6px 0 0;
  color: var(--muted);
}

.viewer-status {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: #f9fbfe;
  color: var(--muted);
  border-radius: 6px;
  white-space: nowrap;
}

.viewer-wrap {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  background:
    linear-gradient(rgba(15, 35, 70, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 35, 70, .06) 1px, transparent 1px),
    #eef3f9;
  background-size: 34px 34px;
}

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

.drop-hint {
  pointer-events: none;
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.viewer-wrap.drop-ready,
.part-row.drop-ready {
  outline: 3px solid rgba(18, 110, 235, .35);
  outline-offset: -3px;
}

.part-panel {
  padding: 14px;
  box-shadow: none;
}

.part-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.part-row {
  padding: 10px;
  border: 1px solid var(--line);
  background: #f9fbfe;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.part-row:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.part-row small {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  padding: 12px 16px;
  background: var(--ink);
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease;
  z-index: 10;
}

@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    height: auto;
    min-height: 88px;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
  }

  .editor-panel {
    max-height: none;
  }
}
