/* LCM simulator: design tokens and components. No external fonts or CSS
 * frameworks; everything here is used by index.html. */

:root {
  color-scheme: light;
  --canvas: #f5f6f8;
  --bounds: rgba(20, 24, 33, 0.16);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-2: #f1f2f5;
  --border: rgba(20, 24, 33, 0.1);
  --border-strong: rgba(20, 24, 33, 0.18);
  --text: #171a21;
  --text-2: #555c69;
  --text-3: #8a909b;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --accent-weak: rgba(47, 91, 234, 0.1);
  --danger: #c62828;
  --warn-weak: rgba(217, 119, 6, 0.12);
  --warn-text: #92400e;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 20px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #0e1014;
    --bounds: rgba(230, 234, 242, 0.14);
    --surface: rgba(25, 28, 35, 0.88);
    --surface-solid: #191c23;
    --surface-2: #22262e;
    --border: rgba(230, 234, 242, 0.09);
    --border-strong: rgba(230, 234, 242, 0.18);
    --text: #e9ebef;
    --text-2: #a6acb8;
    --text-3: #6f7683;
    --accent: #7090ff;
    --accent-text: #0e1014;
    --accent-weak: rgba(112, 144, 255, 0.16);
    --danger: #ff6b6b;
    --warn-weak: rgba(251, 191, 36, 0.14);
    --warn-text: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0e1014;
  --bounds: rgba(230, 234, 242, 0.14);
  --surface: rgba(25, 28, 35, 0.88);
  --surface-solid: #191c23;
  --surface-2: #22262e;
  --border: rgba(230, 234, 242, 0.09);
  --border-strong: rgba(230, 234, 242, 0.18);
  --text: #e9ebef;
  --text-2: #a6acb8;
  --text-3: #6f7683;
  --accent: #7090ff;
  --accent-text: #0e1014;
  --accent-weak: rgba(112, 144, 255, 0.16);
  --danger: #ff6b6b;
  --warn-weak: rgba(251, 191, 36, 0.14);
  --warn-text: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--canvas);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- canvas */
#stage { position: fixed; inset: 0; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#canvas.panning { cursor: grabbing; }

/* ---------------------------------------------------------------- panels */
.panel {
  position: fixed;
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
}
body.clean .panel:not(.keep) { display: none !important; }

/* toolbar, top left */
#toolbar { top: 12px; left: 12px; display: flex; align-items: center; gap: 4px; padding: 6px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 4px; font-weight: 650; letter-spacing: 0.01em; white-space: nowrap; }
.brand svg { color: var(--accent); }
.divider { width: 1px; align-self: stretch; margin: 4px 4px; background: var(--border); }

/* settings, left under the toolbar */
#settings { top: 68px; left: 12px; width: 300px; max-height: calc(100vh - 80px); display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 650; }
.panel-head .spacer { flex: 1; }
.panel-body { overflow-y: auto; padding: 0 6px 6px; }
.panel-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 14px 12px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12px; }

.group { border-radius: var(--radius-sm); }
.group > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px;
  padding: 8px; font-weight: 600; color: var(--text-2); border-radius: var(--radius-sm);
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.06em;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary:hover { background: var(--surface-2); }
.group > summary .chev { transition: transform 0.15s; color: var(--text-3); }
.group[open] > summary .chev { transform: rotate(90deg); }
.group-body { padding: 0 8px 8px; display: grid; gap: 10px; }

.field { display: grid; gap: 4px; }
.field-top { display: flex; align-items: center; gap: 8px; }
.field-top label { flex: 1; color: var(--text); }
.field-top label.has-hint { flex: 0 1 auto; margin-right: auto; cursor: help; text-decoration: underline dotted var(--text-3); text-underline-offset: 3px; }
.field.disabled { opacity: 0.45; }
.field .sub { color: var(--text-3); font-size: 11.5px; }

input[type="number"], select {
  height: 28px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: var(--surface-solid); padding: 0 8px; min-width: 0;
}
input[type="number"] { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
input[type="number"]::-webkit-inner-spin-button { opacity: 0.4; }
select { padding-right: 24px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

textarea {
  width: 100%; resize: vertical; min-height: 96px; padding: 6px 8px; border-radius: 7px;
  border: 1px solid var(--border-strong); background: var(--surface-solid); color: var(--text);
  font: 12px/1.5 var(--mono); tab-size: 4;
}
.field .sub.error { color: var(--danger); }
.field .sub.note { margin-top: -2px; }
.start-summary { margin: 0; padding: 8px 10px; border-radius: 7px; background: var(--surface-2); color: var(--text-2); font-size: 12px; line-height: 1.45; }
.more > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 12px; padding: 2px 0; }
.more > summary::-webkit-details-marker { display: none; }
.more > summary:hover { color: var(--text); }
.more > summary .chev { transition: transform 0.15s; color: var(--text-3); }
.more[open] > summary .chev { transform: rotate(90deg); }
.more-body { display: grid; gap: 10px; padding: 8px 0 0 10px; margin-top: 4px; border-left: 2px solid var(--border); }
input[type="range"] { width: 100%; height: 18px; margin: 0; background: transparent; accent-color: var(--accent); cursor: pointer; }

/* switch */
.switch { position: relative; width: 32px; height: 18px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; min-width: 32px; padding: 0 8px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text); white-space: nowrap;
}
a.btn { text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); padding: 0 12px; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.small { height: 26px; min-width: 26px; padding: 0 6px; font-size: 12px; }
.btn.outline { border-color: var(--border-strong); }
.btn[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); }
.btn svg { flex: none; }
#toolbar select[hidden] { display: none; }
/* The Examples menu opens under its toolbar button (positioned by app.js), like the Export menu. */
#examples_menu { right: auto; bottom: auto; min-width: 280px; max-width: min(360px, calc(100vw - 16px)); }
.menu-item { height: auto; min-height: 36px; padding: 6px 10px 6px 8px; gap: 8px; text-align: left; }
.menu-item .tick { flex: none; display: inline-flex; visibility: hidden; color: var(--accent); }
.menu-item[aria-checked="true"] .tick { visibility: visible; }
.menu-item[aria-checked="true"] { background: var(--accent-weak); }
.menu-item .text { display: grid; gap: 1px; }
.menu-item .title { font-weight: 600; }
.menu-item .note { color: var(--text-3); font-size: 11.5px; font-weight: 400; white-space: normal; }
.menu-item:first-child { margin-bottom: 4px; }
#toolbar select { height: 32px; border-radius: var(--radius-sm); background: var(--surface-solid); }
/* The menu is as wide as its longest entry: with the "per turn" entries (sequential scheduler) hold it to a width the toolbar can afford. */
#playback.has-turns { width: 100px; padding: 0 20px 0 6px; text-overflow: clip; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.warn { background: var(--warn-weak); color: var(--warn-text); }

/* HUD, top right */
#hud { top: 12px; right: 12px; width: 236px; padding: 12px 14px; display: grid; gap: 8px; }
.hud-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.hud-row .k { color: var(--text-2); }
.hud-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.hud-time { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.hud-status { color: var(--text-2); font-size: 12px; }
.hud-status.ended { color: var(--accent); font-weight: 600; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.25s; }
.hud-plot { display: grid; gap: 4px; }
.hud-plot canvas { width: 100%; height: 55px; display: block; border-radius: 6px; background: var(--surface-2); }
.hud-perf { color: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; border-top: 1px solid var(--border); padding-top: 8px; }
.last-event { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); background: var(--surface-2); border-radius: 6px; padding: 6px 8px; }

/* inspector, right under the HUD */
#inspector { top: 12px; right: 260px; width: 250px; padding: 12px 14px; display: grid; gap: 6px; }
#inspector h3 { margin: 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
#inspector h3 .spacer { flex: 1; }
#inspector dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 4px 0 0; }
#inspector dt { color: var(--text-2); }
#inspector dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

/* legend, bottom left */
#legend { left: 12px; bottom: 12px; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; max-width: min(640px, calc(100vw - 90px)); }
#legend .item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); white-space: nowrap; }
#legend .count { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
#settings:not([hidden]) ~ #legend { left: 324px; max-width: calc(100vw - 400px); }

/* view tools, bottom right */
#tools { right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 2px; padding: 4px; }
.menu { position: fixed; z-index: 30; right: 60px; bottom: 60px; padding: 4px; display: grid; min-width: 190px; }
.menu .btn { justify-content: flex-start; }

/* A short laptop screen: the status panel and the view tools share the right edge, so tighten the panel. */
@media (min-width: 761px) and (max-height: 800px) {
  #hud { gap: 4px; padding: 10px 14px; }
}

/* Wherever the view tools are a column (twelve of them), they take two columns, and the status panel (the tallest panel,
 * at the other end of the right edge) gives up its plot, then everything but the essentials, so the two never meet. */
@media (min-width: 761px) and (min-height: 521px) {
  #tools { display: grid; grid-template-columns: repeat(2, auto); gap: 2px; }
}
/* Phones: twelve tools in one row are too many; full screen is the one a phone can do without. */
@media (max-width: 760px) { #fullscreen { display: none; } }
/* Where the status panel's Zoom row is shown (not on phones, nor on screens under 581 px high, which drop its extra rows), it has the + and −. */
@media (min-width: 761px) and (min-height: 581px) { #zoom_in, #zoom_out { display: none; } }
#canvas.measuring { cursor: crosshair; }
@media (min-width: 761px) and (max-height: 680px) {
  #hud .hud-plot { display: none; }
}
@media (min-width: 761px) and (max-height: 580px) {
  #hud .hud-extra { display: none !important; }
}

/* The overview map: bottom right, just left of the view tools (app.js sets its right edge). Only where there is room. */
#overview { bottom: 12px; right: 76px; padding: 0; overflow: hidden; z-index: 4; cursor: crosshair; line-height: 0; }
#overview canvas { display: block; }
@media (max-width: 1219px), (max-height: 520px) { #overview { display: none; } }

/* The caption while a turn is played one at a time: above the legend, left-aligned with it. */
#turn_caption { left: 12px; bottom: 56px; width: min(500px, calc(100vw - 100px)); padding: 10px 14px; display: grid; gap: 3px; z-index: 5; }
#settings:not([hidden]) ~ #turn_caption { left: 324px; width: min(500px, calc(100vw - 440px)); }
#turn_caption .cap-head { font-weight: 650; }
#turn_caption .cap-body { color: var(--text-2); line-height: 1.4; }

/* scale bar in the status panel */
#hud .scale { display: inline-flex; align-items: center; gap: 8px; }
#hud .zoomgauge { display: inline-flex; align-items: center; gap: 4px; }
#hud .zoombtn { width: 20px; height: 20px; min-width: 20px; padding: 0; border: 1px solid var(--border-strong); border-radius: 6px; }
#hud_zoom { min-width: 48px; text-align: right; }
#hud_zoom_meter { position: relative; display: inline-block; width: 40px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2);
  background-image: repeating-linear-gradient(90deg, transparent 0, transparent calc(16.667% - 1px), var(--border-strong) calc(16.667% - 1px), var(--border-strong) 16.667%); }
#hud_zoom_fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); opacity: 0.85; border-radius: 4px; }
#hud_scale_bar { display: inline-block; height: 7px; border: 1.5px solid var(--text-2); border-top: none; box-sizing: border-box; }

/* hover tooltip */
#tip { position: fixed; z-index: 20; pointer-events: none; padding: 4px 8px; border-radius: 6px; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 12px; white-space: nowrap; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(10, 12, 16, 0.28); }
.overlay.plain { background: transparent; pointer-events: none; }
.dialog { position: relative; width: min(460px, calc(100vw - 32px)); padding: 18px 20px; pointer-events: auto; }
.dialog h2 { margin: 0 0 12px; font-size: 15px; }
.dialog .close { position: absolute; top: 12px; right: 12px; }
.dialog.wide { width: min(560px, calc(100vw - 32px)); display: grid; gap: 10px; }
.dialog.wide h2 { margin: 0; }
.dialog p.sub { margin: 0; color: var(--text-2); font-size: 12px; line-height: 1.5; }
.dialog code { font-family: var(--mono); font-size: 11.5px; }
.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-foot .sub { font-size: 12px; color: var(--text-3); }
/* The "Embed in a web page" window (embed.js). */
#embed_dialog .dialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
.embed-options { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center; font-size: 13px; }
.embed-options .k { color: var(--text-2); }
.embed-options .checks, .embed-options .size { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.embed-options .check { display: inline-flex; align-items: center; gap: 5px; }
.embed-options .size label { display: inline-flex; align-items: center; gap: 6px; }
.embed-options .size input { width: 64px; height: 28px; }
.embed-options .presets { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.embed-options select { height: 30px; max-width: 100%; }
.embed-options .check:has(input:disabled) { color: var(--text-3); }
#embed_code { width: 100%; font-family: var(--mono); font-size: 11.5px; line-height: 1.45; resize: vertical; word-break: break-all; }
.dialog-foot .buttons { display: flex; gap: 8px; }
#embed_try { text-decoration: none; }
#embed_try:hover { color: var(--accent); }
.dialog-foot .sub.error { color: var(--danger); }
#coords textarea { min-height: 240px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; }
.keys .combo { display: inline-flex; align-items: center; gap: 4px; color: var(--text-3); white-space: nowrap; }
kbd { color: var(--text); font-family: var(--mono); font-size: 11.5px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-2); white-space: nowrap; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; z-index: 50; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 8px 14px; border-radius: 999px; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
#toast.error { color: var(--danger); border-color: var(--danger); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ------------------------------------------------------------ smaller screens
 * Desktop is the layout above. --top-h is the toolbar's bottom edge and
 * --hud-bottom the stats card's, both set by app.js, so panels stack under
 * whatever height the toolbar wraps to. */
.sheet-close { display: none; }

/* Tablet and small laptops: icon-only toolbar, stats under it on the right. */
@media (max-width: 1219px) {
  #toolbar .label { display: none; }
  /* Never wider than the screen: if fonts run wide, the algorithm menu gives up the room. */
  #toolbar { max-width: calc(100vw - 24px); }
  #algorithm { flex: 0 1 auto; min-width: 120px; }
  #hud { top: calc(var(--top-h, 56px) + 8px); width: 220px; }
  #inspector { top: calc(var(--top-h, 56px) + 8px); right: 244px; }
}

/* Compact stats wherever space is short: just time, terminated and the bar. */
@media (max-width: 760px), (max-height: 520px) {
  #hud { padding: 8px 12px; gap: 5px; width: 190px; }
  #hud .hud-extra { display: none !important; }
  .hud-time { font-size: 17px; }
}

/* Short screens (a phone held sideways): tools in a row along the bottom. */
@media (max-height: 520px) {
  #tools { flex-direction: row; }
  #settings { max-height: calc(100vh - var(--top-h, 56px) - 20px); }
  #legend { display: none; }
  #turn_caption, #settings:not([hidden]) ~ #turn_caption { bottom: 68px; left: 12px; width: min(500px, calc(100vw - 100px)); }
}

/* Phones: full-width toolbar, settings as a bottom sheet, tools in a row. */
@media (max-width: 760px) {
  #toolbar { top: 8px; left: 8px; right: 8px; flex-wrap: wrap; justify-content: space-between; row-gap: 6px; }
  #toolbar .brand, #toolbar .divider { display: none; }
  #algorithm { flex: 1 1 150px; min-width: 0; }
  #examples_menu { left: 8px !important; right: 8px; max-width: none; }
  #hud { top: calc(var(--top-h, 96px) + 6px); left: 8px; right: 8px; width: auto; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 12px; }
  #hud .hud-row:first-child { grid-column: 3; grid-row: 1; }
  #hud .hud-time { grid-column: 1; grid-row: 1; }
  #hud .hud-row:not(:first-child) { grid-column: 2; grid-row: 1; justify-content: flex-start; }
  #hud .progress { grid-column: 1 / -1; }
  #hud .hud-row:first-child .k { display: none; }
  #settings { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72vh; border-radius: 16px 16px 0 0; z-index: 25; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18); }
  .sheet-close { display: inline-flex; }
  #tools { left: 8px; right: 8px; bottom: 8px; flex-direction: row; justify-content: space-between; }
  #tools .btn { flex: 1 1 0; min-width: 0; padding: 0; } /* ten buttons share the row, however narrow the phone */
  #legend, #settings:not([hidden]) ~ #legend { left: 8px; right: 8px; bottom: 64px; max-width: none; }
  #turn_caption, #settings:not([hidden]) ~ #turn_caption { left: 8px; right: 8px; bottom: 112px; width: auto; }
  #inspector { top: calc(var(--hud-bottom, 150px) + 6px); left: 8px; right: 8px; width: auto; }
  .menu { right: 8px; bottom: 64px; }
}

/* Touch screens: finger-sized targets. */
@media (pointer: coarse) {
  .btn { height: 40px; min-width: 40px; }
  .btn.small { height: 34px; min-width: 34px; }
  #toolbar select { height: 40px; }
  .field select, .field input[type="number"] { height: 36px; }
  input[type="range"] { height: 28px; }
}

/* Embedded in another page (?embed, see embed.js): the robots and the chosen buttons only. */
body.embed :is(#settings, #hud, #inspector, #legend, #tools, #overview, #examples_menu, #export_menu, #dirty) { display: none !important; }
body.embed #toolbar > :is(.brand, #algorithm, #examples, .divider, #toggle_settings, #docs_link, #play, #step_event, #step_time, #reset, #playback) { display: none; }
body.embed.embed-play #toolbar > #play,
body.embed.embed-step #toolbar > :is(#step_event, #step_time),
body.embed.embed-reset #toolbar > #reset,
body.embed.embed-speed #toolbar > #playback { display: inline-flex; }
body.embed #toolbar { top: 8px; left: 8px; right: auto; padding: 4px; flex-wrap: nowrap; }
body.embed #toolbar .label { display: none; }
/* A finger on the demo scrolls the page around it (the mouse still drags the view). */
body.embed #canvas { touch-action: pan-x pan-y pinch-zoom; }
body.embed #turn_caption { left: 8px; bottom: 8px; width: min(440px, calc(100vw - 16px)); padding: 7px 10px; font-size: 12.5px; }
#embed_open { position: fixed; top: 8px; right: 8px; padding: 6px 10px; font-size: 12px; color: var(--text-2); text-decoration: none; z-index: 6; }
#embed_open:hover { color: var(--accent); }
#embed_open.short { padding: 6px 9px; }
#embed_open.short .long { display: none; }
#embed_open.gone { visibility: hidden; }
/* A small box: the caption keeps to its first line, so the robots keep the room. */
@media (max-height: 360px), (max-width: 340px) {
  body.embed #turn_caption { padding: 5px 9px; }
  body.embed #turn_caption .cap-body { display: none; }
}
