:root {
  --bg: #121212;
  --surface: #1b1b1b;
  --surface-2: #242424;
  --line: #2e2e2e;
  --text: #ececec;
  --muted: #9a9a9a;
  --accent: #d9b26f;
  --accent-2: #67b1a6;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { font-weight: 600; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand small { color: var(--accent); font-weight: 500; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: conic-gradient(var(--accent), var(--accent-2), var(--accent)); }
.actions { display: flex; gap: 8px; }
.btn {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; white-space: nowrap; user-select: none; -webkit-user-select: none; touch-action: none;
}
.btn:hover:not(:disabled) { border-color: #444; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: #1a1408; border-color: var(--accent); font-weight: 600; }

.layout { flex: 1; display: flex; min-height: 0; }
.stage {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 0; padding: 16px;
}
#canvas { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; box-shadow: 0 8px 40px rgba(0,0,0,.5); touch-action: none; }
.drop {
  width: 100%; max-width: 520px; aspect-ratio: 4 / 3; border: 1.5px dashed #3a3a3a; border-radius: 18px;
  display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer; transition: border-color .2s, background .2s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(217,178,111,.05); }
.drop-icon { color: var(--accent); margin-bottom: 8px; }
.drop-title { font-size: 16px; margin: 0 0 4px; }
.drop-sub { color: var(--muted); margin: 0; font-size: 13px; padding: 0 16px; }
.badge {
  position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.65); padding: 3px 12px; border-radius: 999px; font-size: 12px; pointer-events: none;
}
.status {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.72); padding: 6px 14px; border-radius: 999px; font-size: 12px; color: #ddd; white-space: nowrap; pointer-events: none;
}

.panel {
  width: 340px; flex: none; border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; background: none; border: 0; padding: 12px 0; color: var(--muted); cursor: pointer; position: relative; }
.tab.active { color: var(--text); }
.tab.active::after { content: ""; position: absolute; left: 30%; right: 30%; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.pane { display: none; overflow-y: auto; padding: 14px 16px; flex: 1; min-height: 0; }
.pane.active { display: block; }
.panel-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex: none; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; }
.tip { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }

.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.preset {
  background: var(--surface-2); border: 1.5px solid transparent; border-radius: 10px; padding: 0 0 6px; cursor: pointer; overflow: hidden; font-size: 12px;
}
.preset canvas { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #2a2a2a; margin-bottom: 4px; }
.preset.active { border-color: var(--accent); }

.slider { margin-bottom: 12px; }
.slider-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 2px; }
.slider-head span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; }
.group-title { font-size: 12px; color: var(--accent); margin: 14px 0 8px; letter-spacing: .04em; }
.group-title:first-child { margin-top: 0; }

input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; height: 22px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: linear-gradient(to right, var(--accent) var(--fill, 50%), #3a3a3a var(--fill, 50%)); border-radius: 3px; }
input[type=range]::-moz-range-track { height: 3px; background: #3a3a3a; border-radius: 3px; }
input[type=range]::-moz-range-progress { height: 3px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #f2f2f2; margin-top: -6.5px; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #f2f2f2; }
input[type=range]:disabled { opacity: .35; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; outline: 2px solid transparent; outline-offset: 2px; }
.swatch.active { outline-color: var(--text); }


.btn.icon { padding: 6px 9px; display: inline-flex; align-items: center; }
.stage { flex-direction: column; gap: 20px; }
.recent { width: 100%; max-width: 520px; }
.recent-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.recent-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.recent-list .card-thumb { aspect-ratio: 1; }

.drawer-mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); z-index: 21;
  background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease; padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-hint { padding: 10px 16px 0; margin: 0; }
.history-grid { flex: 1; overflow-y: auto; padding: 12px 16px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; align-content: start; }
.drawer-foot { padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.link.danger { color: #e0796e; }
.empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 40px 0; font-size: 13px; }

.card { position: relative; background: var(--surface-2); border: 1.5px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; }
.card.current { border-color: var(--accent); }
.card-thumb { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: #2a2a2a; }
.card-meta { padding: 6px 8px 8px; font-size: 12px; line-height: 1.35; }
.card-meta b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta span { color: var(--muted); }
.card-del {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1;
}
.recent-list .card-meta { display: none; }
.recent-list .card-del { display: none; }

.tpl-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 8px; }
.tpl-head .group-title { margin: 0; }
.tpl-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tpl-list:empty { display: none; }
.tpl { display: inline-flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.tpl-apply { background: none; border: 0; padding: 5px 4px 5px 12px; cursor: pointer; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.tpl-apply:hover { color: var(--accent); }
.tpl-del { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 5px 10px 5px 6px; font-size: 14px; line-height: 1; }
.tpl-del:hover { color: #e0796e; }
@media (max-width: 760px) {
  .recent-list { grid-template-columns: repeat(4, 1fr); }
  .recent-list .card:nth-child(n+5) { display: none; }
  .actions { gap: 6px; }
  #btnCompare { display: none; }
  .layout { flex-direction: column; }
  .stage { padding: 8px; flex: 1 1 auto; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); height: 42vh; flex: none; }
  .brand small { display: none; }
  .btn { padding: 6px 12px; }
  .drop { aspect-ratio: auto; height: 100%; max-height: 360px; }
}
