.trace {
  --shell: #e4eaf7;
  --shell-ink: #202e4e;
  --shell-line: #abb9d7;
  --scope: #101a31;
  --scope-line: #536b9a;
  --scope-muted: #afbfdf;
  --signal: #99c6ff;
  --signal-deep: #294c94;
  --meter: #4369b7;
  min-width: 0;
  border: 1px solid #7992c5;
  border-radius: .66rem;
  background: var(--shell);
  color: var(--shell-ink);
  color-scheme: light;
  font-family: system-ui, sans-serif;
  box-shadow: 0 1.5rem 5rem #070e28a6, .6rem .64rem 0 #263963, .65rem .69rem 0 #5471a3;
}

.trace[data-tone="wait"] { --signal: #ffd197; --signal-deep: #77512e; --meter: #966331; }
.trace[data-tone="done"] { --signal: #abe2c6; --signal-deep: #255c52; --meter: #387365; }
.window-titlebar {
  display: grid;
  grid-template-columns: 1fr auto 2.3rem;
  align-items: center;
  gap: .8rem;
  min-height: 2.75rem;
  padding: .28rem .48rem .28rem .8rem;
  border-radius: .6rem .6rem 0 0;
  background: #263859;
  color: #f1f5ff;
}
.window-titlebar:has([aria-expanded="false"]) { border-radius: .6rem; }
.window-app { display: flex; align-items: center; gap: .6rem; font: 650 .875rem/1.1 var(--code); }
.window-icon {
  position: relative;
  width: 1.18rem;
  height: 1.01rem;
  border: 1px solid #b7cef8;
  border-top-width: 3px;
  border-radius: .14rem;
}
.window-icon::after {
  position: absolute;
  inset: .28rem .18rem auto;
  height: 2px;
  background: #b7cef8;
  content: '';
}
.window-kind { color: #c8d6ef; font: .69rem/1 var(--code); }
.window-toggle {
  display: grid;
  place-items: center;
  min-width: 2.2rem;
  min-height: 1.95rem;
  border: 1px solid #687fab;
  border-radius: .2rem;
  background: transparent;
  color: #eaf1ff;
  cursor: pointer;
}
.window-toggle::before { width: .57rem; border-top: 1px solid currentColor; content: ''; }
.window-toggle[aria-expanded="false"]::before { height: .53rem; border: 1px solid currentColor; }
.window-toggle:hover { background: #3b507a; }
.trace .window-toggle:focus-visible { outline: 2px solid #eaf1ff; outline-offset: 1px; }

.trace-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: .85rem 1rem;
  padding: 1.15rem clamp(.75rem, 2vw, 1.45rem) .95rem;
}
.trace-header h2 { font-size: clamp(1.8rem, 3.1vw, 3rem); letter-spacing: -.04em; }
.trace-header p { margin-top: .35rem; color: #405176; font-size: .82rem; line-height: 1.4; }
.trace-input { display: grid; gap: .2rem; flex: none; }
.trace-input label { color: #405176; font-size: .71rem; }
.trace-input select {
  max-width: 100%;
  min-height: 2.1rem;
  padding: .28rem .45rem;
  border: 1px solid #869aca;
  border-radius: .2rem;
  background: #f2f5fc;
  color: var(--shell-ink);
  font: 600 .78rem/1.2 system-ui, sans-serif;
}

.trace-scope {
  position: relative;
  margin-inline: clamp(.65rem, 1.65vw, 1.18rem);
  border: 1px solid #536b9a;
  border-radius: .35rem;
  background-color: var(--scope);
  color: #e8efff;
  background-image: radial-gradient(#6485be52 1px, transparent 1px);
  background-size: 12px 12px;
}
.trace-bus {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .55rem;
  margin: 0;
  padding: .7rem;
  list-style: none;
}
.trace-bus li { position: relative; min-width: 0; }
.trace-bus li:not(:last-child)::after {
  position: absolute;
  top: 3.15rem;
  right: -.55rem;
  width: .55rem;
  height: 1px;
  background: #6c85b1;
  content: '';
}
.trace-bus button {
  display: grid;
  justify-items: start;
  align-content: start;
  width: 100%;
  height: 100%;
  min-height: 6.35rem;
  padding: .48rem clamp(.35rem, .7vw, .62rem) .52rem;
  border: 1px solid #526994;
  border-radius: .24rem;
  color: #e4edff;
  background: #1a2a49;
  cursor: pointer;
  text-align: left;
  transition: background-color 260ms ease, border-color 260ms ease, box-shadow 260ms ease;
}
.trace-bus button:disabled { opacity: 1; }
.trace-bus button:hover { border-color: #a4bde9; background: #22385e; }
.trace-bus button:focus-visible, .trace-readout a:focus-visible { outline: 2px solid #ffd197; outline-offset: 2px; }
.trace-bus button[aria-current] {
  border-color: var(--signal);
  background: #243d63;
  box-shadow: inset 0 2px 0 var(--signal);
}
.bus-owner { color: var(--scope-muted); font: .66rem/1.25 var(--code); }
.trace-bus strong { font-size: clamp(.7rem, 1.13vw, .85rem); line-height: 1.2; }
.trace-bus code { margin-top: .2rem; color: var(--scope-muted); font-size: clamp(.61rem, .86vw, .73rem); line-height: 1.27; overflow-wrap: anywhere; }
.bus-icon {
  display: block;
  width: 1.6rem;
  height: 1.05rem;
  position: relative;
  margin: .45rem 0 .44rem;
  color: #9ebbeb;
  transition: color 260ms ease;
}
[aria-current] .bus-icon { color: var(--signal); }
.bus-icon-signal { background: currentColor; clip-path: polygon(0 73%, 26% 73%, 26% 18%, 64% 18%, 64% 73%, 100% 73%, 100% 85%, 57% 85%, 57% 30%, 33% 30%, 33% 85%, 0 85%); }
.bus-icon-wait { width: 1.05rem; border: 1px solid currentColor; border-radius: 50%; }
.bus-icon-wait::after { position: absolute; left: 50%; top: .15rem; width: .28rem; height: .35rem; border: solid currentColor; border-width: 0 0 1px 1px; content: ''; }
.bus-icon-scan { background: repeating-linear-gradient(0deg, transparent 0 4px, currentColor 4px 5px); }
.bus-icon-move { background: currentColor; clip-path: polygon(0 44%, 74% 44%, 57% 14%, 66% 14%, 100% 50%, 66% 86%, 57% 86%, 74% 56%, 0 56%); }

.trace-packet, .trace-transfer {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
}
.trace-packet { width: .44rem; height: .44rem; border-radius: 50%; background: var(--signal); box-shadow: 0 0 .65rem .18rem var(--signal); }
.trace-transfer { width: .7rem; height: .85rem; border: 1px solid #174f42; border-radius: .1rem; background: #9ee2c2; box-shadow: 0 0 .6rem #49866e99; }
.trace-readout {
  padding: .64rem .72rem .72rem;
  border-top: 1px solid #435b86;
  border-radius: 0 0 .3rem .3rem;
  background: #15233d;
  min-height: 5.35rem;
}
.trace-readout-label { display: flex; justify-content: space-between; flex-wrap: wrap; column-gap: .65rem; row-gap: .16rem; }
#trace-event { font-size: .82rem; font-weight: 700; }
#trace-api { max-width: 100%; overflow-wrap: anywhere; color: var(--signal); font: .7rem/1.5 var(--code); text-underline-offset: .2em; transition: color 260ms ease; }
#trace-detail { margin-top: .32rem; color: #c2d0ec; font-size: .79rem; line-height: 1.45; }

.trace-storage {
  position: relative;
  margin-inline: clamp(.66rem, 1.65vw, 1.18rem);
  padding-block: .65rem .7rem;
}
.storage-label { color: #405176; font: .7rem/1.35 var(--code); margin-bottom: .36rem; }
.trace-objects { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .45rem; padding: 0; margin: 0; list-style: none; }
.trace-objects li {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  align-content: start;
  column-gap: .38rem;
  min-height: 3.45rem;
  padding: .42rem .38rem;
  border: 1px solid var(--shell-line);
  border-radius: .24rem;
  background: #f1f5fc;
  transition: background-color 260ms ease, border-color 260ms ease;
}
.trace-objects li[data-active] { border-color: #4b6eb2; background: #d4e2ff; }
.trace[data-tone="wait"] .trace-objects li[data-active] { border-color: #9c703f; background: #f5e4cc; }
.trace[data-tone="done"] .trace-objects li[data-active] { border-color: #649382; background: #d6e9e3; }
.trace-objects strong { font-size: .73rem; line-height: 1.2; }
.trace-objects li > span:last-child { grid-column: 2; margin-top: .18rem; color: #405176; font-size: .7rem; line-height: 1.25; overflow-wrap: anywhere; }
.object-icon { align-self: center; width: .92rem; height: .64rem; position: relative; color: #4b6391; }
.object-folder { border: 1px solid currentColor; border-radius: .1rem; background: #c5d5f5; }
.object-folder::before { position: absolute; top: -.22rem; left: -1px; width: .44rem; height: .2rem; border: 1px solid currentColor; border-bottom: 0; border-radius: .1rem .13rem 0 0; background: #c5d5f5; content: ''; }
.object-queue { border-inline: 1px solid currentColor; background: repeating-linear-gradient(0deg, #6a7fa6 0 1px, transparent 1px 3px); }

.trace-controls {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem 1rem;
  padding: .56rem clamp(.65rem, 1.65vw, 1.18rem) .65rem;
  border-top: 1px solid var(--shell-line);
  border-radius: 0 0 .55rem .55rem;
  background: #d7e1f3;
}
.trace-actions { display: flex; gap: .35rem; }
.trace-actions button {
  background: #edf3fd;
  color: #223354;
  border: 1px solid #8199c3;
  border-radius: .2rem;
  min-height: 2.15rem;
  padding: .33rem .65rem;
  font-size: .77rem;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 200ms ease;
}
.trace-actions button:hover { background: #fff; }
#trace-play { min-width: 5.35rem; background: #294775; color: #f3f7ff; border-color: #294775; }
#trace-play:hover { background: #203b66; }
.trace-controls :focus-visible, .trace-input :focus-visible { outline-color: #294775; outline-offset: 2px; }
.trace-counter { display: flex; align-items: center; gap: .42rem; color: #405176; font: .68rem/1 var(--code); }
.trace-counter > div { width: clamp(2rem, 4.5vw, 4rem); height: 3px; background: #a8b7d3; }
#trace-progress { display: block; width: 100%; height: 100%; background: var(--meter); transform: scaleX(0); transform-origin: left; transition: transform 280ms ease; }
.trace-fallback { margin: .5rem .85rem .8rem; font-size: .82rem; }

@media (max-width: 650px) {
  .trace-header { flex-wrap: wrap; align-items: start; }
  .trace-readout { min-height: 6rem; }
}

@media (max-width: 475px) {
  .trace-bus { grid-template-columns: 1fr; gap: .32rem; align-items: stretch; padding: .55rem; }
  .trace-bus li:not(:last-child)::after { top: auto; bottom: -.33rem; right: auto; left: 1.34rem; width: 1px; height: .33rem; }
  .trace-bus button { min-height: 2.58rem; padding: .3rem .48rem; grid-template-columns: 1.55rem minmax(0, 1fr) auto; gap: .16rem .35rem; align-items: center; align-content: center; }
  .bus-icon { grid-column: 1; grid-row: 1 / 3; margin: 0; width: 1.22rem; height: .88rem; justify-self: center; }
  .bus-icon-wait { width: .88rem; }
  .bus-owner { grid-column: 2; grid-row: 1; }
  .trace-bus strong { grid-column: 2; grid-row: 2; }
  .trace-bus code { grid-column: 3; grid-row: 1 / 3; margin-top: 0; text-align: right; }
  .trace-objects { gap: .32rem; }
  .trace-objects li { grid-template-columns: minmax(0, 1fr); gap: .17rem; padding: .32rem; }
  .trace-objects li > span:last-child { grid-column: 1; margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .trace *, .trace *::before, .trace *::after { transition: none !important; }
}

.trace-transfer[data-kind="queue"] { width: .6rem; height: .4rem; border-color: #7d4b26; background: #ffd197; box-shadow: 0 0 .6rem #a96d42a0; }

.trace-waveforms {
  --cursor: 5%;
  display: grid;
  gap: .25rem;
  padding: 0 .72rem .5rem;
  color: #bac9e5;
  font: .65rem/1.1 var(--code);
}
.trace-waveforms > div {
  display: grid;
  grid-template-columns: 6.65rem minmax(0, 1fr) 5.25rem;
  align-items: center;
  gap: .4rem;
}
.trace-waveforms > div > span:last-child { color: #d3e2ff; text-align: right; }
.trace-samples {
  display: grid;
  height: .91rem;
  position: relative;
  border-inline: 1px solid #59739f;
  background: repeating-linear-gradient(90deg, #627fa329 0 1px, transparent 1px 16px), #0d1729;
}
.trace-samples::after {
  position: absolute;
  inset: 0 auto 0 var(--cursor);
  width: 1px;
  background: #dae5f7a6;
  content: '';
  transition: left 280ms ease;
}
.trace-samples span { position: relative; }
.trace-samples span::before {
  position: absolute;
  inset: 70% 0 auto;
  height: 1px;
  background: #a1c7fe;
  content: '';
}
.trace-samples span[data-level="high"]::before { top: 25%; }
.trace-samples span[data-edge]::after {
  position: absolute;
  inset: 25% auto 26% 0;
  width: 1px;
  background: #a1c7fe;
  content: '';
}
.trace-samples[data-wave="worker"] span::before,
.trace-samples[data-wave="worker"] span[data-edge]::after { background: #ffd197; }

@media (max-width: 475px) {
  .trace-waveforms { padding-inline: .55rem; font-size: .61rem; }
  .trace-waveforms > div { grid-template-columns: 5.45rem minmax(0, 1fr) 4.5rem; gap: .28rem; }
}
