@font-face {
  font-family: "StarCandy";
  src: url("./assets/star-candy.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #2b1f1c;
  --muted: #72645f;
  --cream: #fffaf0;
  --paper: #fffefb;
  --yellow: #ffbd36;
  --yellow-deep: #f0a700;
  --coral: #ff755f;
  --blue: #7fc8eb;
  --line: #2b1f1c;
  --shadow: 7px 8px 0 rgba(43, 31, 28, 0.13);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 189, 54, .16) 0 9%, transparent 9.2%),
    linear-gradient(180deg, #fff9ea 0, #fffdf8 32rem, #f9f7f1 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}

button, input, textarea, select { font: inherit; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 12px clamp(18px, 4vw, 60px) 14px;
  border-bottom: 2px solid rgba(43, 31, 28, .12);
  background: rgba(255, 250, 240, .9);
  backdrop-filter: blur(14px);
}
.header-inner { display: flex; width: min(1440px, 100%); margin: 0 auto; align-items: flex-start; flex-direction: column; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: StarCandy, sans-serif; font-size: 1.35rem; text-decoration: none; }
.brand-star { display: grid; place-items: center; width: 38px; height: 38px; border: 2px solid var(--line); border-radius: 13px; background: var(--yellow); transform: rotate(-7deg); box-shadow: 3px 3px 0 var(--ink); }
.workspace-tabs { display: flex; gap: 8px; padding: 4px; border: 2px solid var(--line); border-radius: 15px; background: white; }
.workspace-tab { min-width: 116px; padding: 9px 18px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); font-weight: 900; cursor: pointer; }
.workspace-tab:hover { background: #fff3cf; }
.workspace-tab[aria-selected="true"] { background: var(--yellow); box-shadow: inset 0 0 0 2px var(--line); }

main { width: min(1440px, calc(100% - 36px)); margin: 0 auto; padding: clamp(24px, 4vw, 48px) 0 clamp(60px, 8vw, 100px); }
h2 { font-family: StarCandy, "PingFang SC", sans-serif; font-weight: 400; }
h2 { margin: 10px 0 26px; font-size: clamp(2rem, 3vw, 3.1rem); line-height: 1.08; }
[hidden] { display: none !important; }
.tab-panel { animation: panel-in .2s ease-out; }
@keyframes panel-in { from { opacity: .35; translate: 10px 0; } to { opacity: 1; translate: 0 0; } }

.editor-shell { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, .8fr); overflow: hidden; border: 3px solid var(--line); border-radius: 34px; background: var(--paper); box-shadow: var(--shadow); }
.editor-preview { padding: clamp(20px, 3vw, 38px); border-right: 3px solid var(--line); background: #ffe8a8; }
.section-kicker { display: flex; align-items: center; gap: 10px; font-size: .84rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.section-kicker span { display: grid; place-items: center; width: 34px; height: 26px; border: 2px solid var(--line); border-radius: 50%; background: white; letter-spacing: 0; }
.canvas-stage { position: relative; display: grid; place-items: center; min-height: 460px; margin-top: 18px; padding: 24px; overflow: hidden; border: 2px solid var(--line); border-radius: 24px; background-color: white; background-image: linear-gradient(45deg,#f0eee9 25%,transparent 25%),linear-gradient(-45deg,#f0eee9 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#f0eee9 75%),linear-gradient(-45deg,transparent 75%,#f0eee9 75%); background-size: 24px 24px; background-position: 0 0,0 12px,12px -12px,-12px 0; }
canvas { display: block; width: 100%; height: auto; max-height: 64vh; object-fit: contain; cursor: grab; filter: drop-shadow(0 12px 13px rgba(65, 41, 20, .15)); touch-action: none; }
canvas.dragging { cursor: grabbing; }
.drag-tip { position: absolute; left: 50%; bottom: 12px; translate: -50%; padding: 7px 12px; border-radius: 99px; background: rgba(43, 31, 28, .82); color: white; font-size: .78rem; pointer-events: none; transition: opacity .25s; }
.preview-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; color: #5d4d47; font-size: .82rem; font-weight: 700; }
.editor-panel { padding: clamp(24px, 4vw, 46px); }
.field-label { display: block; margin: 18px 0 8px; font-weight: 900; }
select, textarea, .search-box input { width: 100%; border: 2px solid var(--line); border-radius: 14px; background: white; color: var(--ink); outline: none; }
select { height: 48px; padding: 0 14px; }
textarea { min-height: 96px; padding: 13px 14px; resize: vertical; font: 400 1.45rem/1.45 StarCandy, sans-serif; }
select:focus, textarea:focus, input:focus-visible { box-shadow: 0 0 0 4px rgba(127, 200, 235, .4); }
.text-hint { display: flex; justify-content: flex-end; margin-top: 7px; color: var(--muted); font-size: .78rem; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px 18px; margin-top: 22px; }
.control-grid label { font-size: .84rem; font-weight: 850; }
.control-grid output { float: right; color: #a14a36; }
input[type="range"] { width: 100%; margin-top: 9px; accent-color: var(--coral); }
.style-row { display: flex; align-items: center; gap: 16px; margin: 24px 0; }
.color-field { display: flex; align-items: center; gap: 10px; font-weight: 850; }
input[type="color"] { width: 46px; height: 38px; padding: 2px; border: 2px solid var(--line); border-radius: 10px; background: white; }
.editor-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.button { min-height: 50px; padding: 0 18px; border: 2px solid var(--line); border-radius: 14px; color: var(--ink); font-weight: 900; cursor: pointer; box-shadow: 3px 4px 0 var(--ink); transition: translate .15s, box-shadow .15s; }
.button:hover { translate: 0 -2px; box-shadow: 4px 6px 0 var(--ink); }
.button:active { translate: 2px 3px; box-shadow: 1px 1px 0 var(--ink); }
.button.primary { background: var(--yellow); }
.button.secondary { background: white; }

.library { padding: 4px 0 0; }
.library-tools { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.search-box { width: min(330px, 100%); flex: 0 0 min(330px, 100%); }
.search-box input { height: 50px; padding: 0 18px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }
.filter-button { padding: 9px 17px; border: 2px solid var(--line); border-radius: 99px; background: white; font-weight: 850; cursor: pointer; }
.filter-button[aria-pressed="true"] { background: var(--ink); color: white; }
.batch-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 18px 0 10px; padding: 13px 14px; border: 2px solid var(--line); border-radius: 16px; background: white; }
.batch-selection { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; }
.batch-check { display: inline-flex; align-items: center; gap: 9px; font-weight: 850; cursor: pointer; }
.batch-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--coral); }
.text-button { padding: 6px 2px; border: 0; border-bottom: 2px solid currentColor; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; }
.text-button:disabled { opacity: .38; cursor: default; }
.batch-download { min-height: 44px; white-space: nowrap; }
.button:disabled { opacity: .46; cursor: not-allowed; box-shadow: none; translate: 0; }
.result-count { margin: 0 0 18px; color: var(--muted); font-size: .9rem; }
.asset-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.asset-card { position: relative; display: flex; flex-direction: column; overflow: hidden; min-width: 0; border: 2px solid var(--line); border-radius: 20px; background: white; box-shadow: 4px 5px 0 rgba(43,31,28,.12); transition: border-color .18s, box-shadow .18s; }
.asset-card.is-selected { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255,117,95,.2), 4px 5px 0 rgba(43,31,28,.12); }
.asset-thumb { display: grid; place-items: center; aspect-ratio: 1 / 1; padding: clamp(22px, 2.2vw, 34px); overflow: hidden; border-bottom: 2px solid var(--line); background-color: #faf8f1; background-image: radial-gradient(#e5dfd3 1px, transparent 1px); background-size: 12px 12px; }
.asset-thumb img { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .24s ease; }
.asset-card:hover img { transform: translateY(-2px); }
.asset-select { position: absolute; top: 10px; right: 10px; z-index: 2; display: grid; place-items: center; width: 38px; height: 38px; border: 2px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.94); cursor: pointer; box-shadow: 2px 3px 0 rgba(43,31,28,.18); }
.asset-select input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.asset-select span { display: grid; place-items: center; width: 24px; height: 24px; border: 2px solid var(--line); border-radius: 7px; color: transparent; font-size: 1rem; font-weight: 950; line-height: 1; }
.asset-select input:focus-visible + span { box-shadow: 0 0 0 4px rgba(127,200,235,.5); }
.asset-select input:checked + span { background: var(--coral); color: white; }
.asset-body { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px; }
.asset-title { min-width: 0; }
.asset-title strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-title span { color: var(--muted); font-size: .75rem; }
.card-actions { display: flex; flex-shrink: 0; gap: 7px; }
.icon-button { display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 0 10px; border: 2px solid var(--line); border-radius: 12px; background: var(--yellow); color: var(--ink); font-size: .78rem; font-weight: 900; text-decoration: none; cursor: pointer; }
.icon-button.edit { background: var(--blue); }
.empty-state { padding: 60px 20px; border: 2px dashed #baada4; border-radius: 20px; color: var(--muted); text-align: center; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 28px clamp(18px, 4vw, 60px); border-top: 2px solid var(--line); background: var(--yellow); font-weight: 900; }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 50; translate: -50% 20px; padding: 12px 18px; border: 2px solid var(--line); border-radius: 14px; background: var(--ink); color: white; opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s; }
.toast.show { translate: -50% 0; opacity: 1; }

@media (min-width: 1051px) {
  body.panel-editor-active {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
  }
  body.panel-editor-active main {
    display: grid;
    height: 100%;
    min-height: 0;
    padding: 14px 0 18px;
  }
  body.panel-editor-active .editor-shell { height: 100%; min-height: 0; }
  body.panel-editor-active .editor-preview { display: flex; min-height: 0; padding: clamp(14px, 1.8vw, 25px); flex-direction: column; }
  body.panel-editor-active .canvas-stage { min-height: 0; margin-top: 10px; padding: 12px; flex: 1; }
  body.panel-editor-active canvas { position: absolute; inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); max-width: none; max-height: none; object-fit: contain; }
  body.panel-editor-active .preview-meta { margin-top: 7px; }
  body.panel-editor-active .editor-panel { min-height: 0; padding: clamp(18px, 2.2vw, 30px); }
  body.panel-editor-active .editor-panel h2 { margin: 5px 0 13px; font-size: clamp(1.7rem, 2.25vw, 2.4rem); }
  body.panel-editor-active .field-label { margin: 10px 0 5px; }
  body.panel-editor-active select { height: 42px; }
  body.panel-editor-active textarea { min-height: 72px; padding: 9px 12px; font-size: 1.2rem; line-height: 1.35; }
  body.panel-editor-active .text-hint { margin-top: 5px; }
  body.panel-editor-active .control-grid { gap: 10px 16px; margin-top: 13px; }
  body.panel-editor-active .control-grid input[type="range"] { margin-top: 5px; }
  body.panel-editor-active .style-row { margin: 13px 0; }
  body.panel-editor-active .button { min-height: 44px; }
  body.panel-editor-active footer { display: none; }
}

@media (max-width: 1050px) {
  .editor-shell { grid-template-columns: 1fr; }
  .editor-preview { border-right: 0; border-bottom: 3px solid var(--line); }
  .asset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  main { width: min(100% - 24px, 1440px); }
  .site-header { padding: 10px 14px 12px; }
  .brand { font-size: 1.05rem; }
  .brand-star { width: 32px; height: 32px; }
  .header-inner { gap: 10px; }
  .workspace-tabs { width: 100%; }
  .workspace-tab { flex: 1; min-width: 0; padding: 9px 12px; }
  .editor-shell { border-radius: 24px; }
  .editor-preview { padding: 16px; }
  .canvas-stage { min-height: 260px; padding: 10px; border-radius: 17px; }
  .preview-meta { display: grid; }
  .editor-panel { padding: 24px 18px 28px; }
  .control-grid { grid-template-columns: 1fr; }
  .style-row { align-items: start; flex-direction: column; }
  .editor-actions { grid-template-columns: 1fr; }
  .library-tools { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; flex-basis: auto; order: -1; }
  .batch-toolbar { align-items: stretch; flex-direction: column; }
  .batch-download { width: 100%; }
  .asset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .asset-thumb { padding: 22px; }
  .asset-body { align-items: start; flex-direction: column; }
  .card-actions { width: 100%; }
  .icon-button { flex: 1; }
}

@media (max-width: 420px) {
  .asset-grid { grid-template-columns: 1fr; }
  footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
