:root {
  --bg: #f5f2ea;
  --surface: #fffefb;
  --ink: #1f2a22;
  --muted: #667066;
  --line: #e0dccf;
  --accent: #2f5d35;
  --accent-ink: #ffffff;
  --accent-soft: #e5eee3;
  --danger: #b3261e;
  --warn: #8a5a00;
  --check-a: #ffffff;
  --check-b: #ebe8df;
  --shadow: 0 1px 2px rgba(31, 42, 34, .06), 0 6px 20px rgba(31, 42, 34, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121714;
    --surface: #1a211c;
    --ink: #e8ede8;
    --muted: #94a095;
    --line: #2b352d;
    --accent: #7fb687;
    --accent-ink: #0f1a11;
    --accent-soft: #223127;
    --danger: #ff8a80;
    --warn: #f0c36a;
    --check-a: #2a302b;
    --check-b: #232924;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  --bg: #121714;
  --surface: #1a211c;
  --ink: #e8ede8;
  --muted: #94a095;
  --line: #2b352d;
  --accent: #7fb687;
  --accent-ink: #0f1a11;
  --accent-soft: #223127;
  --danger: #ff8a80;
  --warn: #f0c36a;
  --check-a: #2a302b;
  --check-b: #232924;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* header */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-in { display: flex; align-items: center; justify-content: space-between; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 12px; margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: .01em; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 38px; border-radius: 6px;
  background: #fdfdfb; color: #252c8c; border: 1.5px solid #cdcdc6;
  font-size: 1.05rem; font-weight: 700; line-height: 1;
}
.top-actions { display: flex; gap: 8px; }

/* cards */
main.wrap { padding-top: 24px; padding-bottom: 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.label { display: block; margin: 0 0 8px; font-size: .85rem; font-weight: 650; color: var(--muted); letter-spacing: .04em; }

/* input */
.tile-input {
  width: 100%;
  padding: 12px 14px;
  font: 1.15rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.tile-input:focus-visible, button:focus-visible, select:focus-visible, input[type=range]:focus-visible, .swatch:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.status { min-height: 1.6em; margin: 8px 0 0; font-size: .9rem; color: var(--muted); }
.status.error { color: var(--danger); }
.status.warn { color: var(--warn); }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.chips-label { font-size: .85rem; color: var(--muted); margin-right: 2px; }
.chip {
  padding: 4px 12px; font-size: .88rem; color: var(--ink);
  background: var(--accent-soft); border: 1px solid transparent; border-radius: 999px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }

/* preview */
.preview {
  position: relative;
  min-height: 96px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    conic-gradient(var(--check-b) 25%, var(--check-a) 0 50%, var(--check-b) 0 75%, var(--check-a) 0) 0 0 / 20px 20px;
  display: flex;
  padding: 14px 18px;
}
.preview-inner { margin: auto; line-height: 0; }
.preview-inner svg { display: block; max-width: none; }
.empty { margin: auto; color: var(--muted); text-align: center; }
.preview.has-tiles .empty { display: none; }
.preview:not(.has-tiles) .preview-inner { display: none; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.toast:empty { display: none; }
.toast { margin: 8px 0 0; font-size: .9rem; color: var(--accent); }

/* buttons */
button, select {
  font: inherit; color: var(--ink);
}
.actions button, .ghost {
  padding: 9px 16px; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer;
}
.actions button:hover:not(:disabled), .ghost:hover { border-color: var(--accent); }
.actions .primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.actions .primary:hover:not(:disabled) { filter: brightness(1.08); }
.actions button:disabled { opacity: .45; cursor: not-allowed; }
.ghost { padding: 6px 12px; font-size: .9rem; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }

/* options */
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px 24px; }
.opt { display: grid; gap: 6px; align-content: start; font-size: .92rem; }
.opt label, .opt-title { color: var(--muted); font-size: .85rem; }
.opt select {
  padding: 8px 10px; background: var(--bg); border: 1.5px solid var(--line); border-radius: 8px;
}
.opt input[type=range] { width: 100%; accent-color: var(--accent); }
.opt-check { align-content: end; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink) !important; font-size: .95rem !important; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.swatches { display: flex; gap: 10px; }
.swatch {
  width: 34px; height: 42px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--line); padding: 0;
}
.swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* help */
.help summary { cursor: pointer; font-weight: 650; }
.help-body { margin-top: 12px; color: var(--ink); font-size: .95rem; }
.help-body p { margin: 8px 0; }
.help-body ul { margin: 8px 0; padding-left: 1.2em; }
.help-body code {
  padding: 1px 6px; font: .9em ui-monospace, Menlo, Consolas, monospace;
  background: var(--accent-soft); border-radius: 5px;
}

.foot { padding-top: 8px; padding-bottom: 32px; color: var(--muted); }

@media (max-width: 520px) {
  .card { padding: 14px; }
  .actions button { flex: 1 1 calc(50% - 5px); }
}
@media (prefers-reduced-motion: no-preference) {
  .chip, button, .swatch { transition: border-color .12s, filter .12s; }
}
