/* TPM 2.0 playground widget, scoped under .tpm and mapped onto the site's
   rack-room palette. Loaded per-page via front matter. The wire view colors
   each field like a logic analyzer channel; the legend in the wire pane is
   the key. */

.tpm {
  --tpm-surface: #0d1014;
  --tpm-surface-2: #11151b;
  --tpm-ok: #7ccb8b;
  --tpm-bad: #e5534b;
  --tpm-ch-tag: #5cc8e8;
  --tpm-ch-size: #7b869c;
  --tpm-ch-cc: var(--orange);
  --tpm-ch-hnd: #b48ee8;
  --tpm-ch-auth: #e87f9b;
  --tpm-ch-par: #7ccb8b;
  font-family: var(--mono);
  font-size: 0.8rem;
  margin: 1.7rem 0;
}

/* Break the widget out of the 48rem prose measure on desktop, like a
   full-bleed figure: the text keeps its reading width, the instrument gets
   room for its byte lanes. 100% here is the width of the prose column, so
   the negative margin centers the wider widget in the viewport. */
@media (min-width: 900px) {
  .tpm {
    --tpm-w: min(74rem, calc(100vw - 3rem));
    width: var(--tpm-w);
    margin-left: calc((100% - var(--tpm-w)) / 2);
  }
}

.tpm .card {
  background: var(--tpm-surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.9rem 1rem;
}

.tpm .label {
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
}
.tpm .label::before { content: '/ '; color: var(--orange); }

.tpm button {
  font: inherit;
  font-size: 0.78rem;
  background: var(--tpm-surface-2);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
.tpm button:hover { border-color: var(--orange); }
.tpm button:focus-visible, .tpm input:focus-visible, .tpm select:focus-visible,
.tpm textarea:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.tpm button.danger:hover { border-color: var(--tpm-bad); color: var(--tpm-bad); }

.tpm input[type=text], .tpm input[type=number], .tpm select, .tpm textarea {
  font: inherit;
  font-size: 0.78rem;
  background: var(--tpm-surface-2);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.42rem 0.6rem;
}
.tpm input[type=number] { width: 4.2rem; }
.tpm input[type=text] { flex: 1; min-width: 6rem; }
.tpm select { width: 4.2rem; }
.tpm textarea { width: 100%; min-height: 3.6rem; resize: vertical; word-break: break-all; }

/* power strip */
.tpm .powerstrip {
  display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.tpm .led {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: #3a4250; box-shadow: 0 0 0 3px rgba(255,255,255,.04);
  transition: background .4s, box-shadow .4s;
}
.tpm .led.on   { background: var(--tpm-ok);  box-shadow: 0 0 9px 1px rgba(124,203,139,.55); }
.tpm .led.boot { background: var(--orange);  box-shadow: 0 0 9px 1px rgba(255,138,0,.55); }
.tpm .led.dead { background: var(--tpm-bad); box-shadow: 0 0 9px 1px rgba(229,83,75,.55); }
.tpm .powerstat { flex: 1; min-width: 10rem; line-height: 1.35; }
.tpm .powerstat b {
  display: block; font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--bright);
}
.tpm .powerstat small { color: var(--muted); font-size: 0.72rem; }

/* state bar */
.tpm .statebar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
  gap: 0.7rem; margin-bottom: 1rem;
}
.tpm .statebar h3 {
  margin: 0 0 0.5rem; font-size: 0.7rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.tpm .statebar h3::before { content: '/ '; color: var(--orange); }
.tpm .kv { display: flex; justify-content: space-between; gap: 0.7rem; font-size: 0.74rem; line-height: 1.75; }
.tpm .kv b { font-weight: 400; color: var(--muted); }
.tpm .kv span { text-align: right; word-break: break-all; }
.tpm .pcr { display: flex; gap: 0.55rem; font-size: 0.72rem; line-height: 1.75; }
.tpm .pcr b { color: var(--muted); font-weight: 400; width: 1rem; flex: none; }
.tpm .pcr span { word-break: break-all; transition: color .3s; }
.tpm .pcr span.flash { color: var(--orange); }

/* commands | wire */
.tpm .duo {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 1rem; align-items: start;
}
/* in the wide breakout, cap the command column and give the wire the rest */
@media (min-width: 1100px) {
  .tpm .duo { grid-template-columns: minmax(19rem, 23rem) minmax(0, 1fr); }
}
@media (max-width: 900px) { .tpm .duo { grid-template-columns: 1fr; } }

.tpm .chap {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--orange);
  margin: 1.1rem 0 0.5rem; padding-top: 0.9rem; border-top: 1px solid var(--rule);
}
.tpm .chap:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.tpm .cmd { margin-bottom: 0.6rem; padding: 0.7rem 0.8rem; }
.tpm .cmd .row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.tpm .cmd .row + .row { margin-top: 0.5rem; }
.tpm .cmd p { margin: 0.5rem 0 0; font-size: 0.72rem; line-height: 1.55; color: var(--muted); }
.tpm .cmd label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.72rem; color: var(--muted); }
.tpm .steps { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.tpm .steps button { text-align: left; }
.tpm .steps button:disabled { opacity: 0.38; cursor: default; }
.tpm .steps button:disabled:hover { border-color: var(--rule); }
.tpm .steps button.done { border-color: var(--tpm-ok); color: var(--muted); }

/* the wire */
.tpm .wire {
  position: sticky; top: 1rem;
  max-height: min(88vh, 42rem); overflow-y: auto;
  padding: 0 1rem 1rem;
  scrollbar-color: var(--rule) transparent; scrollbar-width: thin;
}
@media (max-width: 900px) { .tpm .wire { position: static; max-height: 34rem; } }
.tpm .wire::-webkit-scrollbar { width: 9px; }
.tpm .wire::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 4px; }

.tpm .wirehead {
  position: sticky; top: 0; z-index: 5;
  background: var(--tpm-surface);
  padding: 0.9rem 0 0.5rem;
  box-shadow: 0 6px 8px -6px rgba(0,0,0,.6);
}
.tpm .legend { display: flex; flex-wrap: wrap; gap: 0.35rem 0.8rem; margin-top: 0.4rem; font-size: 0.7rem; color: var(--muted); }
.tpm .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }

.tpm .xchg {
  border: 1px solid var(--rule); border-radius: 4px;
  background: var(--tpm-surface-2); overflow: hidden; margin-top: 0.8rem;
}
.tpm .xchg .head { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; padding: 0.6rem 0.8rem 0; }
.tpm .xchg .name { font-weight: 600; font-size: 0.8rem; color: var(--bright); }
.tpm .chip { font-size: 0.66rem; font-weight: 600; border-radius: 999px; padding: 0.22rem 0.55rem; }
.tpm .chip-ok  { color: var(--tpm-ok);  background: rgba(124,203,139,.12); }
.tpm .chip-bad { color: var(--tpm-bad); background: rgba(229,83,75,.14); }
.tpm .sum { padding: 0.25rem 0.8rem 0; margin: 0; font-size: 0.74rem; line-height: 1.55; color: var(--muted); }

.tpm .lane { padding: 0.55rem 0.8rem 0.1rem; }
.tpm .dir {
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 0.25rem;
}
.tpm .bytes { font-size: 0.72rem; line-height: 1.9; word-break: break-all; }
.tpm .seg { padding: 2px 1px; border-bottom: 2px solid; cursor: default; }
.tpm .seg + .seg { margin-left: 6px; }
.tpm .seg.hot, .tpm tr.hot td { background: rgba(255,138,0,.16); }
.tpm .c-tag  { border-color: var(--tpm-ch-tag);  color: var(--tpm-ch-tag); }
.tpm .c-size { border-color: var(--tpm-ch-size); color: var(--tpm-ch-size); }
.tpm .c-cc   { border-color: var(--tpm-ch-cc);   color: var(--tpm-ch-cc); }
.tpm .c-hnd  { border-color: var(--tpm-ch-hnd);  color: var(--tpm-ch-hnd); }
.tpm .c-auth { border-color: var(--tpm-ch-auth); color: var(--tpm-ch-auth); }
.tpm .c-par  { border-color: var(--tpm-ch-par);  color: var(--tpm-ch-par); }
.tpm .c-rc-ok  { border-color: var(--tpm-ok);  color: var(--tpm-ok); }
.tpm .c-rc-bad { border-color: var(--tpm-bad); color: var(--tpm-bad); font-weight: 600; }

@keyframes tpm-clockin { from { opacity: 0; transform: translateX(-4px); } }
.tpm .fresh .seg { animation: tpm-clockin .22s both; }
@media (prefers-reduced-motion: reduce) { .tpm .fresh .seg { animation: none; } }

.tpm .xchg details { border-top: 1px solid var(--rule); margin-top: 0.5rem; }
.tpm .xchg summary {
  cursor: pointer; padding: 0.45rem 0.8rem; font-size: 0.64rem; font-weight: 600;
  letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted);
}
.tpm .xchg table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.tpm .xchg td { padding: 0.3rem 0.8rem; border-top: 1px solid var(--rule); vertical-align: top; }
.tpm .xchg td.f { font-weight: 600; white-space: nowrap; }
.tpm .xchg td.v { word-break: break-all; }
.tpm .xchg td.d { color: var(--muted); min-width: 30%; }
.tpm .xchg td.tsep { text-align: center; color: var(--muted); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.1em; }

.tpm .verdict { border-top: 1px dashed var(--rule); padding: 0.55rem 0.8rem; font-size: 0.74rem; line-height: 1.55; }
.tpm .verdict.v-ok { color: var(--tpm-ok); }
.tpm .verdict.v-bad { color: var(--tpm-bad); }
.tpm .verdict code { font-weight: 600; color: var(--bright); background: none; }
.tpm .trap { margin: 0; padding: 0.55rem 0.8rem; font-size: 0.7rem; color: var(--tpm-bad); white-space: pre-wrap; }
.tpm .fatal { padding: 0.9rem; color: var(--tpm-bad); }

.tpm .caption { font-size: 0.72rem; line-height: 1.6; color: var(--muted); margin: 0.7rem 0 0; max-width: 70ch; }
