/* The playthrough player (player.js). Uses tokens.css only. */

.pt { display: block; }

/* Desks: three tabs, underlined when chosen */
/* The line is drawn inside the padding (not a border) so the chosen tab's underline covers it and the 5px focus ring isn't clipped. */
.pt-desks { display: flex; gap: var(--space-4); background: linear-gradient(var(--line), var(--line)) left 0 bottom 5px / 100% 1px no-repeat; margin-bottom: var(--space-3); padding: 5px 5px 6px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.pt-desk {
  font: inherit; font-weight: 700; color: var(--muted); background: none; border: 0; padding: var(--space-2) 0;
  border-bottom: 3px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap;
}
.pt-desk[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.pt-desk:hover:not([aria-pressed="true"]) { color: var(--ink); }

/* Inbox: the desk's requests, like slips in a queue */
.pt-inbox { list-style: none; margin: 0 0 var(--space-4); padding: 5px; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--space-2); }
.pt-item {
  width: 100%; height: 100%; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 0;
  padding: var(--space-2) var(--space-3); display: flex; flex-direction: column; gap: 2px;
}
.pt-item:hover { border-left-color: var(--steel); }
.pt-item[aria-current="true"] { border-left-color: var(--ink); background: var(--paper); }
.pt-item-title { font-weight: 700; font-size: var(--step--1); line-height: 1.3; }
.pt-item-from { font-size: 0.8rem; color: var(--muted); }
.pt-item-seen { font-size: 0.75rem; color: var(--muted); margin-top: auto; }
.pt-item-seen::before { content: "✓ "; }

/* Stage: the request and the answer on the left, the trace on the right */
.pt-stage { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.25fr); gap: var(--space-4); align-items: start; }
.pt-left { display: grid; gap: var(--space-4); position: sticky; top: var(--space-4); }

/* The request, styled like where it arrived */
.pt-request { background: var(--surface); border: 1px solid var(--line); padding: var(--space-4); }
.pt-req-head { display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--step--1); color: var(--muted); padding-bottom: var(--space-2); border-bottom: 1px solid var(--line); margin-bottom: var(--space-3); }
.pt-req-kind { font-weight: 700; color: var(--ink); }
.pt-request[data-kind="ticket"] { border-top: 4px solid var(--ink); }
.pt-request[data-kind="email"] { border-top: 4px solid var(--steel); }
.pt-request[data-kind="question"] { border-top: 4px solid var(--muted); }
.pt-req-subject { font-size: var(--step-1); line-height: 1.25; margin: 0 0 var(--space-2); }
.pt-req-body { margin: 0; }

/* Controls */
.pt-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.pt-btn {
  font: inherit; font-size: var(--step--1); color: var(--ink); background: var(--surface); cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.35rem 0.75rem;
}
.pt-btn:hover:not(:disabled) { border-color: var(--ink); }
.pt-btn:disabled { color: var(--muted); cursor: default; opacity: 0.6; }
.pt-play { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; min-width: 7.5rem; }
.pt-play:hover:not(:disabled) { background: var(--steel-strong); border-color: var(--steel-strong); }
.pt-progress { margin-left: auto; font-size: var(--step--1); color: var(--muted); }

/* The trace: a timeline down a rail */
.pt-steps { list-style: none; margin: 0; padding: 0 0 0 var(--space-4); border-left: 2px solid var(--line); min-height: 12rem; }
.pt-steps:empty::before {
  content: "Press Play to watch Keelson work this out, or Next step to go at your own pace.";
  display: block; color: var(--muted); padding: var(--space-3) 0;
}
.pt-step { position: relative; padding-bottom: var(--space-4); }
.pt-step::before {
  content: ""; position: absolute; left: calc(-1 * var(--space-4) - 8px); top: 0.35em;
  width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink);
}
.pt-step[data-state="thinking"]::before, .pt-step[data-state="working"]::before { background: var(--safety); border-color: var(--safety); }
.pt-step[data-state="done"]::before { background: var(--ink); }
.pt-step[data-state="done"][data-status="fault"]::before { background: var(--fault); border-color: var(--fault); }

.pt-think { margin: 0 0 var(--space-2); color: var(--muted); font-style: italic; min-height: 1.5em; }
.pt-call { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); font-family: var(--font-code); font-size: 0.82rem; }
.pt-sys { font-family: var(--font-text); font-size: 0.78rem; font-weight: 700; border: 1px solid currentColor; padding: 0 0.4em; border-radius: var(--radius); color: var(--steel); }
.pt-sys[data-sys="ION"] { color: var(--ink); }
.pt-sys[data-sys="Catalogue"] { color: var(--muted); }
.pt-tool { font-weight: 600; }
.pt-args { color: var(--muted); overflow-wrap: anywhere; }
.pt-step[data-state="working"] .pt-args::after { content: " …"; }
.pt-summary { margin: var(--space-2) 0 0; font-weight: 700; }
.pt-step[data-status="fault"][data-state="done"] .pt-summary { color: var(--fault); }

/* The reply, on green-bar paper with tractor-feed holes */
.pt-reply { margin-top: var(--space-2); }
.pt-reply > summary { color: var(--steel); cursor: pointer; font-size: var(--step--1); width: fit-content; }
.pt-reply > summary:hover { text-decoration: underline; }
.greenbar {
  --row: 1.5em; --holes: 1.4rem;
  margin-top: var(--space-2); background: var(--surface); border: 1px solid var(--greenbar-rule);
  padding: 0 var(--holes); position: relative; font-family: var(--font-code); font-size: 0.78rem;
}
.greenbar::before, .greenbar::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: var(--holes);
  background: radial-gradient(circle at 50% 50%, var(--paper) 0 0.24rem, var(--line) 0.26rem 0.3rem, transparent 0.32rem) 0 0 / 100% calc(var(--row) * 2) repeat-y;
}
.greenbar::before { left: 0; border-right: 1px dashed var(--greenbar-rule); }
.greenbar::after { right: 0; border-left: 1px dashed var(--greenbar-rule); }
.greenbar-head { margin: 0; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--greenbar-rule); display: flex; gap: var(--space-2); overflow-wrap: anywhere; }
.greenbar-head span { font-family: var(--font-text); font-weight: 700; flex: none; }
.greenbar-body {
  margin: 0; padding: 0 var(--space-3); overflow-x: auto; line-height: var(--row); max-height: 22em;
  background: repeating-linear-gradient(var(--greenbar) 0 calc(var(--row) * 3), transparent calc(var(--row) * 3) calc(var(--row) * 6));
  background-attachment: local;
}
.gb-line { display: block; white-space: pre; }
.greenbar-more { margin: 0; padding: var(--space-1) var(--space-3); font-family: var(--font-text); color: var(--muted); border-top: 1px solid var(--greenbar-rule); }

/* The answer */
.pt-answer { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--ink); padding: var(--space-4); }
.pt-answer:focus { outline: none; }
.pt-answer-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-3); }
.pt-answer-head h3 { margin: 0; font-size: var(--step-1); }
.pt-toggles { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); }
.pt-toggle { font: inherit; font-size: var(--step--1); background: var(--surface); color: var(--muted); border: 0; padding: 0.3rem 0.7rem; cursor: pointer; }
.pt-toggle + .pt-toggle { border-left: 1px solid var(--line); }
.pt-toggle:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.pt-toggle:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.pt-toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.pt-answer-text { white-space: pre-wrap; margin: 0 0 var(--space-3); }
.pt-answer-text[data-view="plain"] { font-size: var(--step-1); line-height: 1.45; }
.pt-answer-text[data-view="note"] { font-size: var(--step--1); }
.pt-copy { margin-bottom: var(--space-3); }
.pt-answer-diagram { width: 100%; max-width: 100%; margin: 0 0 var(--space-3); overflow-x: auto; }
.pt-answer-diagram svg { max-width: none; height: auto; }
.pt-answer-diagram-source { max-width: 100%; overflow-x: auto; white-space: pre; }
.pt-tally { margin: 0 0 var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line); font-weight: 700; }
.pt-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.pt-next { font: inherit; color: var(--steel); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.pt-next:hover { text-decoration: underline; }
.pt-error { color: var(--fault); }

/* Focus is always visible */
.pt :focus-visible { outline: 2px solid transparent; outline-offset: 3px; box-shadow: var(--focus); }
@media (forced-colors: active) {
  .pt :focus-visible { outline-color: Highlight; }
}

/* Narrower screens: the inbox scrolls sideways, the stage stacks */
@media (max-width: 1100px) {
  .pt-inbox { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(12rem, 1fr); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: var(--space-2); }
  .pt-inbox > li { scroll-snap-align: start; }
}
@media (max-width: 900px) {
  .pt-stage { grid-template-columns: minmax(0, 1fr); }
  .pt-left { position: static; display: contents; }
  .pt-request { order: 1; }
  .pt-trace { order: 2; }
  .pt-answer { order: 3; }
  .pt-stage { display: flex; flex-direction: column; }
}
@media (max-width: 720px) {
  .pt-desks { flex-wrap: wrap; gap: 0 var(--space-3); background: none; }
  .pt-desk { flex: none; }
}
@media (max-width: 480px) {
  .pt-request, .pt-answer { padding: var(--space-3); }
  .pt-steps { padding-left: var(--space-3); }
  .pt-step::before { left: calc(-1 * var(--space-3) - 8px); }
  .greenbar { --holes: 0.9rem; }
}

/* The systems strip: every system this example touches, in order. Lit once used; the newest is active. */
.pt-strip { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); counter-reset: none; }
.pt-node {
  position: relative; display: flex; flex-direction: column; padding: var(--space-1) var(--space-3);
  border: 1.5px solid var(--line); background: var(--surface); color: var(--muted); min-width: 6.5rem;
  transition: border-color 0.25s, background-color 0.25s, color 0.25s;
}
.pt-node[data-via="connector"] { border-style: dashed; }
.pt-node + .pt-node::before { content: ""; position: absolute; left: calc(-1 * var(--space-2) - 1.5px); top: 50%; width: var(--space-2); border-top: 1.5px solid var(--line); }
.pt-node-name { font-weight: 700; }
.pt-node-what { font-size: 0.78rem; }
.pt-node[data-lit] { border-color: var(--ink); color: var(--ink); background: var(--greenbar); }
.pt-node[data-lit] + .pt-node[data-lit]::before { border-color: var(--ink); }
.pt-node[data-active] { box-shadow: 0 0 0 3px var(--safety); }
.pt-sys[data-via="connector"] { border-style: dashed; color: var(--muted); }
