:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #62605a;
  --line: #dcd9d2;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdf0ee;
  --ok: #1a7f37;
  --device: #1b1c1f;
  --device-edge: #2c2e33;
  --oled: #000000;
  --oled-text: #f2f2f2;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141518;
    --panel: #1d1f23;
    --text: #ececea;
    --muted: #a3a19b;
    --line: #34373d;
    --accent: #4c8dff;
    --danger: #ff7b6e;
    --danger-bg: #3a1d1a;
    --ok: #4ac26b;
    --device: #0b0b0c;
    --device-edge: #3a3d44;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141518;
  --panel: #1d1f23;
  --text: #ececea;
  --muted: #a3a19b;
  --line: #34373d;
  --accent: #4c8dff;
  --danger: #ff7b6e;
  --danger-bg: #3a1d1a;
  --ok: #4ac26b;
  --device: #0b0b0c;
  --device-edge: #3a3d44;
  color-scheme: dark;
}

/* .bs is the builder's root: <main> on the standalone page, the div in the
   <bridge-settings> shadow root when embedded (embed.ts turns :root into :host).
   Layout breakpoints are container queries, so they follow the space the
   builder is given, not the browser window. */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); }
.bs {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: left;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  container-type: inline-size;
}
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 12px; }
.lede { color: var(--muted); margin-bottom: 24px; }
.muted { color: var(--muted); font-size: 0.9rem; }

.intro { margin-bottom: 16px; }
.intro .lede { margin-bottom: 0; }

/* Read my bridge / open a saved file */
.start {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  align-items: center;
  justify-content: space-between;
}
.start .start-text { flex: 1 1 360px; }
.start > p { flex-basis: 100%; margin: 0; }

/* Preview first: it's the centrepiece. Form beside it on wide screens, under it on narrow ones. */
.layout {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}
@container (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
.preview-col { position: sticky; top: var(--bs-sticky-top, 16px); }
@container (max-width: 900px) { .preview-col { position: static; max-width: 420px; margin: 0 auto; width: 100%; } }

section.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 0.875rem; margin-top: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }

input[type="text"], input[type="number"], select {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 38px;
  max-width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input.bad { border-color: var(--danger); }
.choice { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

button {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  cursor: pointer;
  min-height: 38px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--accent); padding: 4px 0; min-height: 0; }

/* Axis table */
.axes { width: 100%; border-collapse: collapse; }
.axes th, .axes td { text-align: left; padding: 6px 8px 6px 0; vertical-align: middle; }
.axes th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.axes input[type="text"] { width: 120px; }
@container (max-width: 560px) {
  .axes thead { display: none; }
  .axes tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .axes td { padding: 0; }
  .axes td:first-child { grid-column: 1 / -1; }
  .axes input[type="text"] { width: 100%; }
}

/* Danger mode */
.danger {
  border: 1px solid var(--danger);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.danger strong { color: var(--danger); }

/* MDI pages */
.mdi-page { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.mdi-page:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.mdi-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.slot {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px 12px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}
.slot:last-child { border-bottom: none; }
.slot .slot-name { font-weight: 600; font-size: 0.9rem; padding-top: 8px; }
.slot .slot-body { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.slot .slot-body .line { flex: 1 1 260px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; text-transform: uppercase; }
.slot .slot-body .lbl { width: 120px; }
.slot .slot-body .num { width: 110px; }
.slot .msg { grid-column: 2; color: var(--danger); font-size: 0.85rem; }

/* Problems + download */
.problems { color: var(--danger); margin: 0 0 12px; padding-left: 20px; }
.ready { color: var(--ok); font-weight: 600; }
.steps { padding-left: 20px; margin: 12px 0 0; }
.steps li { margin-bottom: 4px; }
.error { color: var(--danger); margin-top: 8px; white-space: pre-line; }

/* Jump target from the preview */
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }
.flash { animation: flash 1.6s ease-out; border-radius: 6px; }

/* Quick Keys preview, as it sits by default: dial on top, keys in 4 rows of 2 */
.device {
  background: var(--device);
  border: 2px solid var(--device-edge);
  border-radius: 32px;
  padding: 26px 22px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  max-width: 340px;
  margin: 0 auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.dial {
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 6px solid var(--ring, #fff);
  box-shadow: 0 0 16px var(--ring, #fff);
  background: radial-gradient(circle at 40% 35%, #3b3d42, #1a1b1e 70%);
  cursor: pointer;
  padding: 0;
  min-height: 0;
}
.dial.sel { outline: 3px solid var(--accent); outline-offset: 4px; }
.keys { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; }
.key {
  aspect-ratio: 2 / 1;
  background: var(--oled);
  border: 1px solid #33363c;
  border-radius: 8px;
  color: var(--oled-text);
  font: 600 15px/1.15 ui-monospace, "Cascadia Mono", Consolas, monospace;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  min-height: 0;
}
.key:hover { border-color: #5a5e66; }
.key.empty { border-style: dashed; }
.key.opens { color: #9fc3ff; }
.key.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.preview-meta { margin-top: 14px; }
.preview-meta .page-title { font-weight: 700; text-align: center; }
.detail {
  margin-top: 8px;
  min-height: 4.5em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}
.tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 14px; }
.tabs button { padding: 4px 10px; min-height: 32px; font-size: 0.85rem; }
.tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* A saved .uf2 being dragged over the page */
.bs.dropping::after {
  content: "Drop your settings file to open it";
  position: fixed;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
}

.foot { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; }
.foot p { margin: 0 0 4px; }
.foot .licence { margin: 16px 0; }
.foot .revision { margin-top: 12px; font-variant-numeric: tabular-nums; }
.foot .licence h2 { font-size: 0.95rem; margin: 16px 0 6px; color: var(--text); }
.foot .licence ul { margin: 0 0 8px; padding-left: 1.3em; }
.foot .licence li { margin: 2px 0; }
.foot .licence a { color: inherit; }
.foot .licence summary { cursor: pointer; margin-top: 8px; }
.foot .licence pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.75rem; max-height: 24rem; overflow-y: auto; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }

/* "Your machine": collapsible, since it's set once and carried in every file */
details.machine > summary { list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
details.machine > summary::-webkit-details-marker { display: none; }
details.machine > summary h2 { margin: 0; }
details.machine > summary h2::before { content: "▸"; display: inline-block; width: 1.1em; color: var(--muted); transition: transform 0.15s; }
details.machine[open] > summary h2::before { transform: rotate(90deg); }
details.machine[open] > summary { margin-bottom: 12px; }
details.machine .edit { color: var(--accent); }
