/* Debugger (crates/web/src/debug.rs).
   Desktop: the code dock gets a third column between the code and the serial monitor; the
   editor gives way to the read-only source view. Phone: the run controls are a sheet at the
   bottom; More opens the views under them. */
#code.debugging { grid-template-columns: minmax(0, 1fr) 350px 176px; }
/* The source pane is narrow at 1280: smaller buttons leave the title room. */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
  #code.debugging .code-pane .code-bar { gap: 4px; }
  #code.debugging .code-pane .code-bar button { padding: 0 8px; }
}
/* Up to a 1600 px window the dock is under 900 px wide: debugging, the serial box folds away (Debug off
   brings it back), the Debug column is 350 px (registers and memory rows fit it), and the source gets the rest, long lines wrapping under
   their first character. Wider windows keep the three columns and scroll long lines sideways. */
@media (min-width: 761px) and (max-width: 1599px) and ((min-height: 501px) or (pointer: fine)) {
  #code.debugging { grid-template-columns: minmax(0, 1fr) 350px; }
  #code.debugging .serial-pane { display: none; }
  #code.debugging .sl { min-width: 0; }
  #code.debugging .sl code { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; padding-left: 2ch; text-indent: -2ch; }
}
/* Bench open: the dock is folded to its bar, which keeps the title and Build (Debug and Template come back with the dock). */
body:not(.phone) .app:has(#bench.open) #code .code-bar > :is(#code-debug, #code-template) { display: none; }
/* The editor gives way to the source view, and with it Template and Build; the serial box keeps its
   output and buttons. */
#code.debugging .code-body, #code.debugging #code-template, #code.debugging #code-build,
#code.debugging .serial-pane .code-bar h2 { display: none; }
#code.debugging .serial-pane .code-bar { justify-content: flex-end; }
.dbg-src { display: none; }
#code.debugging .dbg-src {
  display: flex; flex: 1; min-height: 0; flex-direction: column;
  border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--bg);
}
.dbg-src-body {
  position: relative; flex: 1; min-height: 0; overflow: auto; padding: 2px 0;
  font: 12.5px/1.45 ui-monospace, Menlo, monospace;
}
.sl { display: flex; white-space: pre; min-width: max-content; }
.sl code { font: inherit; padding-right: 12px; }
.sl-n {
  position: relative; flex: none; width: 52px; padding-right: 10px; text-align: right;
  color: var(--muted); user-select: none; -webkit-user-select: none; cursor: default;
  background: var(--panel); border-right: 1px solid var(--line); margin-right: 8px;
}
/* A breakpoint can go on lines with code: a dot on hover, red when set. */
.sl.code .sl-n { color: var(--ink); cursor: pointer; }
.sl-n::before {
  content: ""; position: absolute; left: 6px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%;
}
.sl.code .sl-n:hover::before { background: color-mix(in srgb, var(--err) 35%, transparent); }
.sl.bp .sl-n::before, .sl.bp .sl-n:hover::before { background: var(--err); }
.sl.cur { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.sl.cur .sl-n { background: color-mix(in srgb, var(--warn) 30%, var(--panel)); color: var(--ink); font-weight: 600; }
/* Touch: breakpoint rows are as tall as a finger needs. */
body.phone .sl { min-height: 32px; align-items: stretch; }
body.phone .sl-n { display: flex; align-items: center; justify-content: flex-end; }
body.phone .sl code { align-self: center; }
.dbg-note { margin: 10px 12px; color: var(--muted); font: 12px/1.4 system-ui, sans-serif; white-space: normal; }
.dbg-src.running .dbg-src-body .sl.cur { background: transparent; }

.debug-pane {
  position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  padding: 0 12px 10px; border-left: 1px solid var(--line);
}
.dbg-head { display: flex; align-items: center; gap: 8px; }
.dbg-head .dbg-stop { flex: 1; min-width: 0; }
.dbg-more, .dbg-close { display: none; }
.dbg-stop {
  flex: none; height: 54px; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  font-size: 12px; line-height: 16px; overflow: hidden;
}
.dbg-stop > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dbg-reason { font-weight: 600; }
/* While it runs, the Firmware panel beside shows the time; the phone's sheet covers that panel. */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) { .dbg-run-t { display: none; } }
/* The phone shows the run time in the run bar. */
body.phone .dbg-run-t { display: none; }
.dbg-at { font-family: ui-monospace, Menlo, monospace; }
.dbg-count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.dbg-tabs { flex: none; display: flex; gap: 2px; margin-bottom: 6px; }
.dbg-tabs button {
  flex: 1 1 auto; min-width: 0; height: 28px; padding: 0 4px; font-size: 12px; white-space: nowrap;
  background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted);
}
.dbg-tabs button.on { color: var(--ink); border-bottom-color: var(--accent); background: transparent; font-weight: 600; }
.dbg-body {
  flex: 1; min-height: 0; overflow: auto; padding: 6px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
.dbg-body.running > * { opacity: 0.45; }
/* Errors from the inputs: over the bottom of the pane, so nothing moves. */
.dbg-msg {
  position: absolute; left: 12px; right: 12px; bottom: 14px; z-index: 2; display: none;
  padding: 6px 8px; border-radius: 6px; font-size: 12px; background: var(--err-bg); color: var(--err); border: 1px solid var(--err);
}
.dbg-msg.shown { display: block; }

.dbg-list { list-style: none; margin: 0; padding: 0; }
.dbg-row { display: flex; gap: 6px; margin-bottom: 6px; }
.dbg-row input[type="text"] { flex: 1; min-width: 0; height: 30px; padding: 0 8px; font: 12px ui-monospace, Menlo, monospace; }
.dbg-row button, .dbg-row select { height: 30px; flex: none; padding: 0 10px; }
.dbg-check { display: flex; align-items: center; gap: 6px; margin: 2px 0 8px; }

button.dbg-frame {
  width: 100%; display: grid; grid-template-columns: 28px minmax(0, 1fr); text-align: left; gap: 0 4px;
  background: transparent; border: 0; border-radius: 4px; padding: 3px 4px; font-size: 12px;
}
button.dbg-frame.sel { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.fr-n { color: var(--muted); grid-row: span 2; }
.fr-fn, .fr-at { min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fr-fn { font-family: ui-monospace, Menlo, monospace; }
.fr-at { color: var(--muted); }

.reg-grid {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(17, auto); grid-auto-flow: column; gap: 0 8px;
  font: 12px/1.3 ui-monospace, Menlo, monospace;
}
.reg-grid.csr { grid-template-rows: repeat(5, auto); margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
button.reg {
  display: flex; align-items: baseline; gap: 4px; width: 100%; height: 20px; padding: 0 3px; text-align: left;
  background: transparent; border: 0; border-radius: 3px; font: inherit;
}
.reg-n { width: 7ch; flex: none; }
.reg-x { width: 3ch; flex: none; color: var(--muted); }
.reg-grid.csr .reg-x { display: none; }
.reg-grid.csr .reg-n { width: 9ch; }
.reg-v { margin-left: auto; font-variant-numeric: tabular-nums; }
.chg { background: color-mix(in srgb, var(--warn) 24%, transparent); }
button.reg.chg .reg-v { color: var(--warn); font-weight: 600; }

.pregs { font: 12px/1.3 ui-monospace, Menlo, monospace; }
.preg {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 0 10px; padding: 3px 4px; border-radius: 3px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.preg-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preg-a { color: var(--muted); }
.preg-f { grid-column: 1 / -1; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
#dbg-periph { height: 30px; }

.dbg-sym { color: var(--muted); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mem { font: 12px/1.35 ui-monospace, Menlo, monospace; }
.mrow { display: flex; align-items: center; gap: 6px; }
.ma { color: var(--muted); width: 9ch; flex: none; }
button.mw {
  height: 19px; padding: 0 3px; border: 0; border-radius: 3px; background: transparent; font: inherit; white-space: pre;
}
button.mw:disabled { opacity: 1; color: var(--muted); }
.masc { margin-left: auto; white-space: pre; color: var(--muted); }

.bps { margin-top: 4px; border-top: 1px solid var(--line); }
.bpi { display: flex; align-items: center; gap: 8px; min-height: 30px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.bpi-on { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; align-self: stretch; cursor: pointer; }
.bpi-what { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bpi-k { color: var(--muted); width: 56px; flex: none; }
button.bpi-x { width: 28px; height: 26px; padding: 0; flex: none; }

@media (hover: hover) {
  button.reg:hover, button.mw:not(:disabled):hover, button.dbg-frame:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
}

