:root {
  --bg: #14181f;
  --panel: #1c222c;
  --fg: #e6e9ee;
  --muted: #9aa6b5;
  --accent: #6ea8fe;
  --border: #2b333f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 860px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
.lede { color: var(--muted); margin: 0 0 1.5rem; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

.controls { display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; margin-bottom: 1rem; }
.controls label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.controls label.grow { flex: 1 0 100%; min-width: 0; }
.controls label.check { flex-direction: row; align-items: center; gap: .4rem; }
textarea#expr {
  display: block; width: 100%; min-width: 0; resize: vertical;
  max-height: 14rem; overflow-y: auto;
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .7rem; font-family: ui-monospace, Menlo, monospace;
  font-size: 1rem; line-height: 1.4; overflow-wrap: anywhere;
}
textarea#expr:focus { outline: 2px solid var(--accent); border-color: transparent; }
select {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .55rem;
}

.presets { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }
.presets button {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 999px; padding: .35rem .8rem; font-size: .82rem; cursor: pointer;
}
.presets button:hover { border-color: var(--accent); color: var(--accent); }

.stage {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem; display: flex; justify-content: flex-start; align-items: center;
  min-height: 180px; overflow: auto;
}
canvas { image-rendering: pixelated; }
.stage canvas { flex: none; margin-inline: auto; max-width: none; }
.meta { color: var(--muted); font-size: .8rem; font-family: ui-monospace, Menlo, monospace; }
.err { color: #ff8b8b; }

.timeline-row { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; }
.timeline-row #timeline { flex: 1; }
.timeline-row button {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: .35rem .8rem; cursor: pointer; font-size: .85rem;
}
.timeline-row button:hover { border-color: var(--accent); color: var(--accent); }
.timeline-row .hint { color: var(--muted); font-size: .78rem; }
.note { color: var(--muted); font-size: .82rem; margin: .5rem 0 0; }

.penlog { margin-top: 1rem; overflow-x: auto; max-height: 34rem; }
.penlog table { border-collapse: collapse; font-family: ui-monospace, Menlo, monospace; font-size: .8rem; }
.penlog th, .penlog td { border: 1px solid var(--border); padding: .15rem .55rem; text-align: right; }
.penlog th { color: var(--muted); font-weight: 500; }
.penlog td:nth-child(2) { text-align: left; color: var(--accent); }
.penlog td:nth-child(6) { text-align: left; color: var(--muted); }
.penlog tr.cur td { background: rgba(110,168,254,0.18); color: var(--fg); }
.penlog .trace-set { color: #6ea8fe; }
.penlog .trace-clear { color: #ff8080; }

.syntax { margin-top: 1.5rem; color: var(--muted); }
.syntax summary { cursor: pointer; color: var(--fg); }
.syntax ul { margin: .5rem 0; padding-left: 1.2rem; }
.syntax li { margin: .2rem 0; }

.tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.tabs .tab {
  background: none; color: var(--muted); border: 0; border-bottom: 2px solid transparent;
  padding: .5rem .9rem; font-size: .9rem; cursor: pointer;
}
.tabs .tab:hover { color: var(--fg); }
.tabs .tab.active { color: var(--fg); border-bottom-color: var(--accent); }

#fonttable h2 { font-size: 1rem; color: var(--muted); font-weight: 500; margin: 1.5rem 0 .75rem; }
.glyphgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .6rem; }
.glyphcell {
  margin: 0; padding: .5rem; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: .35rem;
}
.glyphcell canvas { image-rendering: pixelated; }
.glyphcell figcaption { display: flex; flex-direction: column; align-items: center; gap: .1rem; text-align: center; }
.glyphcell .gcode { font-family: ui-monospace, Menlo, monospace; font-size: .72rem; color: var(--accent); }
.glyphcell .gname { font-size: .72rem; color: var(--muted); word-break: break-all; }
