/* OpenWorldEngineer: LVGL redraws (artifacts-lvgl.html, assets/art/lvgl.js). Builds on styles.css (tokens, .card, .seg,
   .btn, .note); adds only lv- classes. The frame canvas shows the scene's pixels as they are; with the heatmap on, the
   frame turns to a light grey and every pixel the renderer wrote in that frame takes the colour of its write count. */

.lv {
  container-type: inline-size;
  /* write-count heat, 1 / 2 / 3 / 4+ writes: one orange-red hue from light to dark, drawn over the light grey frame in
     both themes (the canvas is an image, not the page surface); checked as an ordinal ramp against that grey */
  --lv-heat-1: #EE6530; --lv-heat-2: #C9301C; --lv-heat-3: #8E1410; --lv-heat-4: #4E0907;
  --lv-changed: #256ABF;           /* pixels that changed since the previous frame: blue, apart from the heat hue */
  --lv-orig: var(--ink-2);         /* the original renderer's line */
  --lv-sel: var(--accent);         /* the selected renderer's line */
  --lv-other: var(--line-other);   /* the other renderers' lines */
  display: grid; gap: 16px; min-width: 0; color: var(--ink); font-size: var(--fs-ui);
}
.lv-head p { max-width: 74ch; }
.lv-quiet { margin: 0; padding: 18px 0; color: var(--muted); }

/* scene gallery: the scene picker */
.lv-scenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lv-scene {
  display: grid; gap: 6px; padding: 6px 6px 8px; min-width: 0; text-align: left; cursor: pointer;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); background: var(--sheet); color: var(--ink-2);
  transition: border-color 140ms;
}
.lv-scene:hover { border-color: var(--accent); color: var(--ink); }
.lv-scene[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--ink); }
.lv-scene img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 0; background: var(--hover); }
.lv-scene-n { padding: 0 2px; font-size: 0.8125rem; font-weight: 600; line-height: 1.25; }
.lv-scene-f { padding: 0 2px; margin-top: -4px; font-size: 0.75rem; color: var(--muted); line-height: 1.25; }

/* stage and renderer list side by side, stacked when narrow */
.lv-main { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); gap: 16px; align-items: start; min-width: 0; }
.lv-card { padding: 14px; min-width: 0; }
.lv-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; }
.lv-title { font-size: 0.9375rem; font-weight: 650; letter-spacing: -0.02em; min-width: 0; }
.lv-sub { font-size: var(--fs-small); color: var(--muted); }
.lv-seg button { padding: 5px 12px; font-size: 0.8125rem; }

.lv-stage { position: relative; margin-top: 12px; border: 1px solid var(--rule); border-radius: var(--radius-sm); overflow: hidden; background: var(--hover); }
.lv-stage canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; image-rendering: auto; }
@container (min-width: 1000px) { .lv-stage canvas { image-rendering: pixelated; } }
.lv-badge {
  position: absolute; left: 8px; top: 8px; padding: 3px 9px; border-radius: 0; pointer-events: none;
  background: color-mix(in srgb, var(--tip-bg) 82%, transparent); color: var(--tip-fg);
  font-family: var(--font-mono); font-size: 0.75rem; font-variant-numeric: tabular-nums;
}
.lv-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 8px; font-size: 0.75rem; color: var(--muted); min-height: 20px; }
.lv-legend-k { display: inline-flex; align-items: center; gap: 5px; }
.lv-sw { width: 12px; height: 12px; border-radius: 0; flex: none; box-shadow: 0 0 0 1px var(--rule-strong); }
.lv-sw.is-0 { background: #E4E4E4; }

.lv-transport { display: flex; align-items: center; gap: 8px; margin-top: 10px; min-width: 0; }
.lv-tbtn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; padding: 0; cursor: pointer;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); background: var(--sheet); color: var(--ink-2);
}
.lv-tbtn:hover { border-color: var(--accent); color: var(--ink); }
.lv-tbtn svg { width: 14px; height: 14px; }
.lv-range { flex: 1 1 auto; min-width: 60px; accent-color: var(--accent); }
.lv-fno { flex: none; min-width: 7.5ch; text-align: right; font-family: var(--font-mono); font-size: 0.8125rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lv-now { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: var(--fs-small); color: var(--muted); }
.lv-now b { font-family: var(--font-mono); font-weight: 640; color: var(--ink); font-variant-numeric: tabular-nums; }
.lv-warn { margin-top: 8px; padding: 6px 10px; border-radius: 0; background: var(--warn-wash); color: var(--warn-ink); font-size: var(--fs-small); }

/* renderer list: the picker, and the per-scene totals */
.lv-rlist { display: grid; gap: 6px; margin-top: 12px; }
.lv-r {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 8px 10px 11px;
  text-align: left; cursor: pointer; overflow: hidden;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); background: var(--sheet); color: var(--ink-2);
  transition: border-color 140ms;
}
.lv-r:hover { border-color: var(--accent); color: var(--ink); }
.lv-r[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--ink); }
.lv-r-n { font-size: 0.875rem; font-weight: 600; line-height: 1.3; min-width: 0; overflow-wrap: anywhere; }
.lv-r-a { font-weight: 500; color: var(--muted); }
.lv-r-v { font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 640; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lv-r-s { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lv-r-s .is-bad { color: var(--accent-ink); font-weight: 600; }
.lv-r-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--s, 0) * 100%); background: var(--line-on); }
.lv-r[aria-checked="true"] .lv-r-bar { background: var(--accent); }
.lv-r.is-orig .lv-r-bar { background: var(--ink-2); }
.lv-side-foot { margin-top: 12px; }
.lv-side-foot a { color: var(--link); }

/* per-frame cost chart */
.lv-chart-card { padding: 14px 14px 10px; }
.lv-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: 0.75rem; color: var(--muted); }
.lv-key { display: inline-flex; align-items: center; gap: 6px; }
.lv-key i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; }
.lv-key i.is-orig { border-color: var(--lv-orig); }
.lv-key i.is-sel { border-color: var(--lv-sel); }
.lv-key i.is-other { border-color: var(--line-on); border-top-width: 1.5px; }
.lv-chart { position: relative; margin-top: 8px; touch-action: pan-y; cursor: crosshair; }
.lv-chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.lv-chart .ax text { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.lv-chart .grid line { stroke: var(--rule); stroke-width: 1; shape-rendering: crispEdges; }
.lv-chart .base { stroke: var(--rule-strong); stroke-width: 1; shape-rendering: crispEdges; }
.lv-chart path.ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lv-chart path.ln.is-other { stroke: var(--lv-other); stroke-width: 1.5; }
.lv-chart path.ln.is-other.is-hot { stroke: var(--line-on); }
.lv-chart path.ln.is-orig { stroke: var(--lv-orig); }
.lv-chart path.ln.is-sel { stroke: var(--lv-sel); }
.lv-chart .cur { stroke: var(--ink-2); stroke-width: 1; opacity: 0.55; shape-rendering: crispEdges; }
.lv-chart .hov { stroke: var(--muted); stroke-width: 1; shape-rendering: crispEdges; }
.lv-chart circle.dot { stroke: var(--sheet); stroke-width: 2; }
.lv-chart circle.dot.is-orig { fill: var(--lv-orig); }
.lv-chart circle.dot.is-sel { fill: var(--lv-sel); }
.lv-chart .lbl { font-size: 11px; font-weight: 600; fill: var(--ink-2); }
.lv-chart-foot { margin-top: 4px; }

@container (max-width: 860px) {
  .lv-main { grid-template-columns: minmax(0, 1fr); }
}
/* side by side, the renderer list (the original and 13 models) scrolls inside a card as tall as the stage's */
@container (min-width: 861px) {
  .lv-main:has(> .lv-side) { align-items: stretch; }
  .lv-side { display: flex; flex-direction: column; }
  .lv-side .lv-rlist { flex: 1 1 0; min-height: 0; contain: size; overflow-y: auto; grid-auto-rows: max-content; align-content: start;
    padding: 4px; margin: 8px -4px 0; }   /* room for the focus ring inside the scroller */
  .lv-side .lv-rlist.is-more { mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent); }
}
@container (max-width: 560px) {
  .lv-scenes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .lv-scene { padding: 4px 4px 6px; }
  .lv-scene-f { display: none; }
  .lv-card { padding: 12px; }
  .lv-chart svg { height: 200px; }
}
@container (max-width: 560px) {
  .lv-legend > span:first-child { flex-basis: 100%; }
}

/* scene set switch (hidden test / public dev) and the graded-vs-re-run line on hidden scenes */
.lv-pool { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.lv-r-g { grid-column: 1 / -1; font-family: var(--font-mono); font-size: 0.75rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lv-r-g.is-bad { color: var(--accent-ink); font-weight: 600; }

/* a task page's frame (html.embed): the stage and the chart side by side, the chart as tall as the stage; stacked when
   narrow. drawChart reads --h. */
.embed .lv-main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.embed .lv-chart { --h: 430; }
.embed .lv-legend > span:first-child { flex-basis: 100%; }
.embed .lv-chart svg { height: calc(var(--h) * 1px); }
@container (max-width: 760px) {
  .embed .lv-main { grid-template-columns: minmax(0, 1fr); }
  .embed .lv-chart { --h: 240; }
}
@container (max-width: 560px) {
  .embed .lv-chart { --h: 200; }
}
