/* handrail's skin: a phosphor terminal watching a page get used by something that isn't a person.
   "Terminal-green on near-black, tool schemas rendered as live JSON, a blinking agent cursor that
   'clicks' the page itself." Scoped to its exhibit stage; nothing leaks into the frame (SPEC §6). */
@layer skin {
  @scope ([data-skin="handrail"]) {
    :scope {
      --skin-accent: oklch(0.86 0.19 128);
      --skin-bg: oklch(0.14 0.03 150);
      --skin-ink: oklch(0.86 0.13 132);
      --dim: oklch(0.6 0.1 138);
      --rule: color-mix(in oklch, var(--skin-accent) 32%, transparent);
      --glow: 0 0 0.5em color-mix(in oklch, var(--skin-accent) 50%, transparent);
      font: 400 0.8125rem / 1.5 var(--mono);
      text-shadow: var(--glow);
      background-image:
        repeating-linear-gradient(0deg, oklch(0 0 0 / 0.28) 0 1px, transparent 1px 3px),
        radial-gradient(110% 80% at 25% 15%, color-mix(in oklch, var(--skin-accent) 12%, transparent), transparent 70%);
    }

    .hr { display: grid; gap: 1.25rem; align-items: start; }
    @container (width > 40rem) { .hr { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); } }

    /* Left: the page a person sees. A plain issue tracker, nothing agent-shaped about it. */
    .hr__page { display: grid; gap: 0.5rem; padding: 0 1rem 1.25rem; border: 1px solid var(--rule); }
    .hr__bar {
      display: flex; justify-content: space-between; gap: 1rem;
      margin-inline: -1rem; padding: 0.45rem 1rem; border-bottom: 1px solid var(--rule);
      color: var(--dim); font-size: 0.6875rem;
      & span::before { content: '\25CF\00a0\25CF\00a0\25CF\2003'; letter-spacing: -0.1em; }
    }
    /* Narrow stages and posters (down to 240px): the window dots give way to the address */
    @container (width < 20rem) { .hr__bar span::before { content: none; } }
    .hr__no { margin-block-start: 0.6rem; color: var(--dim); }
    .hr__title { font-size: clamp(1.15rem, 3.4cqi, 1.5rem); line-height: 1.15; font-weight: 500; text-wrap: balance; }
    .hr__tags {
      display: flex; flex-wrap: wrap; gap: 0.4rem; min-block-size: 1.7rem;
      & span { padding: 0.1rem 0.45rem; border: 1px solid var(--skin-accent); font-size: 0.6875rem; animation: hr-in 0.5s var(--ease-out); }
      & .hr__none { border-style: dashed; border-color: var(--dim); color: var(--dim); }
    }

    .hr__tools { position: relative; display: grid; gap: 0.5rem; margin-block-start: 0.5rem; }
    .hr__btn {
      block-size: 2.6rem; padding-inline: 0.8rem;
      display: flex; justify-content: space-between; align-items: center;
      border: 1px solid var(--skin-accent);
      text-transform: uppercase; letter-spacing: 0.14em;
      /* the attribute handrail reads, shown as the button's second name */
      &::after { content: attr(hx-tool); text-transform: none; letter-spacing: 0; color: var(--dim); }
      &:hover { background: color-mix(in oklch, var(--skin-accent) 14%, transparent); }
      &:focus-visible { outline-color: var(--skin-accent); }
    }
    .hr__btn--hit-a { animation: hr-hit-a 0.9s var(--ease-out); }
    .hr__btn--hit-b { animation: hr-hit-b 0.9s var(--ease-out); }

    /* The cursor: the server says which tool was pressed (--at) and by whom; CSS walks it there */
    .hr__cursor {
      position: absolute; top: 0; inset-inline-start: 58%;
      translate: 0 calc(var(--at) * 3.1rem + 1.15rem);
      transition: translate 0.7s var(--ease-out);
      pointer-events: none;
      &::before {
        content: ''; display: block; inline-size: 1rem; block-size: 1.45rem;
        background: var(--skin-accent);
        clip-path: polygon(0 0, 0 100%, 30% 76%, 50% 100%, 66% 93%, 46% 68%, 84% 68%);
        animation: hr-blink 1.1s steps(2, jump-none) infinite;
      }
      &::after {
        content: attr(data-who); position: absolute; top: 1.2rem; left: 0.9rem;
        padding: 0 0.3rem; background: var(--skin-accent); color: var(--skin-bg); text-shadow: none;
        font-size: 0.625rem; letter-spacing: 0.12em; text-transform: uppercase;
      }
    }

    /* Right: what the agent reads instead of a screenshot */
    .hr__agent { display: grid; gap: 0.6rem; min-inline-size: 0; container-type: inline-size; }
    .hr__head {
      display: flex; justify-content: space-between; gap: 1rem;
      padding-block-end: 0.3rem; border-bottom: 1px solid var(--rule);
      font-size: 0.6875rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim);
    }
    .hr__json {
      font: inherit; font-size: 0.75rem; line-height: 1.5; color: var(--dim);
      white-space: pre-wrap; overflow-wrap: anywhere;
      & em { font-style: normal; color: var(--skin-ink); }
      & [data-hot] { color: var(--skin-ink); background: color-mix(in oklch, var(--skin-accent) 16%, transparent); transition: background 0.4s; }
    }
    .hr__log {
      display: grid; gap: 0.45rem; font-size: 0.75rem;
      & li { display: grid; grid-template-columns: 3.4em 4.2em minmax(0, 1fr); column-gap: 0.5em; animation: hr-in 0.5s var(--ease-out); }
      & li > span:first-child { color: var(--dim); }
      & li[data-who="you"] > span:nth-child(2) { justify-self: start; padding-inline: 0.25em; background: var(--skin-accent); color: var(--skin-bg); text-shadow: none; }
      & code { font: inherit; color: var(--skin-ink); overflow-wrap: anywhere; }
      & li > span:last-child { grid-column: 3; color: var(--dim); }
    }
    /* The live log fills up to four calls; reserve them so the stage never grows under the reader (CLS).
       A call is two lines when its code fits on one, three when it wraps, four or five on the narrowest.
       Live stage only: a poster is a still and keeps its own height. */
    :scope.exhibit__stage .hr__log { --rows: 3; align-content: start; min-block-size: calc(4 * var(--rows) * 1lh + 3 * 0.45rem); }
    @container (width >= 30rem) { :scope.exhibit__stage .hr__log { --rows: 2; } }
    @container (width < 18rem) { :scope.exhibit__stage .hr__log { --rows: 4.5; } }
    /* Stacked (narrow) stage: issue titles run one or two lines; hold two so the log below stays put. */
    @container (width <= 40rem) { :scope.exhibit__stage .hr__title { min-block-size: 2lh; } }

    /* Frame-owned pins (A–D) sit where the plate's notes point */
    [data-note] { font-weight: 400; text-shadow: none; }
    .hr__tools > [data-note] { position: absolute; top: -1.6rem; inset-inline-end: 0; }

    @media (prefers-reduced-motion: reduce) {
      .hr__btn, .hr__tags span, .hr__log li, .hr__cursor::before { animation: none; }
      .hr__cursor { transition: none; }
    }
  }

  /* Keyframes are global names, so they live beside the scope, prefixed hr- */
  @keyframes hr-hit-a { from { background: var(--skin-accent); color: var(--skin-bg); text-shadow: none; } }
  @keyframes hr-hit-b { from { background: var(--skin-accent); color: var(--skin-bg); text-shadow: none; } }
  @keyframes hr-blink { 50% { opacity: 0.15; } }
  @keyframes hr-in { from { opacity: 0; translate: 0 -0.4rem; } }
}
