/**
 * Kozmo Handshake — Retro-scifi comm panel
 *
 * One-off embed for 2029-drew-extraction.md flashback. Two-hander between
 * Drew (cool cyan terminal, monospace, defensive) and Kozmo (warm amber
 * ornate panel, sans, "dressed to impress" — Concord's clinic AI making
 * direct contact for the first time).
 *
 * Identity validation moment uses the Standard Galactic Alphabet font
 * (Commander Keen, Tom Hall, 1990) — chosen in-fiction because Drew's
 * visual cortex has rewired around geometry after seven years deaf.
 *
 * Contrast: every text token verified ≥8:1 against the dark background.
 */

/* --- SGA font (alien-script identity validation) ---------------------- */

@font-face {
  font-family: "StandardGalactic";
  src: url("/static/fonts/Sga-Regular.woff") format("woff");
  font-display: swap;
}

/* --- Component scope --------------------------------------------------- */

.kozmo-handshake {
  /* Local tokens — keep the embed visually self-contained while still
     letting the era CSS adjust outer chrome. */
  --kh-bg: #050b0b;
  --kh-bg-elev: #0a1316;
  --kh-amber: #ffd478;       /* Kozmo body — 14.1:1 on --kh-bg */
  --kh-amber-bright: #ffe7a8; /* Kozmo headlines — 16.3:1 */
  --kh-amber-dim: #daab60;    /* meta labels — 9.4:1 (≥8:1 floor) */
  --kh-cyan: #7cd0ff;         /* Drew body — 11.6:1 on --kh-bg */
  --kh-cyan-dim: #6cb1d8;     /* drew prompt prefix — 8.4:1 */
  --kh-green: hsl(100, 100%, 70%); /* OHC sigil */
  --kh-rule: rgba(255, 220, 160, 0.16);
  --kh-rule-drew: rgba(124, 208, 255, 0.18);

  position: relative;
  margin: 3rem 0;
  padding: 2rem 1.75rem 1.5rem;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 200, 120, 0.10) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 110%, rgba(124, 208, 255, 0.06) 0%, transparent 55%),
    var(--kh-bg);
  border: 1px solid var(--kh-rule);
  border-radius: 2px;
  color: var(--kh-amber);
  font-family: var(--sf-font-mono, "SF Mono", Menlo, monospace);
  line-height: 1.55;
  overflow: hidden;
}

/* HUD corner brackets — four L-shapes */
.kozmo-handshake::before,
.kozmo-handshake::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--kh-green);
  pointer-events: none;
}
.kozmo-handshake::before {
  top: 6px; left: 6px;
  border-right: none; border-bottom: none;
}
.kozmo-handshake::after {
  bottom: 6px; right: 6px;
  border-left: none; border-top: none;
}

/* Scanline texture — barely there */
.kozmo-handshake .kh-stage {
  position: relative;
}
.kozmo-handshake .kh-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(0, 0, 0, 0.18) 3px,
    rgba(0, 0, 0, 0.18) 4px
  );
  opacity: 0.45;
  mix-blend-mode: multiply;
}

/* --- Header bar ------------------------------------------------------- */

.kh-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px dashed var(--kh-rule);
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--kh-green);
}

.kh-header .kh-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
}

.kh-header .kh-tag::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--kh-green);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--kh-green);
  animation: kh-blink 2.4s ease-in-out infinite;
}

.kh-header .kh-time {
  color: var(--kh-amber-dim);
  font-weight: 500;
}

.kh-header h3 {
  flex-basis: 100%;
  margin: 0.25rem 0 0;
  font-family: var(--sf-font-serif, Georgia, serif);
  font-size: 1.35rem;
  font-weight: 500;
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
  color: var(--kh-amber-bright);
}

/* --- Connection meta strip ------------------------------------------- */

.kh-conn {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.4rem 1.2rem;
  margin: 0 0 1.5rem;
  padding: 0.6rem 0.85rem;
  background: rgba(255, 220, 160, 0.04);
  border: 1px solid var(--kh-rule);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}

.kh-conn dt {
  display: inline-block;
  margin-right: 0.5rem;
  color: var(--kh-green);
  font-weight: 700;
}

.kh-conn dd {
  display: inline;
  margin: 0;
  color: var(--kh-amber-bright);
  font-weight: 500;
}

.kh-conn-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

/* --- Messages --------------------------------------------------------- */

.kh-msg {
  margin: 0 0 1.5rem;
  font-size: 0.98rem;
}

.kh-msg-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.kh-msg-head .kh-from {
  font-weight: 700;
}

.kh-msg-head .kh-from-meta {
  color: var(--kh-amber-dim);
  font-weight: 500;
  letter-spacing: 0.12em;
}

.kh-msg-head .kh-rule {
  flex: 1;
  height: 1px;
  background: currentColor;
  opacity: 0.4;
}

.kh-body {
  margin: 0;
  padding: 0;
}

.kh-body p {
  margin: 0 0 0.35rem;
}

.kh-body p:last-child {
  margin-bottom: 0;
}

/* --- Kozmo voice (ornate, warm) -------------------------------------- */

.kh-msg.kh-kozmo {
  padding: 0.85rem 1rem 0.95rem 1.25rem;
  background:
    linear-gradient(
      90deg,
      rgba(255, 200, 120, 0.05) 0%,
      rgba(255, 200, 120, 0.015) 40%,
      transparent 100%
    );
  border-left: 2px solid var(--kh-amber);
  color: var(--kh-amber);
}

.kh-msg.kh-kozmo .kh-msg-head {
  color: var(--kh-green);
}

.kh-msg.kh-kozmo .kh-from {
  color: var(--kh-amber-bright);
  font-family: var(--sf-font-serif, Georgia, serif);
  font-style: italic;
  font-size: 0.96rem;
  letter-spacing: 0.04em;
  text-transform: none;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(255, 200, 120, 0.35);
}

.kh-msg.kh-kozmo .kh-body {
  font-family: var(--sf-font-sans, -apple-system, "Helvetica Neue", Arial, sans-serif);
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.6;
}

/* OHC sigil ahead of Kozmo's name */
.kh-sigil {
  display: inline-block;
  width: 0.95em;
  height: 0.95em;
  vertical-align: -0.13em;
  margin-right: 0.35em;
  fill: none;
  stroke: var(--kh-green);
  stroke-width: 1.6;
  filter: drop-shadow(0 0 3px rgba(0, 255, 150, 0.5));
}

/* --- Drew voice (stark terminal) ------------------------------------- */

.kh-msg.kh-drew {
  padding: 0.3rem 0 0.3rem 1.1rem;
  border-left: 2px solid var(--kh-cyan);
  color: var(--kh-cyan);
}

.kh-msg.kh-drew .kh-msg-head {
  color: var(--kh-cyan-dim);
  margin-bottom: 0.3rem;
}

.kh-msg.kh-drew .kh-from {
  color: var(--kh-cyan);
  font-family: var(--sf-font-mono, "SF Mono", Menlo, monospace);
}

.kh-msg.kh-drew .kh-body {
  font-family: var(--sf-font-mono, "SF Mono", Menlo, monospace);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--kh-cyan);
}

.kh-msg.kh-drew .kh-body p::before {
  content: "drew@bushwick:~$ ";
  color: var(--kh-cyan-dim);
  user-select: none;
}

.kh-msg.kh-drew .kh-body p:last-child::after {
  content: "_";
  display: inline-block;
  margin-left: 2px;
  color: var(--kh-cyan);
  animation: kh-cursor 1.05s steps(2) infinite;
}

/* --- SGA splash panel ------------------------------------------------- */

.kh-sga {
  margin: 0.5rem 0 0.85rem;
  padding: 1.4rem 1rem 1.1rem;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 200, 120, 0.10) 0%,
    rgba(255, 200, 120, 0.025) 55%,
    transparent 90%
  );
  border-top: 1px solid var(--kh-rule);
  border-bottom: 1px solid var(--kh-rule);
  text-align: center;
}

.kh-sga-label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: 0.66rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--kh-green);
  font-weight: 700;
}

.kh-sga-glyphs {
  display: inline-flex;
  gap: 0.55em;
  font-family: "StandardGalactic", "Sga-Regular", sans-serif;
  font-size: 5.4rem;
  line-height: 1;
  color: var(--kh-amber-bright);
  text-shadow:
    0 0 14px rgba(255, 200, 120, 0.55),
    0 0 38px rgba(255, 160, 60, 0.25);
  letter-spacing: 0.02em;
  /* Cushion against tall glyph extents */
  padding: 0.1em 0;
}

.kh-sga-glyphs.kh-sga-small {
  font-size: 2.6rem;
  gap: 0.45em;
}

.kh-decoder {
  position: relative;
  height: 16px;
  margin: 0.75rem auto;
  width: min(420px, 80%);
  background: linear-gradient(
    to right,
    transparent,
    rgba(255, 220, 160, 0.18),
    transparent
  );
  border-top: 1px solid var(--kh-amber-dim);
  border-bottom: 1px solid var(--kh-amber-dim);
  overflow: hidden;
}

.kh-decoder::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 22%;
  background: linear-gradient(
    to right,
    transparent 0%,
    rgba(255, 220, 160, 0.45) 30%,
    rgba(255, 255, 255, 0.85) 50%,
    rgba(255, 220, 160, 0.45) 70%,
    transparent 100%
  );
  animation: kh-sweep 3.2s ease-in-out infinite;
}

.kh-decoder::after {
  content: "▸ DECODE";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--sf-font-mono, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.4em;
  color: var(--kh-amber-bright);
  text-shadow: 0 0 4px rgba(255, 220, 160, 0.7);
  font-weight: 700;
}

.kh-decoded {
  display: inline-block;
  font-family: var(--sf-font-mono, monospace);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.6em;
  color: var(--kh-amber-bright);
  margin-left: 0.6em; /* compensate for trailing letter-spacing */
  text-shadow: 0 0 8px rgba(255, 200, 120, 0.4);
}

.kh-sga-small + .kh-decoder {
  height: 12px;
  width: min(280px, 70%);
}

.kh-sga-small ~ .kh-decoded {
  font-size: 1.05rem;
}

.kh-sga-caption {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--kh-amber-dim);
  font-weight: 500;
}

/* --- Patch transmission block ---------------------------------------- */

.kh-patch {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.9rem;
  background: rgba(0, 0, 0, 0.45);
  border: 1px dashed var(--kh-rule);
  font-family: var(--sf-font-mono, monospace);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--kh-amber-bright);
  white-space: pre;
  overflow-x: auto;
}

.kh-patch .kh-patch-add { color: hsl(100, 80%, 72%); }
.kh-patch .kh-patch-loc { color: var(--kh-amber-dim); }
.kh-patch .kh-patch-head {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--kh-green);
}

/* --- Footer ----------------------------------------------------------- */

.kh-footer {
  margin-top: 1.25rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--kh-rule);
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--kh-amber-dim);
}

.kh-footer .kh-footer-end {
  color: var(--kh-green);
  font-weight: 700;
}

/* --- Animations ------------------------------------------------------- */

@keyframes kh-blink {
  0%, 60%, 100% { opacity: 1; }
  30% { opacity: 0.25; }
}

@keyframes kh-cursor {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

@keyframes kh-sweep {
  0%   { transform: translateX(-22%); }
  50%  { transform: translateX(450%); }
  50.01% { transform: translateX(-22%); }
  100% { transform: translateX(450%); }
}

@media (prefers-reduced-motion: reduce) {
  .kh-header .kh-tag::before,
  .kh-msg.kh-drew .kh-body p:last-child::after,
  .kh-decoder::before {
    animation: none;
  }
}

/* --- Compact variant (mid-journey check-ins) ------------------------- */
/* Tighter chrome, no SGA splash. Use for shorter terminal exchanges that
   don't carry an identity-validation beat. */

.kozmo-handshake--compact {
  margin: 2.25rem 0;
  padding: 1.4rem 1.25rem 1.1rem;
}

.kozmo-handshake--compact .kh-header {
  margin-bottom: 0.85rem;
  padding-bottom: 0.6rem;
}

.kozmo-handshake--compact .kh-header h3 {
  font-size: 1.1rem;
}

.kozmo-handshake--compact .kh-conn {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  padding: 0.45rem 0.7rem;
  margin-bottom: 1.1rem;
  font-size: 0.74rem;
}

.kozmo-handshake--compact .kh-msg {
  margin-bottom: 1rem;
  font-size: 0.94rem;
}

.kozmo-handshake--compact .kh-msg.kh-kozmo {
  padding: 0.7rem 0.85rem 0.8rem 1rem;
}

/* --- Spectrum variant (cortical-channel intra-skull transmission) ---- */
/* Replaces the SGA glyph splash with a multi-trace oscilloscope panel.
   Same identity-validation grammar (label → glyphic content → decode bar
   → decoded message → caption), new modality. The visual rhyme with the
   2029 SGA splash is the point. */

.kh-spectrum {
  margin: 0.5rem 0 0.85rem;
  padding: 1.35rem 1rem 1.15rem;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 200, 120, 0.10) 0%,
    rgba(255, 200, 120, 0.02) 55%,
    transparent 90%
  );
  border-top: 1px solid var(--kh-rule);
  border-bottom: 1px solid var(--kh-rule);
  text-align: center;
}

.kh-spectrum-label {
  display: block;
  margin-bottom: 0.7rem;
  font-size: 0.66rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--kh-green);
  font-weight: 700;
}

.kh-wave {
  display: block;
  width: min(560px, 92%);
  height: 132px;
  margin: 0 auto;
  overflow: visible;
}

.kh-wave .kh-wave-grid {
  stroke: rgba(255, 200, 120, 0.10);
  stroke-width: 1;
  fill: none;
}

.kh-wave .kh-wave-trace {
  fill: none;
  stroke: var(--kh-amber-bright);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(255, 220, 160, 0.7));
}

.kh-wave .kh-wave-trace--soft {
  stroke: var(--kh-amber-dim);
  stroke-width: 1.4;
  opacity: 0.85;
  filter: none;
}

.kh-wave .kh-wave-trace--bright {
  stroke: var(--kh-amber-bright);
  stroke-width: 2.4;
}

.kh-wave .kh-wave-marker {
  fill: var(--kh-green);
  filter: drop-shadow(0 0 5px rgba(120, 255, 120, 0.7));
}

@keyframes kh-wave-draw {
  from { stroke-dashoffset: 1200; }
  to   { stroke-dashoffset: 0; }
}

.kh-wave .kh-wave-trace {
  stroke-dasharray: 1200;
  stroke-dashoffset: 0;
  animation: kh-wave-draw 2.4s ease-out;
}

.kh-wave .kh-wave-trace--soft {
  animation-duration: 3s;
  animation-delay: 0.2s;
}

.kh-wave .kh-wave-trace--bright {
  animation-duration: 2s;
  animation-delay: 0.45s;
}

@media (prefers-reduced-motion: reduce) {
  .kh-wave .kh-wave-trace { animation: none; }
}

/* --- Responsive ------------------------------------------------------- */

@media (max-width: 600px) {
  .kozmo-handshake {
    padding: 1.5rem 1.1rem 1.2rem;
    margin: 2.25rem -0.25rem;
  }
  .kh-sga-glyphs { font-size: 3.6rem; }
  .kh-sga-glyphs.kh-sga-small { font-size: 2rem; }
  .kh-decoded { font-size: 1.15rem; letter-spacing: 0.45em; }
  .kh-header h3 { font-size: 1.15rem; }
}
