/* Tildagon live playground — "icon dock + browse flyout" redesign (option 1C).
   Dark, dense, lime accent; tokens transcribed from the design handoff. */

/* IBM Plex, vendored by build.sh into dist/fonts/ (the site stays zero-CDN).
   Opening src/ directly just falls back to the system stacks below. */
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url("fonts/plex-sans-var.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/plex-mono-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/plex-mono-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/plex-mono-600.woff2") format("woff2");
}

:root {
  --bg: #141414;          /* app / dock */
  --page: #0f0f0f;
  --bar: #171717;         /* top bar */
  --flyout: #181818;
  --editor-bg: #161616;
  --card: #191919;        /* info modal */
  --console: #1b1b1b;
  --input: #1d1d1d;
  --btn: #232323;         /* secondary buttons */
  --btn-hover: #2e2e2e;

  --text: #f2f2ef;
  --text-2: #e8e8e5;
  --text-soft: #cfcfca;
  --muted: #9a9a95;
  --dim: #8b8b86;
  --faint: #7d7d78;
  --fainter: #6a6a66;
  --gutter: #4a4a46;

  --accent: #aecb3a;
  --accent-text: #c5df5e;
  --accent-10: rgba(174, 203, 58, 0.1);
  --accent-12: rgba(174, 203, 58, 0.12);
  --accent-22: rgba(174, 203, 58, 0.22);
  --accent-border: rgba(174, 203, 58, 0.4);

  --flash: #f4c430;
  --flash-12: rgba(244, 196, 48, 0.12);
  --flash-20: rgba(244, 196, 48, 0.2);
  --flash-border: rgba(244, 196, 48, 0.4);

  --error: #e07a7a;
  --warn: #d9a441;

  --line-06: rgba(255, 255, 255, 0.06);
  --line-07: rgba(255, 255, 255, 0.07);
  --line-08: rgba(255, 255, 255, 0.08);
  --line-10: rgba(255, 255, 255, 0.1);
  --line-12: rgba(255, 255, 255, 0.12);

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--sans);
  font-size: 14px;
}

body { display: flex; flex-direction: column; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-text); }

button { font-family: inherit; }
.spacer { flex: 1; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--line-12);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* --- top bar ---------------------------------------------------------------- */
header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 54px;
  padding: 0 18px;
  background: var(--bar);
  border-bottom: 1px solid var(--line-07);
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  color: #e9e9e6;
  white-space: nowrap;
}
.brand strong { font-weight: 600; }
.brand-hex { color: var(--accent); font-size: 17px; }
.brand-sub { color: var(--dim); }

.info-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line-12);
  background: var(--btn);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.info-btn:hover { background: var(--btn-hover); }

#btn-new-top {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 13px;
  border-radius: 8px;
  border: 1px solid var(--accent-border);
  background: var(--accent-12);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#btn-new-top:hover { background: var(--accent-22); }

/* --- main layout -------------------------------------------------------------- */
main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#stage {
  flex: 1;
  min-width: 0;
  display: flex;
  position: relative;
}

/* --- icon dock ------------------------------------------------------------------ */
#dock {
  flex: none;
  width: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 13px 0;
  background: var(--bg);
  border-right: 1px solid var(--line-07);
  z-index: 30;
}

#btn-browse {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(174, 203, 58, 0.35);
  background: var(--accent-10);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-browse:hover, body.flyout-open #btn-browse { background: var(--accent-22); }

.dock-rule {
  width: 30px;
  height: 1px;
  background: var(--line-08);
  margin: 3px 0;
}

.dock-label {
  font-size: 9px;
  letter-spacing: 0.05em;
  color: var(--fainter);
  text-transform: uppercase;
}

#now-thumb {
  width: 42px;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(174, 203, 58, 0.5);
  flex: none;
}

/* the collapsed-gallery script strip: one mini thumbnail per demo/snippet
   (the handoff's "thumb" DemoCard layout), title on hover, click to open.
   Doubles as the dock's flexible spacer. */
#dock-tiles {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  overflow-y: auto;
  scrollbar-width: none;
}
#dock-tiles::-webkit-scrollbar { display: none; }
/* the open gallery already lists everything — no need to say it twice
   (visibility keeps the flex layout, drops them from tab order) */
body.flyout-open #dock-tiles { visibility: hidden; }

.dock-tile {
  flex: none;
  width: 46px;
  height: 30px;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--line-12);
  padding: 0;
  cursor: pointer;
}
.dock-tile:hover { border-color: var(--accent); }
.dock-tile.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.dock-tiles-rule {
  flex: none;
  width: 30px;
  height: 1px;
  background: var(--line-08);
  margin: 2px 0;
}

.dock-new {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 17px;
}
.dock-new:hover { border-color: var(--accent); color: var(--accent-text); }

.dock-info {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line-12);
  background: var(--input);
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.dock-info:hover { background: #2a2a2a; color: var(--text-soft); }

/* --- browse flyout ---------------------------------------------------------------- */
#flyout {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 318px;
  background: var(--flyout);
  border-right: 1px solid var(--line-10);
  box-shadow: 14px 0 40px rgba(0, 0, 0, 0.45);
  z-index: 20;
  display: flex;
  flex-direction: column;
}
#flyout[hidden] { display: none; }

.flyout-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 15px 16px 11px;
}
.flyout-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--dim);
  text-transform: uppercase;
}
#btn-flyout-close {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--line-12);
  background: var(--btn);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 12px;
}
#btn-flyout-close:hover { background: var(--btn-hover); }

.flyout-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  margin: 0 16px 10px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--input);
  border: 1px solid var(--line-08);
  flex: none;
}
.search-glyph { font-size: 12px; }
#gallery-search {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  color: var(--text-2);
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
}
#gallery-search::placeholder { color: #6f6f6a; }
#gallery-search::-webkit-search-cancel-button { display: none; }

#gallery-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}

/* display:flex would defeat the hidden attribute (search filter, empty Mine
   section) — same trap as #flyout[hidden]/#screen-boot[hidden] below. */
.card[hidden], .gallery-section[hidden] { display: none; }

.gallery-section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fainter);
  text-transform: uppercase;
}
#mine-head { padding-top: 14px; }
.gallery-section .count { color: #4a4a46; }
.gallery-section .rule { flex: 1; height: 1px; background: var(--line-06); }

#btn-new-flyout {
  width: 100%;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  border-radius: 9px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
#btn-new-flyout:hover { border-color: var(--accent); color: var(--accent-text); }

/* --- demo card (row layout) --------------------------------------------------------- */
.card {
  position: relative;
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 8px;
  border-radius: 9px;
  cursor: pointer;
}
.card:hover { background: #1e1e1e; }
.card.active::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.card .thumb {
  width: 66px;
  height: 42px;
  border-radius: 6px;
  overflow: hidden;
  flex: none;
  border: 1px solid var(--line-08);
}

.card-text { flex: 1; min-width: 0; }
.card-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions { display: flex; gap: 5px; flex: none; }
.card-actions button {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid var(--line-10);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.12s;
}
.card-actions button:hover { opacity: 1; }
.card-flash { color: var(--flash); }
.card-dup { color: var(--text-soft); }
.card-del { color: var(--error); }

/* preview thumbnails: captured badge frames on a skeleton placeholder */
.thumb {
  background: #0a0a0a;
  position: relative;
}
/* Drawn as the round badge screen: a circle as tall as the tile, centred.
   The screen disc is the inscribed circle of the square framebuffer, so a
   full-bleed square image shown round IS exactly the screen. */
.thumb.has-preview::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background-image: var(--preview);
  background-size: 100% 100%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07);
}
.thumb:not(.has-preview)::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.05) 0 38%, transparent 40%),
    linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.035) 50%, transparent 70%);
  background-size: 100% 100%, 220% 100%;
  animation: thumb-sheen 2.2s linear infinite;
}
@keyframes thumb-sheen {
  from { background-position: 0 0, -120% 0; }
  to { background-position: 0 0, 120% 0; }
}

/* --- editor pane -------------------------------------------------------------------- */
#editor-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--editor-bg);
}

#toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-07);
  overflow-x: auto;
  scrollbar-width: thin;
}

#run-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(174, 203, 58, 0.6);
  cursor: help;
}
#run-dot.stale {
  background: var(--error);
  box-shadow: 0 0 8px rgba(224, 122, 122, 0.6);
  animation: pulse 1.2s ease-in-out infinite;
}

#snip-name {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #f0f0ee;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 8px;
  /* the one shrinkable toolbar item: give it a floor so a narrow toolbar
     scrolls instead of squeezing the name to nothing */
  min-width: 6em;
  width: 14em;
  text-overflow: ellipsis;
}
#snip-name:not(.as-label):hover,
#snip-name:not(.as-label):focus {
  border-color: var(--line-12);
  background: var(--input);
  outline: none;
}
#snip-name.as-label { pointer-events: none; }

#dirty-dot { color: var(--warn); flex: none; font-size: 12px; }

.tbtn {
  flex: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-soft);
  background: var(--btn);
  border: 1px solid var(--line-12);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.tbtn:hover:not(:disabled) { background: var(--btn-hover); }
.tbtn:disabled { opacity: 0.4; cursor: default; }

.tbtn-text {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 5px 6px;
}
.tbtn-text:hover:not(:disabled) { background: transparent; color: #e8e8e6; }

#btn-flash {
  border-color: var(--flash-border);
  background: var(--flash-12);
  color: var(--flash);
  font-weight: 600;
  padding: 5px 12px;
}
#btn-flash:hover:not(:disabled) { background: var(--flash-20); }

#toolbar-msg {
  flex: 1;
  min-width: 2rem;
  text-align: right;
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.3s;
}
#toolbar-msg.show { opacity: 1; }

#size-badge {
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  cursor: help;
}
#size-badge.warn { color: var(--warn); }
#size-badge.over { color: var(--error); font-weight: 700; }

#lib-menu { position: relative; flex: none; }
#lib-menu summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: var(--text-soft);
  border: 1px solid var(--line-12);
  background: var(--btn);
  border-radius: 7px;
  font-size: 15px;
  user-select: none;
}
#lib-menu summary::-webkit-details-marker { display: none; }
#lib-menu summary:hover { background: var(--btn-hover); }
#lib-menu .menu-items {
  /* fixed + JS-anchored on open: absolute would be clipped into #toolbar's
     overflow-x:auto scroll container instead of overlaying the editor */
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  min-width: 13.5em;
  background: var(--input);
  border: 1px solid var(--line-12);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}
#lib-menu .menu-items button {
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-radius: 5px;
  padding: 6px 9px;
  cursor: pointer;
  white-space: nowrap;
}
#lib-menu .menu-items button:hover { background: var(--btn); }
#lib-menu .menu-items hr {
  border: none;
  border-top: 1px solid var(--line-08);
  margin: 4px 3px;
}

#editor { flex: 1; min-height: 0; }
#editor .cm-editor { height: 100%; }
#editor .cm-scroller { overflow: auto; }

kbd {
  font: 12px var(--mono);
  color: #dcdcd6;
  background: #0e0e0e;
  border: 1px solid var(--line-12);
  border-radius: 4px;
  padding: 1px 6px;
}
code {
  font: 12px var(--mono);
  color: #c3e88d;
  background: #0e0e0e;
  border-radius: 4px;
  padding: 1px 6px;
}

.swatch-hint {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: linear-gradient(135deg, #f55089 0 50%, #2eadd9 50% 100%);
  vertical-align: -0.05em;
}

/* --- emulator pane ---------------------------------------------------------------- */
#badge-pane {
  flex: none;
  width: 452px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line-07);
  overflow-y: auto;
}

#badge-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  min-height: 0;
}

#badge {
  position: relative;
  width: min(100%, 372px);
  aspect-ratio: 1;
  background: url("badge.png") center / contain no-repeat;
  user-select: none;
  touch-action: none;
}

#screen {
  position: absolute;
  left: 34.11%;
  top: 33.56%;
  width: 32.74%;
  height: 32.74%;
  border-radius: 50%;
  background: #000;
}

#screen-boot {
  position: absolute;
  left: 34.11%;
  top: 33.56%;
  width: 32.74%;
  height: 32.74%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12%;
  font-size: 0.72rem;
  color: var(--dim);
  background: rgba(0, 0, 0, 0.75);
}
#screen-boot.error { color: var(--error); }
/* the explicit display:flex above would defeat the hidden attribute */
#screen-boot[hidden] { display: none; }

#stale-dot {
  position: absolute;
  left: 63%;
  top: 36%;
  color: var(--error);
  font-size: 0.9rem;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.led {
  position: absolute;
  width: 3.2%;
  height: 3.2%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
  transition: background 60ms linear, box-shadow 60ms linear;
}

.btn-hotspot {
  position: absolute;
  width: 8.5%;
  height: 8.5%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  font: 11px var(--mono);
}
#badge:hover .btn-hotspot {
  color: rgba(255, 255, 255, 0.75);
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.25);
}
.btn-hotspot.held {
  color: #10130a !important;
  background: var(--accent) !important;
  border-color: var(--accent) !important;
}

#badge-hint {
  flex: none;
  padding: 0 20px 6px;
  font-size: 12px;
  color: var(--faint);
  text-align: center;
}

/* --- transport ----------------------------------------------------------------- */
#transport {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}

#transport > button {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line-12);
  background: var(--btn);
  color: #e8e8e6;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#transport > button:hover:not(:disabled) { background: var(--btn-hover); }
#transport > button:disabled { opacity: 0.35; cursor: default; }

#speed-wrap { flex: 1; display: flex; align-items: center; min-width: 40px; }
#speed {
  flex: 1;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #2a2a2a;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
#speed::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 0 3px var(--accent-22);
}
#speed::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 0 3px var(--accent-22);
}
#speed::-moz-range-track { height: 6px; border-radius: 3px; background: #2a2a2a; }
/* Firefox paints the track pseudo over the element background, hiding the JS
   gradient fill — use its native progress pseudo for the lime fill instead. */
#speed::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }

#speed-label {
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  color: #c9c9c4;
  min-width: 3.2em;
  text-align: right;
}
.stat {
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  min-width: 4em;
  text-align: right;
}

/* --- console --------------------------------------------------------------------- */
#console {
  flex: none;
  margin: 0 16px 16px;
  border-radius: 8px;
  background: var(--console);
  border: 1px solid var(--line-07);
}
#console summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
#console summary::-webkit-details-marker { display: none; }
.console-arrow { font-size: 9px; transition: transform 0.12s; }
#console[open] .console-arrow { transform: rotate(90deg); }
#console-log {
  margin: 0;
  padding: 6px 14px 10px;
  max-height: 180px;
  overflow-y: auto;
  font: 11.5px/1.45 var(--mono);
  white-space: pre-wrap;
  border-top: 1px solid var(--line-07);
}
.c-out { color: var(--muted); }
.c-err { color: var(--error); }

/* --- info window --------------------------------------------------------------------- */
#info-dialog {
  width: 540px;
  max-width: 88vw;
  max-height: 82vh;
  background: var(--card);
  color: var(--text-2);
  border: 1px solid var(--line-10);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  padding: 0;
}
#info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.info-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line-07);
}
.info-head .brand-hex { font-size: 18px; }
#info-title { flex: 1; font-size: 17px; font-weight: 600; color: var(--text); }
#btn-info-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line-12);
  background: #242424;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 14px;
}
#btn-info-close:hover { background: #2f2f2f; }

.info-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.info-row { display: flex; gap: 12px; }
.info-row > div { font-size: 13.5px; line-height: 1.5; color: #c6c6c1; }
.info-row b { color: #eaeae7; font-weight: 600; }
.info-glyph { flex: none; font-size: 16px; line-height: 1.4; }
.info-hash { font-family: var(--mono); font-size: 15px; color: var(--dim); }
.info-dot { color: var(--accent); }

.info-foot {
  padding: 15px 22px 20px;
  border-top: 1px solid var(--line-07);
  font-size: 12px;
  line-height: 1.55;
  color: var(--dim);
}

/* --- flash dialog ----------------------------------------------------------- */
#flash-dialog {
  background: var(--card);
  color: var(--text-2);
  border: 1px solid var(--line-10);
  border-radius: 12px;
  padding: 0;
  width: min(94vw, 34rem);
  font-size: 0.9rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
#flash-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
#flash-dialog header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line-08);
  background: transparent;
  height: auto;
}
.flash-body { padding: 0.75rem 0.9rem 0.9rem; }
.flash-body p, .flash-body ol { margin: 0.4rem 0; line-height: 1.5; }
.flash-body ol { padding-left: 1.3rem; }
.flash-body button {
  font: inherit;
  font-size: 13px;
  color: var(--text-soft);
  background: var(--btn);
  border: 1px solid var(--line-12);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
}
.flash-body button:hover:not(:disabled) { background: var(--btn-hover); }
.flash-primary { color: var(--accent-text) !important; border-color: var(--accent-border) !important; background: var(--accent-12) !important; }
.flash-primary:hover:not(:disabled) { background: var(--accent-22) !important; }
.flash-err, .err { color: var(--error); }
.flash-ok { color: var(--accent); }
.dim { color: var(--dim); }
.flash-busy { color: var(--dim); }
.flash-anydev {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--dim);
}
.flash-log {
  margin: 0.5rem 0;
  padding: 0.45rem 0.6rem;
  max-height: 11rem;
  overflow-y: auto;
  background: var(--page);
  border: 1px solid var(--line-08);
  border-radius: 6px;
  font: 11.5px/1.5 var(--mono);
  white-space: pre-wrap;
}
.flash-ports { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.5rem 0; }
.flash-port {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  border: 1px solid var(--line-08);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}
.flash-port:has(input:checked) { border-color: var(--accent); }
.flash-port.off { opacity: 0.55; cursor: default; }
.flash-port em { display: block; font-style: normal; font-size: 0.78rem; }
.flash-opts { margin: 0.6rem 0; display: flex; flex-direction: column; gap: 0.5rem; }
.flash-opts input {
  font: inherit;
  color: var(--text-2);
  background: var(--input);
  border: 1px solid var(--line-12);
  border-radius: 5px;
  padding: 0.15rem 0.4rem;
}
.flash-opts fieldset {
  border: 1px solid var(--line-08);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.flash-opts legend { color: var(--dim); font-size: 0.78rem; padding: 0 0.3rem; }
.flash-note { font-size: 0.76rem; margin: 0.1rem 0 0; }
.flash-adv summary { color: var(--dim); font-size: 0.78rem; cursor: pointer; }
.flash-adv label { margin-right: 0.8rem; }
.flash-bar {
  display: inline-block;
  width: 5.5rem;
  height: 0.45rem;
  border: 1px solid var(--line-12);
  border-radius: 4px;
  overflow: hidden;
  vertical-align: middle;
  margin-left: 0.3rem;
}
.flash-bar div { height: 100%; background: var(--accent); }
.flash-bar.warn div { background: var(--warn); }
.flash-bar.over div { background: var(--error); }

/* --- middling widths: shrink the emulator before the editor starves -------------- */
@media (max-width: 1250px) and (min-width: 901px) {
  #badge-pane { width: 380px; }
}

/* --- narrow screens --------------------------------------------------------- */
@media (max-width: 900px) {
  /* dock becomes a bottom bar; flyout covers the viewport; float.js turns the
     badge pane into the draggable PiP disc. */
  main { flex-direction: column-reverse; }

  #dock {
    width: auto;
    height: 54px;
    flex-direction: row;
    gap: 10px;
    padding: 0 12px;
    border-right: none;
    border-top: 1px solid var(--line-07);
  }
  .dock-rule { width: 1px; height: 30px; margin: 0 3px; }
  .dock-label { display: none; }

  /* the script strip scrolls sideways in the bottom bar */
  #dock-tiles {
    flex-direction: row;
    width: auto;
    height: 100%;
    min-width: 0;
    align-items: center;
    padding: 0 2px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .dock-tiles-rule { width: 1px; height: 20px; margin: 0 2px; }

  #stage { flex-direction: column; overflow: hidden; }

  #flyout {
    position: fixed;
    inset: 0;
    width: auto;
    z-index: 45;
    border-right: none;
    box-shadow: none;
  }

  /* Fallback layout if float.js hasn't run yet: badge stacked above editor. */
  #editor-pane { min-height: 0; height: 100%; }
  #badge-pane {
    width: auto;
    border-left: none;
    border-bottom: 1px solid var(--line-07);
  }
  #badge { width: min(100%, 420px); margin: 0 auto; }

  /* ===== floating "picture-in-picture" badge (body.float-active) ===========
     JS (float.js) adds .float-active on narrow screens and .badge-expanded
     when the disc is opened up. Everything here is scoped to those classes so
     the pre-JS fallback above and the desktop layout stay untouched. */
  :root { --mini-size: clamp(150px, 43vw, 220px); }

  /* Editor owns the whole viewport; the badge pane leaves the flow. */
  body.float-active #editor-pane {
    border-right: none;
    min-height: 0;
    height: 100%;
  }

  /* ---- the floating badge (mini) ---- */
  body.float-active #badge-pane {
    position: fixed;
    z-index: 40;
    left: var(--fx, auto);
    top: var(--fy, auto);
    width: var(--mini-size);
    height: var(--mini-size);
    min-width: 0;
    max-width: none;
    padding: 0;
    margin: 0;
    gap: 0;
    background: transparent;
    /* the hexagon clip lives on #badge-stage; a drop-shadow filter (unlike
       box-shadow) hugs that clipped silhouette */
    filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.55));
    touch-action: none;
    transition: filter 120ms ease;
  }
  body.float-active.badge-dragging #badge-pane {
    transition: none;
    filter: drop-shadow(0 16px 40px rgba(0, 0, 0, 0.6))
      drop-shadow(0 0 6px rgba(174, 203, 58, 0.45));
    cursor: grabbing;
  }

  /* In mini, show the screen + LED ring: scale the badge up so the ring
     fills the tile and clip the tile to the badge's own hexagon. The badge
     itself is inert (drag the tile; no accidental tilt or button presses). */
  body.float-active:not(.badge-expanded) #badge-pane { cursor: grab; }
  body.float-active:not(.badge-expanded) #badge-stage {
    position: absolute;
    inset: 0;
    padding: 0;
    overflow: hidden;
    clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
    background: var(--console);
  }
  body.float-active:not(.badge-expanded) #badge {
    width: 100%;
    height: 100%;
    margin: 0;
    transform: scale(1.28);
    transform-origin: center;
    pointer-events: none;
  }
  body.float-active:not(.badge-expanded) #transport,
  body.float-active:not(.badge-expanded) #badge-hint,
  body.float-active:not(.badge-expanded) #console {
    display: none;
  }

  /* ---- the expand / collapse handle ---- */
  .badge-fab {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    line-height: 1;
    color: var(--text-2);
    background: rgba(20, 20, 20, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.22);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    cursor: pointer;
    padding: 0;
  }
  body.float-active:not(.badge-expanded) .badge-fab {
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 22px;
    border-radius: 999px;
    font-size: 0.85rem;
  }

  /* ---- expanded overlay ---- */
  body.float-active.badge-expanded #badge-pane {
    inset: 0;
    z-index: 50;
    width: auto;
    height: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
    filter: none;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 3rem 0 1.4rem;
    overflow-y: auto;
    touch-action: auto;
  }
  body.float-active.badge-expanded #badge-stage {
    flex: none;
    width: 100%;
  }
  body.float-active.badge-expanded #badge {
    width: min(78vw, 340px);
    transform: none;
    pointer-events: auto;
  }
  body.float-active.badge-expanded #transport { width: 100%; }
  body.float-active.badge-expanded #console { width: calc(100% - 32px); }
  /* Touch devices have no hover: surface the button hotspots so they're usable. */
  body.float-active.badge-expanded .btn-hotspot {
    color: rgba(255, 255, 255, 0.75);
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(0, 0, 0, 0.25);
  }
  body.float-active.badge-expanded .badge-fab {
    top: 10px;
    right: 12px;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: 1.1rem;
  }

  /* In mini the button hotspots are far too small to hit — turn them off so a
     stray tap can't fire a badge button (dragging is handled on the disc). */
  body.float-active:not(.badge-expanded) .btn-hotspot { pointer-events: none; }
}
