:root {
  --bg: #ebe6dd;
  --bg-glow: #f8f4ec;
  --panel: #fbfaf7;
  --ink: #23201c;
  --muted: #7b736a;
  --line: #e2dcd2;
  --chip: #f1ede6;
  --accent: #23201c;
  --accent-ink: #fbfaf7;
  --gold: #b68a2e;
  --danger: #b0412e;
  --radius: 14px;
  --panel-w: 400px;
  font-family: "SF Pro Text", -apple-system, "PingFang SC", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1816;
    --bg-glow: #2a2622;
    --panel: #201e1b;
    --ink: #eee8de;
    --muted: #9a9187;
    --line: #34302b;
    --chip: #2a2723;
    --accent: #eee8de;
    --accent-ink: #1a1816;
    --gold: #d9b25a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  height: 100dvh;
  transition: grid-template-columns 0.45s cubic-bezier(.2,.8,.2,1);
}
.app[data-collapsed="true"] { grid-template-columns: 1fr 0px; }

/* 舞台 */
.stage {
  position: relative;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, var(--bg-glow), var(--bg) 70%);
  min-height: 0;
}
.stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  cursor: pointer; outline: none; touch-action: none;
}
.stage[data-dragging="true"] canvas { cursor: grabbing; }
.stage canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--gold); }

.hint {
  position: absolute; left: 0; right: 0; bottom: 22px; margin: 0;
  text-align: center; font-size: 13px; color: var(--muted);
  pointer-events: none; letter-spacing: 0.02em;
}
.viewer-head {
  position: absolute; top: 28px; left: 0; right: 0; text-align: center; pointer-events: none;
}
.viewer-kicker { margin: 0; font-family: "Fraunces", Georgia, serif; font-style: italic; font-size: 22px; color: var(--ink); }
.make-own {
  position: absolute; right: 20px; top: 20px; z-index: 2;
  padding: 9px 16px; border-radius: 999px; font-size: 14px;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
}
.panel-toggle {
  position: absolute; right: 16px; top: 16px; z-index: 2;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(8px); border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.fail {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 24px;
  text-align: center; color: var(--muted);
}
.drop-overlay {
  position: absolute; inset: 14px; z-index: 3; display: grid; place-items: center;
  border: 2px dashed var(--gold); border-radius: 22px;
  background: color-mix(in srgb, var(--bg-glow) 85%, transparent);
  font-family: "Fraunces", Georgia, serif; font-size: 22px; font-style: italic; color: var(--ink);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.app[data-dropping="true"] .drop-overlay { opacity: 1; }

/* 面板 */
.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden;
  min-width: 0;
}
.panel > * { width: var(--panel-w); }
.head { padding: 30px 28px 6px; }
.head h1 {
  margin: 0; font-family: "Fraunces", Georgia, serif; font-weight: 500; font-size: 34px; letter-spacing: -0.01em;
  background: linear-gradient(100deg, #8a6420, #e9c873 35%, #a87b26 55%, #f2d98c 75%, #8a6420);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.head h1 a { color: inherit; text-decoration: none; }
.head-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lang { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--chip); flex: none; }
.lang button {
  border: 0; background: none; border-radius: 999px; padding: 5px 11px; font-size: 12.5px;
  color: var(--muted); cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.sub { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

.section { padding: 20px 28px; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; padding-bottom: 36px; }
.section h2 {
  display: flex; align-items: center; gap: 10px; margin: 0 0 14px;
  font-size: 15px; font-weight: 600;
}
.n {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); font-size: 12px; font-weight: 500; color: var(--muted);
}
.picked { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 13px; }
.surprise { margin-left: auto; }

.link {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--gold); font-size: 13px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px;
}

.cover { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: start; }
.proof-wrap { position: relative; line-height: 0; }
.proof {
  display: block; width: auto; height: auto; max-width: 150px; max-height: 150px;
  border-radius: 6px; cursor: crosshair;
  box-shadow: 0 0 0 1px var(--line), 0 8px 16px -10px rgba(17, 17, 20, 0.45);
}
.cover-side { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.cover-side .note { margin: 0; }
.upload { display: inline-flex; align-items: center; gap: 8px; align-self: start; padding: 8px 14px; }
.upload:hover { border-color: var(--gold); }
.dominant { margin-top: 12px; }
.thumbs {
  display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -2px;
  scrollbar-width: thin;
}
.thumb {
  flex: none; width: 74px; display: grid; justify-items: center; align-content: start; gap: 5px;
  padding: 0; border: 0; background: none; cursor: pointer;
  font-size: 11.5px; line-height: 1.25; text-align: center; color: var(--muted);
}
.thumb canvas { max-width: 74px; }
.thumb canvas {
  width: auto; height: 76px; border-radius: 4px;
  box-shadow: 0 0 0 1px var(--line), 0 4px 10px -6px rgba(17, 17, 20, 0.5);
  transition: transform 0.15s;
}
.thumb:hover canvas { transform: translateY(-2px); }
.thumb[aria-checked="true"] { color: var(--ink); }
.thumb[aria-checked="true"] canvas { box-shadow: 0 0 0 2px var(--ink); }
.error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }

.row { margin-top: 14px; display: grid; gap: 8px; }
.label { font-size: 12px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid transparent; background: var(--chip); border-radius: 999px;
  padding: 7px 13px; font-size: 13px; cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.chip:hover { border-color: var(--line); }
.chip[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

.swatches { gap: 10px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.5), 0 1px 2px rgba(0,0,0,0.12);
  outline-offset: 3px;
}
.swatch[aria-checked="true"] { outline: 2px solid var(--ink); }
.swatches.small .swatch { width: 26px; height: 26px; }

.note { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.pick-dot {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.4); pointer-events: none;
}

.range { display: grid; gap: 6px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.range input { width: 100%; accent-color: var(--gold); }
.check { display: flex; gap: 8px; align-items: center; margin-top: 14px; font-size: 13.5px; cursor: pointer; }
.check input { accent-color: var(--gold); width: 16px; height: 16px; }

textarea, input[type="text"], .url {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-glow);
  padding: 10px 12px; font-size: 14px; line-height: 1.5; resize: vertical;
}
textarea { font-family: "Caveat", "Kaiti SC", "STKaiti", cursive; font-size: 20px; line-height: 1.35; }
input[type="text"] { margin-top: 8px; }
textarea:focus, input:focus-visible { outline: 2px solid color-mix(in srgb, var(--gold) 60%, transparent); outline-offset: 1px; }

.button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 10px 18px; font-size: 14px; cursor: pointer;
}
.button.primary {
  width: 100%; padding: 13px; border: 0; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.button:disabled { opacity: 0.6; cursor: progress; }
.share-box { margin-top: 14px; display: grid; gap: 10px; }
.actions { display: flex; gap: 8px; }
.stale { color: var(--danger); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 查看模式：只剩卡片 */
.app[data-mode="view"] { grid-template-columns: 1fr; }
.app[data-mode="view"] .panel,
.app[data-mode="view"] .panel-toggle { display: none; }

@media (max-width: 820px) {
  body { overflow: auto; }
  .app, .app[data-collapsed="true"] { display: block; height: auto; }
  .stage { position: sticky; top: 0; height: 58dvh; z-index: 1; }
  .app[data-mode="view"] .stage { height: 100dvh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .panel > * { width: auto; }
  .head, .section { padding-left: 16px; padding-right: 16px; }
  .panel-toggle { display: none; }
}
