:root {
  color-scheme: light;
  --bg: #f5f7ff;
  --surface: #ffffff;
  --surface-soft: #eef2ff;
  --surface-blue: #eaf6ff;
  --line: #dbe3ff;
  --ink: #24304f;
  --muted: #687494;
  --brand: #7b8cff;
  --brand-strong: #6474ef;
  --accent: #b99cff;
  --shadow: 0 20px 60px rgba(95, 112, 190, 0.18);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(234, 246, 255, 0.9), rgba(247, 241, 255, 0.88)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(360px, 1fr) minmax(270px, 330px);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.library-panel,
.controls-panel,
.preview-card,
.drop-zone,
.control-group {
  border: 1px solid rgba(219, 227, 255, 0.9);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.library-panel,
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: 28px;
  padding: 18px;
}

.workspace {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
}

.workspace-header,
.panel-heading,
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading.compact {
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 18px;
}

.library-help {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.soft-input,
.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 9px 12px;
  outline: none;
}

.soft-input:focus,
.field input:focus,
.field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(123, 140, 255, 0.16);
}

.field small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.primary-button,
.secondary-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 18px;
  padding: 10px 16px;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  box-shadow: 0 12px 28px rgba(123, 140, 255, 0.28);
}

.secondary-button {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.compact-button {
  width: auto;
  min-width: 104px;
}

.secondary-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.drop-zone {
  display: grid;
  min-height: 178px;
  place-items: center;
  border-radius: 28px;
  border-style: dashed;
}

.drop-zone.is-dragging {
  border-color: var(--brand);
  background: rgba(238, 242, 255, 0.96);
}

.drop-copy {
  display: grid;
  width: min(100%, 620px);
  gap: 10px;
  text-align: center;
}

.drop-copy > span,
.empty-state,
.preview-stats {
  color: var(--muted);
  font-size: 14px;
}

.native-upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 4px;
}

.native-file-card {
  position: relative;
  display: grid;
  min-height: 58px;
  place-items: center;
  overflow: hidden;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  box-shadow: 0 12px 28px rgba(123, 140, 255, 0.22);
  color: #fff;
  font-weight: 800;
}

.native-file-card input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.01;
  cursor: pointer;
  font-size: 80px;
}

.fallback-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  padding: 9px;
}

.upload-status {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 700;
}

.preview-card {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 16px;
  border-radius: 30px;
  padding: 18px;
}

.canvas-frame {
  display: grid;
  min-height: 420px;
  flex: 1;
  place-items: center;
  overflow: auto;
  border-radius: 24px;
  background:
    linear-gradient(45deg, rgba(219, 227, 255, 0.45) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(219, 227, 255, 0.45) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(219, 227, 255, 0.45) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(219, 227, 255, 0.45) 75%);
  background-color: #fff;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

canvas {
  width: min(100%, 720px);
  height: auto;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 14px 36px rgba(36, 48, 79, 0.12);
}

.control-group {
  display: grid;
  gap: 12px;
  border-radius: 24px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 16px;
  background: var(--surface-blue);
  padding: 8px 10px;
  color: var(--ink);
}

.source-note {
  border-radius: 16px;
  background: var(--surface-blue);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
}

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

.custom-row {
  display: grid;
  grid-template-columns: 1fr 1fr 44px 64px;
  gap: 8px;
}

.custom-row input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px 9px;
}

.custom-color-list {
  display: grid;
  gap: 8px;
}

.custom-color-pill {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  padding: 7px;
  color: var(--muted);
  font-size: 13px;
}

.project-list,
.palette-list {
  display: grid;
  gap: 10px;
  overflow: auto;
}

.project-card,
.palette-row {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.78);
  padding: 10px;
}

.project-card {
  grid-template-columns: 58px 1fr;
  align-items: center;
}

.project-thumb {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  object-fit: cover;
  background: var(--surface-soft);
}

.project-meta {
  min-width: 0;
}

.project-title {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.project-actions {
  display: flex;
  grid-column: 1 / -1;
  gap: 8px;
}

.mini-button {
  flex: 1;
  min-height: 32px;
  border-radius: 13px;
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 700;
}

.palette-row {
  grid-template-columns: 34px 1fr auto;
  align-items: center;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(36, 48, 79, 0.12);
  border-radius: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  transform: translateY(20px);
  border-radius: 18px;
  background: rgba(36, 48, 79, 0.92);
  color: #fff;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  transition: 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.print-area {
  display: none;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 260px minmax(360px, 1fr);
  }

  .controls-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .library-panel,
  .controls-panel {
    border-radius: 24px;
  }

  .controls-panel {
    display: flex;
  }

  .workspace-header,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .compact-button {
    width: 100%;
  }

  .native-upload-grid {
    grid-template-columns: 1fr;
  }

  .canvas-frame {
    min-height: 320px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell,
  .toast {
    display: none !important;
  }

  .print-area {
    display: block;
    color: #111;
    font-family: Arial, sans-serif;
  }

  .print-page {
    break-after: page;
    padding: 18mm;
  }

  .print-page:last-child {
    break-after: auto;
  }

  .print-page img {
    max-width: 100%;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #999;
    padding: 6px;
    text-align: left;
  }
}
