/* DemoGNG — new UI. Layout follows the design canvas: toolbar, canvas first, inspector. */
:root {
  --bg: #eef0f3;
  --panel: #fff;
  --line: #e3e5e8;
  --line2: #d0d4da;
  --ink: #15171a;
  --ink2: #3a3f47;
  --muted: #5b616b;
  --accent: #1f5fd6;
  --stage: #0e1116;
  --stage2: #12161c;
  --node: #f08c2e;
  --radius: 12px;
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100vh; display: flex; flex-direction: column; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---- toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; padding-right: 6px; }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11px; }
.picker { display: flex; align-items: center; gap: 4px; }
.icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 1px solid var(--line2); border-radius: 8px; background: #fff; text-decoration: none; color: var(--ink2); font-size: 18px; }
.icon:hover, .toolbar button:hover { background: #f5f6f8; }
.select { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 10px; border: 1px solid var(--line2); border-radius: 8px; background: #fff; text-align: left; }
.select small { display: block; font-size: 11px; color: var(--muted); }
label.select { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; }
label.select select { border: 0; padding: 0; font-weight: 600; background: transparent; max-width: 290px; }
.select.dist { min-width: 220px; }
.select.dist b { display: block; }
#distThumb { width: 30px; height: 30px; border-radius: 5px; background: var(--stage); }
.spacer { flex: 1 1 10px; }
.transport { display: flex; gap: 6px; }
.transport button { height: 40px; padding: 0 14px; border: 1px solid var(--line2); border-radius: 8px; background: #fff; font-weight: 500; }
.transport button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 96px; }
.transport button.primary:hover { background: #1a51b8; }
.transport button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.icon.wide { width: auto; padding: 0 12px; font-size: 13px; font-weight: 500; }
.speed { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.speed input { width: 110px; accent-color: var(--accent); }
.speed output { font: 12px ui-monospace, monospace; color: var(--ink); min-width: 52px; }

/* ---- workspace ---- */
.workspace { flex: 1; display: flex; gap: 16px; padding: 16px; min-height: 0; }
.stage { flex: 999 1 560px; min-width: 0; min-height: 0; background: var(--stage); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.layerbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; }
.layers, .viewtools { display: flex; flex-wrap: wrap; gap: 8px; }
.viewtools { margin-left: auto; }
.viewtools button { height: 30px; padding: 0 11px; border-radius: 999px; border: 1px solid rgba(255,255,255,.16); background: transparent; color: #c9d1dc; font-size: 12px; }
.viewtools button[aria-pressed="true"] { background: rgba(255,255,255,.12); color: #fff; }
.layers button:disabled { opacity: .35; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; height: 36px; }
.seg button { border: 0; padding: 0 12px; background: #fff; font-weight: 600; font-size: 12px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
#cv { touch-action: none; }
#cv.grab, #cv3.grab { cursor: grab; } #cv.grabbing, #cv3.grabbing { cursor: grabbing; }
.embedOpen { position: absolute; right: 10px; bottom: 10px; color: #c9d1dc; background: rgba(14,17,22,.75); border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: 4px 8px; font-size: 12px; text-decoration: none; }
/* embedded (?mode=embedded): only the canvas, e.g. inside the start page */
body.embedded .toolbar, body.embedded .inspector, body.embedded .layerbar, body.embedded .hud { display: none; }
body.embedded .workspace { padding: 0; }
body.embedded .stage { border-radius: 0; }
body.embedded #cv, body.embedded #cv3 { width: 100vw; height: 100vh; }
body.embedded .canvasWrap { padding: 0; }
.layers button { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 999px; border: 1px solid rgba(255,255,255,.16); background: transparent; color: #8a94a3; font-size: 12px; font-weight: 500; }
.layers button[aria-pressed="true"] { background: rgba(255,255,255,.12); color: #f2f4f7; }
.layers .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; }
.layers button[aria-pressed="true"] .dot { background: var(--c); border-color: var(--c); }
.canvasWrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 12px; }
#cv, #cv3 { width: 100%; height: 100%; display: block; }   /* whole area; the data keep their shape */
#cv[hidden], #cv3[hidden] { display: none; }
/* Fixed height and fixed column widths: changing numbers and status texts never change the
   size of the bar, so the canvas above keeps its size (no flicker). */
.hud { display: flex; flex-wrap: nowrap; align-items: center; gap: 18px; height: 74px; box-sizing: border-box; overflow: hidden;
  padding: 10px 16px; border-top: 1px solid rgba(255,255,255,.08); background: var(--stage2); color: #f2f4f7; }
.hud div { display: flex; flex-direction: column; flex: 0 0 auto; }
.hud small { color: #9aa4b2; font-size: 11px; white-space: nowrap; }
.hud b { font: 500 15px ui-monospace, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud .num { min-width: 6ch; }
.hud .num.wide { min-width: 10ch; }
.hud .phase { flex: 1 1 0; min-width: 0; }
.hud .phase b { font-size: 13px; line-height: 1.3; height: 2.6em; white-space: normal; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.hud .spark { flex: 0 0 clamp(120px, 18%, 260px); flex-direction: row; align-items: center; gap: 10px; }
.hud .spark small { white-space: normal; width: 5.5em; }
.hud .spark canvas { flex: 1; height: 30px; min-width: 0; }
#fsStatus { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- inspector ---- */
.inspector { flex: 0 1 370px; min-width: 290px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 4px 8px 0; }
.tabs button { flex: 1; height: 38px; border: 0; background: transparent; font-weight: 600; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabpanel { flex: 1; overflow: auto; padding: 14px 18px; }
.tabpanel h3 { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px; }
.tabpanel h3:first-child { margin-top: 0; }
.param { margin: 0 0 12px; }
.param .top { display: flex; align-items: baseline; gap: 6px; }
.param label { flex: 1; font-weight: 500; font-size: 13px; }
.param .sym { font-family: 'Times New Roman', serif; font-style: italic; color: var(--ink2); font-weight: 400; margin-left: 3px; }
.param .tag { font-size: 9px; font-weight: 600; border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; color: var(--muted); }
.param .reset { border: 0; background: none; color: var(--accent); padding: 0 2px; font-size: 14px; }
.param input[type=number] { width: 84px; height: 28px; border: 1px solid var(--line2); border-radius: 6px; padding: 0 6px; text-align: right; font: 12px ui-monospace, monospace; }
.param input[type=range] { width: 100%; margin: 5px 0 2px; accent-color: var(--accent); }
.param .help { font-size: 12px; color: var(--muted); line-height: 1.35; }
.check { display: flex; gap: 10px; align-items: center; margin: 0 0 10px; font-size: 13px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.about p, .about li { color: var(--ink2); font-size: 13px; line-height: 1.5; }
.about h2 { font-size: 18px; margin: 0 0 4px; }
.about .by { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.inspectorFoot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.inspectorFoot button { flex: 1; height: 36px; border: 1px solid var(--line2); border-radius: 8px; background: #fff; font-weight: 500; }

/* ---- gallery ---- */
dialog#gallery, dialog#keyhelp { width: min(760px, 94vw); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 12px 32px rgba(21,23,26,.16); }
dialog#gallery::backdrop, dialog#keyhelp::backdrop { background: rgba(14,17,22,.35); }
.galleryHead { display: flex; align-items: center; gap: 12px; }
.galleryHead h2 { flex: 1; font-size: 17px; margin: 0; }
.galleryHead input { height: 34px; width: 200px; border: 1px solid var(--line2); border-radius: 8px; padding: 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chips button { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line2); background: #fff; font-size: 12px; font-weight: 500; }
.chips button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 8px; max-height: 60vh; overflow: auto; }
.grid button { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 2px solid transparent; border-radius: 10px; background: #fff; text-align: left; font-size: 12px; font-weight: 500; position: relative; }
.grid button:hover { background: #f5f6f8; }
.grid button[aria-pressed="true"] { border-color: var(--accent); }
.grid canvas { width: 100%; aspect-ratio: 1.4; border-radius: 6px; background: var(--stage); }
.grid .moving { position: absolute; right: 10px; top: 10px; font-size: 9px; font-weight: 700; background: var(--node); color: var(--ink); border-radius: 4px; padding: 1px 5px; }
.hint { font-size: 12px; color: var(--muted); margin: 12px 0 0; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

/* ---- phone ---- */
@media (max-width: 900px) {
  body { height: auto; }
  .workspace { flex-wrap: wrap; }
  .canvasWrap { min-height: 0; }
  #cv, #cv3 { width: 100%; height: auto; aspect-ratio: 1; }   /* phones: page scrolls, square canvas */
  .toolbar { gap: 8px; padding: 8px 10px; }
  .brand small, .speed span { display: none; }
  .picker { flex: 1 1 100%; }
  .picker .select { flex: 1; }
  label.select select { max-width: none; width: 100%; }
  .workspace { padding: 8px; gap: 8px; }
  .stage { flex-basis: 100%; }
  .inspector { max-width: none; flex-basis: 100%; max-height: none; }
  .hud { gap: 14px; }
  .hud .spark { display: none; }          /* phones: numbers and status only */
  .hud .num.wide { min-width: 8ch; }
}

/* ---- fullscreen: only the simulation, as large as the screen allows ---- */
.fsBar { display: none; }
.stage.fs { position: fixed; inset: 0; z-index: 50; border-radius: 0; }  /* also the fallback without the Fullscreen API */
.stage.fs .layerbar, .stage.fs .hud { display: none; }
.stage.fs .canvasWrap { padding: 0; }
.stage.fs #cv, .stage.fs #cv3 { width: 100vw; height: 100vh; height: 100dvh; max-width: none; aspect-ratio: auto; }
.stage.fs .fsBar { display: flex; align-items: center; gap: 8px; position: absolute; top: 12px; right: 12px; opacity: .25; transition: opacity .2s; }
.stage.fs .fsBar:hover, .stage.fs .fsBar:focus-within { opacity: 1; }
.fsBar span { font: 12px ui-monospace, monospace; color: #c9d1dc; }
.fsBar button { height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.25); background: rgba(14,17,22,.7); color: #f2f4f7; font-size: 13px; }

/* ---- keyboard help, frame rate ---- */
dialog#keyhelp { width: min(560px, 94vw); }
#keyhelp table { border-collapse: collapse; width: 100%; font-size: 13px; }
#keyhelp td { padding: 3px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
#keyhelp td:first-child { white-space: nowrap; width: 1%; }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 5px; font: 12px ui-monospace, monospace; text-align: center; background: #fff; }
.hud .fps[hidden], .inspector[hidden] { display: none; }

/* ---- name card on model / distribution change (announce.js): at the top, see-through ---- */
.canvasWrap { container-type: inline-size; }
.announce { position: absolute; inset: 0; z-index: 5; display: flex; align-items: flex-start; justify-content: center; pointer-events: none; text-align: center; padding-top: clamp(10px, 2.2cqi, 28px); }
.announce[hidden] { display: none; }
.aCard { display: flex; flex-direction: column; align-items: center; gap: clamp(4px, .8cqi, 12px); max-width: 86%;
  padding: clamp(8px, 1.4cqi, 18px) clamp(16px, 3cqi, 40px); border-radius: 16px;
  background: rgba(14,17,22,.35); border: 1px solid rgba(255,255,255,.10); text-shadow: 0 1px 6px rgba(0,0,0,.8); }
.aModel[hidden], .aDist[hidden] { display: none; }
.aModel b { display: block; font-weight: 700; font-size: clamp(30px, 6.5cqi, 96px); line-height: 1; letter-spacing: -.02em; color: rgba(240,140,46,.95); }
.aModel span { display: block; margin-top: clamp(2px, .5cqi, 8px); font-weight: 500; font-size: clamp(13px, 2cqi, 28px); line-height: 1.2; color: rgba(230,233,238,.9); }
.aDist { font-weight: 650; font-size: clamp(22px, 4.6cqi, 66px); line-height: 1.05; color: rgba(127,176,255,.95); }
.announce.enter .aCard { animation: announceIn .28s ease-out both; }
.announce.fading { opacity: 0; transition: opacity .6s ease; }
@keyframes announceIn { from { opacity: 0; transform: scale(.94); } }
@keyframes announceFade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .announce.enter .aCard { animation-name: announceFade; } }
