:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e5ea;
  --text: #1c2129;
  --muted: #6b7380;
  --accent: #2c6bed;
  --accent-text: #ffffff;
  --input: #ffffff;
  --stage: #e9ebef;
  --hover: #f0f3f8;
  --sel: #e5eeff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --panel: #1d2026;
    --line: #2d313a;
    --text: #e6e8ec;
    --muted: #8d95a3;
    --accent: #4d86ff;
    --input: #23272e;
    --stage: #111316;
    --hover: #252a33;
    --sel: #213152;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
code { font-size: 12px; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.top .brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }
.top nav { display: flex; gap: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center-text { text-align: center; }
.sr-only { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Layout */
.editor {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr minmax(300px, 360px);
  gap: 16px;
  padding: 16px;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.center { position: sticky; top: 64px; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr 1fr; }
  .center { grid-column: 1 / -1; grid-row: 1; position: static; }
}
@media (max-width: 700px) {
  .editor { grid-template-columns: 1fr; padding: 12px 16px; }
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.panel > summary, .sub > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 2px 0 6px;
  list-style-position: inside;
}
.sub { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 6px; }
.sub > summary { font-weight: 500; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }

.row {
  display: grid;
  grid-template-columns: 84px 1fr auto;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
}
.row > span:first-child { color: var(--muted); }
.row.check { grid-template-columns: 1fr auto; }
.row input[type="text"], .row input[type="url"], .row input[type="search"], .row select {
  grid-column: span 1;
  min-width: 0;
}
.row > :last-child:nth-child(2) { grid-column: 2 / -1; }

input, select, button, .button {
  font: inherit;
  color: var(--text);
}
input[type="text"], input[type="url"], input[type="search"], input[type="number"], select {
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input.num { width: 64px; }
input.hex { width: 92px; font-family: ui-monospace, monospace; font-size: 12px; }
input[type="color"] {
  width: 100%;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px;
  background: var(--input);
}

button, .button {
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--hover); }
button:disabled { opacity: 0.35; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.primary:hover { background: var(--accent); filter: brightness(1.08); }

.actions { display: flex; gap: 8px; align-items: center; margin: 8px 0 4px; }
.actions.wrap { flex-wrap: wrap; }
.status { padding: 6px 8px; border-radius: 6px; background: var(--sel); margin: 6px 0; word-break: break-word; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}
.palette { margin-top: 8px; }

/* Stage */
.stage-tools { display: flex; justify-content: space-between; align-items: center; }
.chip { display: inline-flex; gap: 6px; align-items: center; }
.stage {
  background: var(--stage);
  border-radius: 14px;
  padding: 28px 16px;
  display: flex;
  justify-content: center;
}
.stage.checker {
  background: repeating-conic-gradient(#d4d7dd 0% 25%, #ffffff 0% 50%) 50% / 20px 20px;
}
.preview { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.preview .big svg { width: min(300px, 70vw); height: auto; display: block; }
.minis { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; justify-content: center; }
.mini { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px; border-radius: 10px; }
.mini span { font-size: 11px; color: #8d95a3; }
.mini.light { background: #ffffff; }
.mini.dark { background: #1b1d22; }
.mini svg { display: block; }

/* Layers */
.layers .add { display: flex; gap: 4px; flex-wrap: wrap; }
.layers .add button { padding: 3px 7px; font-size: 12px; }
.layers ul { list-style: none; margin: 0; padding: 0; }
.layer {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.layer:hover { background: var(--hover); }
.layer.selected { background: var(--sel); }
.layer.hidden .label, .layer.hidden .thumb { opacity: 0.4; }
.layer .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .thumb { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 5px; background: var(--input); border: 1px solid var(--line); overflow: hidden; }
.layer .thumb img { max-width: 22px; max-height: 22px; }
.layer .thumb .sq { width: 12px; height: 12px; background: var(--muted); border-radius: 2px; }
.layer .ops { display: flex; gap: 2px; }
.layer .ops button { padding: 1px 5px; font-size: 11px; border-color: transparent; background: transparent; }
.layer .ops button:hover:not(:disabled) { background: var(--panel); border-color: var(--line); }


#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 90, 0.35);
  display: grid;
  place-items: center;
  z-index: 20;
  pointer-events: none;
}
#drop-overlay[hidden] { display: none; }
#drop-overlay div { background: var(--panel); padding: 18px 26px; border-radius: 12px; font-size: 16px; font-weight: 600; }

/* Matrix */
.matrix { padding: 16px; max-width: 1100px; margin: 0 auto; }
.matrix h1 { margin: 4px 0; font-size: 20px; }
.matrix form.inline { display: flex; gap: 8px; max-width: 520px; margin: 10px 0 16px; }
.grid { border-collapse: separate; border-spacing: 12px; }
.grid th { text-align: left; font-weight: 600; vertical-align: middle; }
.grid thead th { text-align: center; }
.grid th.fam { min-width: 150px; }
.grid .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.grid td a { display: block; border-radius: 34px; transition: transform 0.12s; }
.grid td a:hover { transform: scale(1.04); }
.grid td svg { display: block; width: 150px; height: 150px; }
@media (max-width: 700px) {
  .grid td svg { width: 64px; height: 64px; }
  .grid { border-spacing: 6px; }
  .grid th.fam { min-width: 0; }
}

/* Reference icons */
.refs { margin-bottom: 28px; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; margin-top: 12px; }
.ref { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.ref .pair { display: flex; gap: 12px; justify-content: center; background: var(--stage); border-radius: 10px; padding: 12px 8px 6px; }
.ref .pair > div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ref img, .ref svg { display: block; width: 150px; height: 150px; }
.ref a { display: block; border-radius: 34px; transition: transform 0.12s; }
.ref a:hover { transform: scale(1.04); }
.ref figcaption { margin-top: 8px; }
.ref code { word-break: break-all; }
@media (max-width: 700px) {
  .ref-grid { grid-template-columns: 1fr; }
  .ref img, .ref svg { width: 120px; height: 120px; }
}

/* Glyph dialog */
.gp {
  width: min(1040px, calc(100vw - 32px));
  height: min(760px, calc(100vh - 32px));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.gp::backdrop { background: rgba(10, 14, 22, 0.45); }
.gp-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "head head" "cats main" "foot foot";
  height: 100%;
}
.gp-head { grid-area: head; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.gp-head h2 { font-size: 15px; margin: 0; white-space: nowrap; }
.gp-head input { flex: 1; min-width: 0; }
.gp-x { border-color: transparent; background: transparent; font-size: 15px; }
.gp-sets { display: flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; gap: 2px; flex-shrink: 0; }
.gp-sets button { border-color: transparent; background: transparent; padding: 4px 10px; border-radius: 6px; font-size: 12.5px; }
.gp-sets button.on { background: var(--sel); color: var(--accent); }
.gp-cats { grid-area: cats; overflow: auto; padding: 8px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 1px; }
.gp-cats button {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  text-align: left;
  border-color: transparent;
  background: transparent;
  padding: 5px 8px;
}
.gp-cats button .t { overflow: hidden; text-overflow: ellipsis; }
.gp-cats button .n { color: var(--muted); font-size: 11px; }
.gp-cats button.on { background: var(--sel); }
.gp-main { grid-area: main; overflow: auto; padding: 10px 14px; min-height: 0; }
.gp-info { margin: 0 0 8px; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; }
.linkish:hover { background: none; text-decoration: underline; }
.gp-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.gp-items button {
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 12px 4px 8px;
  border-color: transparent;
  background: var(--bg);
  white-space: normal;
  min-width: 0;
}
.gp-items button:hover { border-color: var(--line); }
.gp-items svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.gp-items svg.filled { fill: currentColor; stroke: none; }
.gp-items button span {
  font-size: 10.5px;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gp-foot { grid-area: foot; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.gp-preview { width: 56px; height: 56px; flex: none; }
.gp-preview svg { width: 56px; height: 56px; display: block; }
.gp-sel { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.gp-sel b { font-family: ui-monospace, monospace; font-size: 12px; }
@media (max-width: 700px) {
  .gp { width: 100vw; height: 100vh; max-height: 100dvh; border-radius: 0; }
  .gp-shell { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; grid-template-areas: "head" "cats" "main" "foot"; }
  .gp-head h2 { display: none; }
  .gp-cats { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .gp-cats { gap: 4px; }
  .gp-cats button { grid-template-columns: 16px auto; white-space: nowrap; }
  .gp-cats button .t { overflow: visible; }
  .gp-cats button .n { display: none; }
  .gp-items { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
  .gp-sel span { display: none; }
}
