:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface2: #eef0f3;
  --text: #16181b;
  --muted: #5d6470;
  --line: #dcdfe5;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e3edfd;
  --danger: #c4312b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --mono: ui-monospace, Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface2: #1f232b;
  --text: #e6e8eb;
  --muted: #9aa3af;
  --line: #2c313a;
  --accent: #5b9dff;
  --accent-ink: #0b0d10;
  --accent-soft: #1b2a44;
  --danger: #ff7b72;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code, .mono { font-family: var(--mono); }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }
.grow { flex: 1 1 auto; }

/* header */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.backlink { text-decoration: none; color: var(--muted); }
.backlink:hover { color: var(--text); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }

/* buttons */
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 7px 12px; color: var(--text); background: none; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, .dropzone:focus-visible, pre:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.07); }
.secondary { background: var(--surface2); border-color: var(--line); }
.secondary:hover:not(:disabled) { border-color: var(--muted); }
.ghost { border-color: var(--line); }
.ghost:hover:not(:disabled) { background: var(--surface2); }
.ghost.small { padding: 5px 10px; font-size: 13px; }
.iconbtn { width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1; }

main { max-width: 1320px; margin: 0 auto; padding: 0 20px 40px; }
.hero { padding: 28px 0 18px; }
.hero h1 { font-size: clamp(26px, 3.4vw, 38px); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.01em; }
.lede { margin: 0; color: var(--muted); max-width: 760px; font-size: 16px; }

/* workspace */
.workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 4px 16px 16px; }
.block { padding: 12px 0; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.block h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center;
  border: 2px dashed var(--line); border-radius: 12px; padding: 18px 12px; cursor: pointer; background: var(--surface2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.row { display: flex; align-items: center; }
.gap { gap: 8px; margin-top: 10px; }
.examples { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.thumb { padding: 0; border: 2px solid var(--line); border-radius: 8px; overflow: hidden; line-height: 0; }
.thumb:hover { border-color: var(--accent); }
.thumb img { display: block; width: 72px; height: 48px; object-fit: cover; }
#srcInfo { margin: 8px 0 0; min-height: 1em; word-break: break-all; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; background: var(--surface); }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; background: var(--surface2); }
.seg label { flex: 1 1 0; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 6px 8px; border-radius: 7px; font-size: 14px; user-select: none; }
.seg input:checked + span { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small span { padding: 4px 12px; font-size: 13px; }

.field { margin-top: 12px; }
.field > label, .field .labelrow label, .field.two label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.labelrow { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.labelrow label { margin-bottom: 0 !important; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
select, input[type="text"], input[type="number"] {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
#custom { margin-top: 6px; }
#colsNum { width: 64px; padding: 2px 6px; text-align: right; font-family: var(--mono); font-size: 13px; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
output { color: var(--muted); }
.checks { display: flex; gap: 18px; margin: 12px 0; font-size: 14px; }
.checks input { accent-color: var(--accent); }

/* stage */
.stage { min-width: 0; position: sticky; top: 70px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tools button { padding: 6px 11px; font-size: 14px; }
.cambar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.live { width: 9px; height: 9px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 3px rgba(229, 72, 77, .25); }

.output {
  position: relative; border-radius: 14px; border: 1px solid var(--line); overflow: auto;
  background: #0b0d10; min-height: 260px; max-height: calc(100vh - 190px);
  display: flex; align-items: flex-start; justify-content: center; box-shadow: var(--shadow);
}
.output[data-paper="light"] { background: #ffffff; }
#art { display: block; width: 100%; height: auto; image-rendering: auto; }
.arttext {
  margin: 0; padding: 12px; width: 100%; font-family: var(--mono); line-height: 1.2; letter-spacing: 0;
  white-space: pre; color: #e6e8eb; background: #0b0d10; overflow: auto;
}
.arttext[data-paper="light"] { color: #16181b; background: #ffffff; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9aa3af; }
#stats { margin: 8px 2px 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; margin: 0;
  transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

/* about */
.about { margin-top: 40px; padding-top: 8px; border-top: 1px solid var(--line); }
.about h2 { font-size: 22px; margin: 20px 0 8px; }
.about h3 { font-size: 16px; margin: 16px 0 6px; }
.about p, .about li { color: var(--muted); }
.cols3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.tips { padding-left: 20px; margin: 6px 0 0; }
.tips li { margin: 4px 0; }

.footer { max-width: 1320px; margin: 0 auto; padding: 16px 20px 32px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .stage { position: static; order: -1; }
  .output { max-height: 70vh; min-height: 200px; }
  .cols3 { grid-template-columns: 1fr; gap: 4px; }
}
@media (max-width: 560px) {
  main { padding: 0 16px 32px; }
  .topbar { padding: 8px 16px; }
  .badge { display: none; }
  .hero { padding: 18px 0 12px; }
  .lede { font-size: 15px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .tools { display: grid; grid-template-columns: repeat(4, 1fr); }
  .tools #copyBtn, .tools #copyFenceBtn { grid-column: span 2; }
  .footer { flex-direction: column; padding: 16px; }
}
