/* Keygraph graphic primitives: lattice, pills, callout, panel, product window,
   terminal, isometric blocks, dot streams and the motion keyframes. Load after
   tokens.css. Every value comes from the tokens; values match keygraph.io. */

.kg-ground { background: var(--canvas); color: var(--ink); font-family: var(--font-sans); }

/* Lattice: the container draws top and left hairlines, cells draw right and
   bottom; an 11px registration cross (2px bars) sits on every cell corner. */
.kg-lattice { display: grid; border-top: 1px solid var(--hairline); border-left: 1px solid var(--hairline); position: relative; }
.kg-lattice > * { position: relative; border-right: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline);
  padding: var(--cell-x) var(--cell-x) var(--cell-y-foot); }
.kg-lattice > *::after, .kg-lattice::before { content: ""; position: absolute; width: 11px; height: 11px; z-index: 1; pointer-events: none;
  background: linear-gradient(var(--hairline), var(--hairline)) 0 4.5px / 11px 2px no-repeat,
              linear-gradient(var(--hairline), var(--hairline)) 4.5px 0 / 2px 11px no-repeat; }
.kg-lattice > *::after { right: -6px; bottom: -6px; }
.kg-lattice::before { left: -6px; top: -6px; }
.kg-band { border: 1px solid var(--hairline); border-bottom: 0; padding: var(--band-y) var(--gutter); text-align: center; }
.kg-cell-sub { font-family: var(--font-mono); font-size: 13px; line-height: 1.6; letter-spacing: 0.52px; color: var(--text-sec); margin: 0 0 10px; }
.kg-cell-h { font-size: 16px; font-weight: 700; letter-spacing: -0.16px; color: var(--ink); margin: 0 0 8px; }
.kg-cell-p { font-size: 14px; line-height: 1.6; color: var(--text-sec); margin: 0; }
.kg-link-caps { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 1.32px; text-transform: uppercase; color: var(--orange-text); text-decoration: none; }

/* Pills: ivory primary with canvas ink, charcoal ghost with ink. Both turn
   orange with a white label on hover and keyboard focus. */
.kg-pill { display: inline-flex; align-items: center; gap: 10px; font: 600 15px/1 var(--font-sans); padding: 13px 24px; border-radius: var(--radius-pill);
  background: var(--button); color: var(--canvas); border: 1px solid var(--button); text-decoration: none; cursor: pointer;
  transition: background var(--dur-hover), color var(--dur-hover), border-color var(--dur-hover), transform var(--dur-hover); }
.kg-pill.is-ghost { background: var(--control); color: var(--ink); border-color: var(--control); }
.kg-pill:hover, .kg-pill:focus-visible, .kg-pill.is-hover { background: var(--orange); color: var(--white); border-color: var(--orange); }
.kg-pill:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.kg-pill-split { width: 1px; align-self: stretch; background: var(--hairline); margin: -13px 0; }

/* Callout: dashed ivory frame over a translucent canvas fill, square corners. */
.kg-callout { border: 1px dashed var(--callout-rule); background: var(--callout-fill); padding: 18px 20px 19px; max-width: 260px; }
.kg-callout-h { font-size: 18px; line-height: 27px; font-weight: 700; letter-spacing: -0.18px; color: var(--ink); margin: 0; }
.kg-callout-p { font-size: 15px; line-height: 1.5; color: var(--text-sec); margin: 4px 0 0; }

/* Panels and product windows. */
.kg-panel { background: var(--panel); border-radius: var(--radius-panel); overflow: hidden; }
.kg-window { background: var(--window); border-radius: var(--radius-window) var(--radius-window) 0 0; border: 1px solid var(--hairline); border-bottom: 0; overflow: hidden; }
.kg-window-bar { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--hairline); }
.kg-window-bar i { width: 9px; height: 9px; border-radius: 50%; background: var(--chrome-dot); display: block; }

/* Terminal. */
.kg-term { background: var(--panel); border: 1px solid var(--hairline); }
.kg-term-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--hairline);
  font: 600 10.5px/1 var(--font-mono); letter-spacing: 2.1px; text-transform: uppercase; color: var(--text-tri); }
.kg-term pre { margin: 0; padding: 20px 24px 22px; font: 400 12.5px/1.85 var(--font-mono); color: rgba(243, 243, 243, 0.9); white-space: pre-wrap; }
.kg-term .c { color: var(--text-tri); } .kg-term .p { color: var(--orange-text); }

/* Isometric blocks (SVG), the site's .kg-isoart rules. Class names match the
   drawings on keygraph.io: ib-top / ib-lf / ib-rf faces, ib-edge outline,
   ib-inset rim, ib-ic icon; is-lit and is-ghost states. */
.kg-iso text { font-family: var(--font-sans); }
.kg-iso .ib-top { fill: var(--control); }
.kg-iso .ib-lf { fill: var(--panel); }
.kg-iso .ib-rf { fill: var(--panel); fill-opacity: 0.72; }
.kg-iso .ib-edge { fill: none; stroke: var(--iso-line); stroke-width: 1.2; stroke-linejoin: round; transition: stroke 0.25s ease; }
.kg-iso .ib-inset { fill: none; stroke: var(--iso-rim); stroke-width: 1; }
.kg-iso .ib-ic { fill: none; stroke: var(--iso-icon); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.kg-iso .ib-ic * { vector-effect: non-scaling-stroke; }
.kg-iso .is-lit .ib-top, .kg-iso .is-lit .ib-lf { fill: var(--lit); }
.kg-iso .is-lit .ib-rf { fill: var(--lit); fill-opacity: 0.8; }
.kg-iso .is-lit .ib-edge { stroke: var(--orange); }
.kg-iso .is-lit .ib-inset { stroke: var(--iso-rim-lit); }
.kg-iso .is-lit .ib-ic { stroke: var(--orange-text); }
.kg-iso .is-ghost .ib-top, .kg-iso .is-ghost .ib-lf, .kg-iso .is-ghost .ib-rf { fill: none; }
.kg-iso .is-ghost .ib-edge { stroke: rgba(243, 243, 243, 0.24); stroke-dasharray: 4 3; }
.kg-iso .is-ghost .ib-ic { stroke: rgba(243, 243, 243, 0.3); }
.kg-iso .ix-floor { fill: rgba(243, 243, 243, 0.03); }
.kg-iso .ix-perim { fill: none; stroke: rgba(243, 243, 243, 0.3); stroke-width: 1.3; stroke-dasharray: 7 6; transition: stroke 0.25s ease; }
.kg-iso .ix-wire { fill: none; stroke: rgba(243, 243, 243, 0.32); stroke-width: 1.3; stroke-dasharray: 5 5; transition: stroke 0.25s ease; }
.kg-iso .ix-wire.is-out { stroke: rgba(243, 243, 243, 0.16); }
.kg-iso .ix-cut path { fill: none; stroke: rgba(243, 243, 243, 0.55); stroke-width: 1.8; stroke-linecap: round; }
.kg-iso .ix-lab { font-size: 12.5px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: var(--canvas); stroke-width: 6px; stroke-linejoin: round; }
.kg-iso .ix-lab.is-dim { fill: rgba(243, 243, 243, 0.42); }
.kg-iso .ix-m, .kg-iso .ix-sub { font-family: var(--font-mono); font-size: 8.5px; letter-spacing: 0.12em; fill: rgba(243, 243, 243, 0.5); paint-order: stroke; stroke: var(--canvas); stroke-width: 5px; }
.kg-iso .ix-m.ca-acc { fill: var(--orange-text); }
.kg-iso .ix-b { transition: transform var(--dur-rise) var(--ease-rise); transition-delay: calc(var(--i, 0) * 60ms); }
.kg-iso .ix-plate { transition: transform 0.5s var(--ease-rise); }
/* Alive: add .is-alive to the svg (or its card) on hover or on a beat. */
.is-alive .kg-iso .ix-b, .kg-iso.is-alive .ix-b { transform: translateY(-7px); }
.is-alive .kg-iso .ix-plate, .kg-iso.is-alive .ix-plate { transform: translateY(calc(var(--k, 0) * -9px - 4px)); }
.is-alive .kg-iso .ix-wire:not(.is-out), .kg-iso.is-alive .ix-wire:not(.is-out) { stroke: var(--orange); animation: kg-march 0.85s linear infinite; }
.is-alive .kg-iso .ix-perim, .kg-iso.is-alive .ix-perim { stroke: rgba(208, 81, 33, 0.7); animation: kg-march 1.2s linear infinite; }
.is-alive .kg-iso .ix-cut path, .kg-iso.is-alive .ix-cut path { stroke: var(--orange); }
.is-alive .kg-iso .ib-edge, .kg-iso.is-alive .ib-edge { stroke: rgba(243, 243, 243, 0.75); }
.is-alive .kg-iso .is-lit .ib-edge, .kg-iso.is-alive .is-lit .ib-edge { stroke: var(--orange); }

/* Dot streams: round-cap dots stepping forward. */
.kg-strm { fill: none; stroke: rgba(243, 243, 243, 0.46); stroke-width: 3.2; stroke-linecap: round; stroke-dasharray: 0 10; animation: kg-flow10 var(--dur-stream) linear infinite; }
.kg-strm.is-thin { stroke: rgba(243, 243, 243, 0.3); stroke-dasharray: 0 26; animation-name: kg-flow26; animation-duration: var(--dur-stream-thin); }
.kg-strm.is-hot { stroke: var(--orange); stroke-dasharray: 0 7; animation-name: kg-flow7; animation-duration: var(--dur-stream-hot); }
.kg-strm.is-back { animation-direction: reverse; }
@keyframes kg-flow10 { to { stroke-dashoffset: -10; } }
@keyframes kg-flow26 { to { stroke-dashoffset: -26; } }
@keyframes kg-flow7 { to { stroke-dashoffset: -7; } }

/* The motion vocabulary. */
@keyframes kg-march { to { stroke-dashoffset: -20; } }
@keyframes kg-pop { 0% { transform: scale(1); } 45% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes kg-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-3px); } 40% { transform: translateX(3px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes kg-nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(3px); } }
@keyframes kg-bob { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-3px); } }
@keyframes kg-spin { to { transform: rotate(360deg); } }
@keyframes kg-rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.kg-pop { animation: kg-pop var(--dur-pop) var(--ease-pop) 0.1s both; transform-box: fill-box; transform-origin: center; }
.kg-shake { animation: kg-shake var(--dur-shake) ease-in-out 0.1s both; }
.kg-nudge { animation: kg-nudge var(--dur-nudge) ease-in-out infinite; }
.kg-bob { animation: kg-bob var(--dur-bob) ease-in-out infinite; }
.kg-spin { animation: kg-spin var(--dur-spin) linear infinite; transform-box: fill-box; transform-origin: center; }
.kg-rise-in { animation: kg-rise-in var(--dur-rise) var(--ease-rise) both; }

@media (prefers-reduced-motion: reduce) {
  .kg-iso .ix-b, .kg-iso .ix-plate { transition: none; }
  .kg-strm, .kg-iso .ix-wire, .kg-iso .ix-perim, .kg-pop, .kg-shake, .kg-nudge, .kg-bob, .kg-spin, .kg-rise-in { animation: none; }
}
