:root {
  color-scheme: dark;
  --accent: hsl(330 100% 50%);
  --accent-hover: hsl(330 100% 58%);
  --accent-soft: hsl(330 100% 50% / 0.14);
  --accent-line: hsl(330 100% 50% / 0.55);
  --bg: hsl(330 6% 6%);
  --panel: hsl(330 6% 9%);
  --raised: hsl(330 6% 12%);
  --line: hsl(330 6% 18%);
  --line-strong: hsl(330 6% 26%);
  --text: hsl(330 12% 92%);
  --muted: hsl(330 5% 60%);
  --faint: hsl(330 5% 40%);
  --warn: hsl(40 95% 62%);
  --error: hsl(5 90% 64%);
  --info: hsl(200 80% 66%);
  --guide-base: hsl(200 90% 60%);
  --guide-xh: hsl(150 60% 50%);
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --preview-font: system-ui;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  min-width: 960px;
}
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: 0.92em; color: var(--text); background: var(--raised); padding: 0.05em 0.35em; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 13px; margin: 22px 0 10px; color: var(--text); }
h3 .muted { font-weight: 400; margin-left: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- controls ---------- */
button, .file-btn {
  font: inherit; color: inherit; cursor: pointer;
  border-radius: 6px; border: 1px solid transparent;
  padding: 6px 12px; background: none; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
button.ghost, .file-btn.ghost { border-color: var(--line-strong); background: var(--raised); }
button.ghost:hover, .file-btn.ghost:hover { border-color: var(--accent-line); }
button.small, .file-btn.small { padding: 4px 10px; font-size: 12.5px; }
button.big { padding: 10px 18px; font-size: 15px; }
button:disabled { opacity: 0.5; cursor: default; }
button.icon { padding: 4px 8px; color: var(--muted); }
button.icon:hover { color: var(--text); background: var(--raised); }

input[type="text"], input[type="number"], input[type="url"], select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 6px 8px; width: 100%; min-width: 0;
}
input[type="number"] { font-family: var(--mono); font-size: 13px; }
textarea { resize: vertical; min-height: 56px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }
select { padding-right: 24px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }
.toggle:hover { color: var(--text); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.logo { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); box-shadow: 0 0 18px hsl(330 100% 50% / 0.45); }
.project { display: flex; align-items: center; gap: 10px; margin-left: 12px; padding-left: 14px; border-left: 1px solid var(--line); }
.folder { font-weight: 600; }
.folder::before { content: "▸ "; color: var(--accent); }
#svg-select { width: auto; max-width: 220px; padding: 4px 24px 4px 8px; font-size: 13px; }
.status { color: var(--muted); font-size: 12.5px; }
.status.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--accent); animation: pulse 0.9s infinite alternate; }
@keyframes pulse { to { opacity: 0.25; } }
.spacer { flex: 1; }
.export { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; letter-spacing: 0.02em; }
.seg label + label span { border-left: 1px solid var(--line-strong); }
.seg input:checked + span { background: var(--accent-soft); color: var(--accent-hover); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- empty state ---------- */
.empty { flex: 1; display: grid; place-items: center; padding: 40px; }
.empty-card { max-width: 620px; }
.empty-card h1 { font-size: 30px; line-height: 1.15; margin-bottom: 14px; }
.empty-card > p { color: var(--muted); font-size: 15px; margin: 0 0 24px; }
.empty-actions { display: flex; gap: 10px; margin-bottom: 28px; }
.hints { margin: 0; padding: 18px 18px 18px 34px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); }
.hints li + li { margin-top: 8px; }
.fine { color: var(--faint); font-size: 12.5px; }

/* ---------- workspace ---------- */
.workspace { flex: 1; display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; height: calc(100vh - 53px); position: sticky; top: 53px; }
.tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.tabs button { border-radius: 6px 6px 0 0; color: var(--muted); padding: 8px 12px; border-bottom: 2px solid transparent; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.panel { padding: 16px; }
.panel > h3:first-child { margin-top: 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 12px; color: var(--muted); }
.field .check { display: flex; align-items: center; gap: 6px; padding-top: 6px; color: var(--text); font-size: 13px; }
.file-row { margin: 16px 0 8px; font-size: 12.5px; }
.row-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.wide { width: 100%; }

.kern-head, .kern-row { display: grid; grid-template-columns: 1fr 1fr 82px 30px; gap: 6px; align-items: center; }
.kern-head { font-size: 12px; color: var(--muted); margin: 6px 0 4px; }
.kern-row { margin-bottom: 6px; }
.kern-row input[type="text"] { font-family: var(--preview-font); }
#btn-add-kern { margin-top: 4px; }
.kern-sample { font-family: var(--preview-font); font-size: 44px; line-height: 1.2; padding: 8px 12px; margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); overflow-wrap: anywhere; font-kerning: normal; }
.kern-sample.off { font-kerning: none; margin-top: 6px; color: var(--muted); }

/* glyph panel */
.glyph-hero { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
.glyph-hero svg { width: 100%; height: 240px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); }
.glyph-title { display: flex; align-items: baseline; gap: 10px; }
.glyph-title strong { font-size: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 12.5px; margin: 10px 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }

/* ---------- main ---------- */
.main { padding: 18px 22px 40px; min-width: 0; }
.preview-card { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); overflow: hidden; }
.preview-tools { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.preview-tools label { display: inline-flex; align-items: center; gap: 8px; }
.preview-tools output { font-family: var(--mono); color: var(--text); min-width: 40px; }
.preview-tools input[type="range"] { width: 120px; }
.preview-tools select { width: auto; padding: 3px 22px 3px 6px; font-size: 12.5px; }
.preview {
  --size: 48px; --leading: 1.25;
  font-family: var(--preview-font); font-size: var(--size); line-height: var(--leading);
  padding: 18px 22px; color: hsl(0 0% 88%); background: #000;
  max-height: 62vh; overflow: auto; overflow-wrap: anywhere;
}
.preview.no-kern, .preview.no-kern * { font-kerning: none; }
.preview p { margin: 0 0 0.35em; }
.preview .editable { min-height: calc(var(--size) * var(--leading) + 1.2em); margin-top: 0.4em; padding: 0.3em 0.4em; border: 2px dashed hsl(0 0% 25%); border-radius: 6px; outline: none; }
.preview .editable:focus { border-color: var(--accent); caret-color: var(--accent); }
.preview .editable:empty::before { content: attr(data-placeholder); color: hsl(0 0% 35%); font-family: system-ui; font-size: 0.4em; }
.preview mark.fb { background: none; color: var(--accent); }

.grid-head { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 12px; }
.grid-head h2 { font-size: 15px; }
.grid-head h2 .muted { font-weight: 400; margin-left: 6px; font-size: 13px; }
.legend { display: flex; align-items: center; gap: 6px 8px; font-size: 12px; color: var(--muted); }
.sw { display: inline-block; width: 14px; height: 2px; margin-left: 8px; }
.sw.base { background: var(--guide-base); }
.sw.xh { background: var(--guide-xh); }
.sw.adv { background: var(--accent); }

.glyph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.glyph-card {
  display: flex; flex-direction: column; padding: 0; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius); overflow: hidden; text-align: left; cursor: pointer; gap: 0;
}
.glyph-card:hover { border-color: var(--line-strong); background: var(--raised); }
.glyph-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.glyph-card svg { width: 100%; height: 112px; display: block; background: var(--bg); }
.glyph-card .meta { display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; font-size: 11.5px; width: 100%; }
.glyph-card .meta .id { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glyph-card .meta .cp { font-family: var(--mono); color: var(--muted); }
.glyph-card.empty svg, .glyph-card.unmapped svg, .glyph-card.excluded svg { opacity: 0.35; }
.glyph-card .flag { font-size: 10.5px; padding: 0 8px 6px; color: var(--muted); }
.glyph-card.unmapped .flag { color: var(--warn); }
.glyph-card.error .flag { color: var(--error); }

svg .ink { fill: hsl(0 0% 92%); }
svg .g-base { stroke: var(--guide-base); }
svg .g-xh { stroke: var(--guide-xh); }
svg .g-asc { stroke: var(--line-strong); }
svg .g-adv { stroke: var(--accent); }
svg .guide { stroke-width: 1; vector-effect: non-scaling-stroke; fill: none; }
svg .ghost-char { fill: hsl(0 0% 30%); font: 900px system-ui; }

.issues { margin-top: 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.issues summary { padding: 10px 14px; cursor: pointer; font-weight: 600; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--raised); color: var(--muted); font-size: 11.5px; text-align: center; font-weight: 600; }
.badge.warn { background: hsl(40 95% 62% / 0.15); color: var(--warn); }
.issues ul { list-style: none; margin: 0; padding: 0 14px 12px; }
.issues li { padding: 5px 0 5px 18px; position: relative; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
.issues li::before { content: ""; position: absolute; left: 2px; top: 12px; width: 7px; height: 7px; border-radius: 50%; background: var(--info); }
.issues li.warn::before { background: var(--warn); }
.issues li.error::before { background: var(--error); }
.issues li.error { color: var(--text); }
.issues li button { padding: 0; color: var(--accent-hover); font-size: inherit; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--raised); border: 1px solid var(--line-strong); padding: 9px 16px; border-radius: 8px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5); transition: 0.2s; max-width: 70vw; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--error); }
