/* DSEG-Char live demo. The canvas is a night-sky figure in both site themes;
   only the site topbar follows light/dark. */
body.demo {
  --d-bg: #05060a; --d-ink: #e8edf7; --d-dim: #7682a0;
  --d-line: rgba(150,175,215,.15); --d-glass: rgba(12,16,26,.74);
  --state: #ffb454; --graph: #35e6d5; --context: #c07bff; --end: #ff5470;
  --cjk: "Songti SC","STSong","Source Han Serif SC","Noto Serif CJK SC","Noto Serif TC",serif;
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
}
body.demo .topbar .wrap { max-width: none; }
body.demo .topbar-inner { height: 52px; }
.crumbs { color: var(--faint); font-size: 13px; white-space: nowrap; }
.crumbs a { color: var(--muted); }

#app {
  flex: 1; min-height: 0; display: flex; background: var(--d-bg); color: var(--d-ink);
  font: 13px/1.5 -apple-system, "SF Pro Text", "PingFang SC", system-ui, sans-serif;
}
#app .dim { color: var(--d-dim); }
#stage { position: relative; flex: 1; min-width: 0; }
#cv { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
#cv.grabbing { cursor: grabbing; }

.glass {
  background: var(--d-glass); border: 1px solid var(--d-line); border-radius: 12px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
#app button {
  background: rgba(255,255,255,.05); border: 1px solid var(--d-line); color: var(--d-ink);
  border-radius: 8px; padding: 6px 11px; cursor: pointer; font-size: 12px; transition: .15s; white-space: nowrap;
}
#app button:hover { background: rgba(255,255,255,.11); }
#app button:disabled { opacity: .35; cursor: default; }
#app button.primary { background: rgba(53,230,213,.16); border-color: rgba(53,230,213,.5); color: #a9fff4; font-weight: 600; }
#app button.primary:hover { background: rgba(53,230,213,.26); }

/* ---- top bar ---- */
#bar { position: absolute; top: 14px; left: 14px; right: 14px; padding: 8px 10px; display: flex; flex-direction: column; gap: 7px; z-index: 3; }
#bar .row { display: flex; align-items: center; gap: 8px; }
#prefix {
  flex: 1; min-width: 90px; background: rgba(255,255,255,.05); border: 1px solid var(--d-line);
  border-radius: 8px; color: var(--d-ink); padding: 6px 10px; font-family: var(--cjk); font-size: 17px;
}
#prefix:focus { outline: none; border-color: rgba(53,230,213,.55); }
.presets { flex-wrap: wrap; font-size: 11.5px; }
#app .chip { font-family: var(--cjk); font-size: 13px; padding: 2px 9px; border-radius: 999px; }
#convnote { font-size: 11px; }
#convnote b { color: var(--d-ink); font-family: var(--cjk); font-weight: 400; }
.sep { width: 1px; height: 20px; background: var(--d-line); flex: none; }
.mini { display: flex; align-items: center; gap: 6px; color: var(--d-dim); font-size: 11px; white-space: nowrap; }
#speed { width: 80px; accent-color: #35e6d5; }
.show-sm { display: none !important; }

/* ---- knobs ---- */
#knobs {
  position: absolute; top: 104px; left: 14px; padding: 10px 12px; width: 190px; z-index: 2;
  display: flex; flex-direction: column; gap: 7px; font-size: 11px; color: var(--d-dim);
}
#knobs label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#knobs select, #knobs input[type=number] {
  width: 86px; background: rgba(255,255,255,.05); border: 1px solid var(--d-line);
  border-radius: 6px; color: var(--d-ink); padding: 3px 6px; font-size: 11px;
}
#knobs select option { background: #10141e; }
#knobs hr { border: none; border-top: 1px solid var(--d-line); margin: 2px 0; }
#knobs .chk { justify-content: flex-start; cursor: pointer; gap: 0; }
#knobs .chk input { accent-color: #35e6d5; margin: 0 6px 0 0; }

/* ---- poem ---- */
#poem { position: absolute; left: 14px; bottom: 14px; right: 14px; padding: 10px 14px; z-index: 2; }
#poem .phase { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--d-dim); margin-bottom: 5px; }
#poem .line { display: flex; align-items: baseline; gap: 10px; font-family: var(--cjk); font-size: 23px; min-height: 32px; line-height: 1.4; }
#poem .tag {
  font-family: system-ui; font-size: 9px; letter-spacing: .1em; color: var(--d-dim); text-transform: uppercase;
  border: 1px solid var(--d-line); border-radius: 4px; padding: 1px 5px; flex: none; transform: translateY(-4px); min-width: 52px; text-align: center;
}
#poem-prefix { color: #8ea3c4; }
#poem-gen { word-break: break-all; }
#poem-gen span { cursor: pointer; transition: .2s; text-shadow: 0 0 14px currentColor; }
#poem-gen span:hover { filter: brightness(1.5); }
#caret { color: #35e6d5; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- legend ---- */
#legend {
  position: absolute; right: 14px; top: 104px; padding: 9px 12px; z-index: 2;
  display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: #a3aec4;
}
#legend span { display: flex; align-items: center; gap: 7px; }
#legend b { font-weight: 600; color: var(--d-ink); }
#legend em { font-style: normal; color: var(--d-dim); }
#legend i { width: 14px; height: 2px; border-radius: 2px; box-shadow: 0 0 8px currentColor; flex: none; }
#legend .note { display: block; color: var(--d-dim); font-size: 10.5px; max-width: 220px; line-height: 1.45; margin-top: 2px; }

#tooltip {
  position: absolute; pointer-events: none; background: rgba(8,11,18,.95); border: 1px solid var(--d-line);
  border-radius: 7px; padding: 5px 9px; font-size: 11px; transform: translate(10px,-120%); white-space: nowrap; z-index: 9;
}
#tooltip b { font-family: var(--cjk); font-size: 16px; margin-right: 6px; }

/* ---- loader ---- */
#loader { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5,6,10,.6); z-index: 8; transition: opacity .4s; }
#loader.done { opacity: 0; pointer-events: none; }
#loader[hidden] { display: none; }
#loader .lbox { width: min(340px, 80%); text-align: center; }
#loader .lt { font-size: 14px; margin-bottom: 10px; }
#loader .lbar { height: 4px; background: rgba(255,255,255,.08); border-radius: 2px; overflow: hidden; }
#lfill { display: block; height: 100%; width: 0; background: #35e6d5; box-shadow: 0 0 10px #35e6d5; transition: width .15s; }
#loader .ls { font-size: 11px; margin-top: 8px; }

/* ---- side ---- */
#side {
  width: 340px; flex: none; border-left: 1px solid var(--d-line); background: #070911;
  display: flex; flex-direction: column; overflow-y: auto; padding: 16px 15px; gap: 11px;
}
#side header h1 { font-size: 16px; font-weight: 650; margin: 0; color: var(--d-ink); display: flex; align-items: center; gap: 8px; }
#side .live { font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #35e6d5; border: 1px solid rgba(53,230,213,.5); border-radius: 4px; padding: 0 5px; }
#side .sub { color: var(--d-dim); font-size: 11.5px; margin: 4px 0 0; line-height: 1.5; }
.card { border: 1px solid var(--d-line); border-radius: 10px; padding: 11px 12px; background: rgba(255,255,255,.015); }
.card .k { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--d-dim); margin-bottom: 9px; }
.card .formula { text-transform: none; letter-spacing: 0; margin-left: 4px; }

#app dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 11px; margin: 0; }
#app dt { color: var(--d-dim); }
#app dd { text-align: right; font-variant-numeric: tabular-nums; margin: 0; }

.hop { font-family: var(--cjk); font-size: 26px; display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-height: 36px; }
.hop .arrow { font-size: 14px; color: var(--d-dim); font-family: system-ui; }
.hop .p { margin-left: auto; font-family: system-ui; font-size: 11.5px; color: var(--d-dim); font-variant-numeric: tabular-nums; text-align: right; }

.term { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 8px; font-size: 11px; margin: 5px 0; }
.term .name { color: var(--d-dim); }
.term .val { text-align: right; font-variant-numeric: tabular-nums; }
.track { position: relative; height: 6px; background: rgba(255,255,255,.05); border-radius: 3px; }
.track .zero { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--d-line); }
.track .fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; box-shadow: 0 0 10px currentColor; }
.term.is-support .name { color: var(--d-ink); font-weight: 600; }

.edge { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--d-line); font-size: 11px; font-variant-numeric: tabular-nums; line-height: 1.5; }
.edge .off { color: var(--end); }
.edge .on { color: var(--graph); }

.cands { list-style: none; display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; }
.cands li { display: grid; grid-template-columns: 22px 1fr 50px; align-items: center; gap: 8px; font-size: 11px; padding: 3px 4px; border-radius: 5px; }
.cands li.sel { background: rgba(255,255,255,.07); }
.cands .c { font-family: var(--cjk); font-size: 16px; }
.cands .bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,.05); position: relative; overflow: hidden; }
.cands .bar span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; box-shadow: 0 0 8px currentColor; }
.cands .pv { text-align: right; color: var(--d-dim); font-variant-numeric: tabular-nums; }
.cands .bb { color: var(--graph); }
.cands li.note { display: block; font-size: 10.5px; line-height: 1.4; padding-top: 4px; border-top: 1px solid var(--d-line); margin-top: 2px; }

.summary { display: flex; flex-direction: column; gap: 7px; font-size: 11px; }
.srow { display: grid; grid-template-columns: 96px 1fr 38px; align-items: center; gap: 8px; }
.srow .sb { height: 6px; background: rgba(255,255,255,.05); border-radius: 3px; position: relative; }
.srow .sb span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; box-shadow: 0 0 10px currentColor; }
.srow .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--d-dim); }
.summary .hint { color: var(--d-dim); line-height: 1.5; border-top: 1px solid var(--d-line); padding-top: 8px; margin-top: 2px; }

#side footer { margin-top: auto; padding-top: 6px; font-size: 10.5px; line-height: 1.55; }
#side footer p { margin: 0 0 6px; }
#side footer a { color: #8fd8ff; }

/* ---- narrow screens: stage on top, panel below, page scrolls ---- */
@media (max-width: 980px) {
  .crumbs { display: none; }
  #legend { display: none; }
}
@media (max-width: 820px) {
  body.demo { height: auto; overflow: auto; }
  body.demo .nav-links { display: none; }
  #app { flex-direction: column; }
  #stage { height: 64vh; height: 64dvh; min-height: 520px; flex: none; }
  #bar .row:first-child { flex-wrap: wrap; }
  #prefix { flex: 1 1 100%; }
  #bar .row:first-child .sep { display: none; }
  #side { width: auto; border-left: none; border-top: 1px solid var(--d-line); overflow: visible; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-block !important; }
  #knobs { display: none; top: auto; bottom: 110px; }
  #knobs.open { display: flex; }
  #poem .line { font-size: 19px; }
  #app button { padding: 6px 9px; }
}
