/* Shared command-strip reveal. The text streams in behind a solid block cursor,
   then the cursor remains at the completed command. */

@keyframes commandStreamReveal {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

@keyframes commandStreamCursor {
  from { transform: translate3d(0, -50%, 0); }
  to { transform: translate3d(calc(var(--stream-chars) * 1ch + .14ch), -50%, 0); }
}

@keyframes commandStreamBlink {
  0%, 48% { opacity: 1; }
  49%, 100% { opacity: 0; }
}

@keyframes recordQueryReveal {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

@keyframes recordQueryCursorReady {
  from { visibility: hidden; }
  to { visibility: visible; }
}

.command-line {
  display: flex;
  align-items: baseline;
  min-width: 0;
}

.command-signature {
  position: relative;
  display: inline-block;
  width: min(100%, 390px);
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1px solid rgba(28, 26, 23, .28);
  border-top: 2px solid #7a2a1f;
  background: rgba(28, 26, 23, .025);
}

.command-signature::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -1px;
  width: 54px;
  height: 2px;
  background: #1c1a17;
}

.command-prompt {
  flex: 0 0 auto;
}

.command-stream {
  --stream-chars: 20;
  --stream-duration: 1.2s;
  --stream-delay: .45s;
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: calc(var(--stream-chars) * 1ch + 1.1ch);
  max-width: 100%;
  white-space: nowrap;
  color: #7a2a1f;
  vertical-align: baseline;
  contain: paint;
}

.command-copy {
  display: inline-block;
  clip-path: inset(0 100% 0 0);
  animation: commandStreamReveal var(--stream-duration)
    steps(var(--stream-chars), end) var(--stream-delay) both;
}

.command-verb { color: #686159; }
.command-root,
.command-domain-number { color: #7a2a1f; }
.command-domain-name {
  color: #1c1a17;
  font-weight: 500;
}

.command-cursor {
  position: absolute;
  left: 0;
  top: 50%;
  width: .72ch;
  height: 1.12em;
  background: #7a2a1f;
  transform: translate3d(0, -50%, 0);
  will-change: transform;
  animation:
    commandStreamCursor var(--stream-duration)
      steps(var(--stream-chars), end) var(--stream-delay) both,
    commandStreamBlink 1.05s step-end
      calc(var(--stream-delay) + var(--stream-duration)) infinite;
}

.record-query {
  position: relative;
  width: min(100%, 980px);
  box-sizing: border-box;
  margin: 0 auto clamp(28px, 4vh, 42px);
  padding: 14px 16px 15px;
  border: 1px solid rgba(28, 26, 23, .28);
  border-top: 2px solid #7a2a1f;
  background: rgba(28, 26, 23, .025);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.55;
  color: #1c1a17;
}

.record-query::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -1px;
  width: 72px;
  height: 2px;
  background: #1c1a17;
}

.record-query-line {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  min-width: 0;
}

.record-query-line-grep {
  padding-top: 10px;
  border-top: 1px solid rgba(28, 26, 23, .14);
}

.record-query-prompt {
  color: #98928a;
  white-space: nowrap;
}

.record-query-command {
  min-width: 0;
  overflow-wrap: anywhere;
}

.record-query-flag {
  color: #686159;
}

.record-query-pattern {
  color: #7a2a1f;
}

.record-query-output {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 20px;
  min-width: 0;
  margin: 5px 0 10px 92px;
}

.record-query-output a {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  min-width: 0;
  color: #1c1a17;
  text-decoration: none;
}

.record-query-output a::before {
  content: "↳";
  margin-right: 7px;
  color: #98928a;
}

.record-query-output a:hover,
.record-query-output a:focus-visible {
  color: #7a2a1f;
}

.record-query-output a:focus-visible {
  outline: 1px solid #7a2a1f;
  outline-offset: 3px;
}

.record-query-matches {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  margin-top: 6px;
  margin-bottom: 0;
}

.record-query-matches a {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 12px 6px 0;
  border-top: 1px solid rgba(28, 26, 23, .14);
}

.record-query-matches a::before {
  content: none;
}

.record-query-matches a + a {
  padding-left: 12px;
  border-left: 1px solid rgba(28, 26, 23, .14);
}

.record-query-matches span {
  color: #7a2a1f;
}

.record-query-matches small {
  font-family: 'Archivo', sans-serif;
  font-size: 9px;
  line-height: 1.35;
  letter-spacing: .04em;
  color: #686159;
}

.record-query-cursor {
  display: inline-block;
  width: .72ch;
  height: 1.12em;
  margin-left: .35ch;
  background: #7a2a1f;
  vertical-align: -.18em;
}

.record-query.is-revealed .record-query-line-ls,
.record-query.is-revealed .record-query-domains,
.record-query.is-revealed .record-query-line-grep,
.record-query.is-revealed .record-query-matches {
  animation: recordQueryReveal .72s steps(18, end) both;
}

.record-query.is-revealed .record-query-line-ls {
  animation-delay: .14s;
}

.record-query.is-revealed .record-query-domains {
  animation-delay: .68s;
}

.record-query.is-revealed .record-query-line-grep {
  animation-delay: 1.04s;
}

.record-query.is-revealed .record-query-matches {
  animation-delay: 1.78s;
}

.record-query.is-revealed .record-query-cursor {
  visibility: hidden;
  animation:
    recordQueryCursorReady .01s linear .9s both,
    commandStreamBlink 1.05s step-end .91s infinite;
}

@media (max-width: 560px) {
  .command-signature {
    padding: 11px 12px;
  }

  .record-query {
    margin-bottom: 30px;
    padding: 12px;
    font-size: 11px;
  }

  .record-query-line {
    grid-template-columns: 1fr;
    gap: 1px;
  }

  .record-query-output {
    margin-left: 0;
  }

  .record-query-domains {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
    margin-top: 7px;
  }

  .record-query-domains a {
    min-height: 36px;
  }

  .record-query-matches {
    grid-template-columns: 1fr 1fr;
  }

  .record-query-matches a,
  .record-query-matches a + a {
    min-height: 44px;
    box-sizing: border-box;
    padding: 7px 8px 6px 0;
    border-left: 0;
  }

  .record-query-matches a:nth-child(even) {
    padding-left: 10px;
    border-left: 1px solid rgba(28, 26, 23, .14);
  }
}

@media (prefers-reduced-motion: reduce) {
  .command-copy {
    clip-path: none !important;
    animation: none !important;
  }

  .chapter-hero [data-anim] .command-cursor,
  .command-cursor {
    opacity: 1 !important;
    animation: none !important;
    transform: translate3d(calc(var(--stream-chars) * 1ch + .14ch), -50%, 0) !important;
  }

  .record-query-line,
  .record-query-output,
  .record-query-cursor {
    clip-path: none !important;
    animation: none !important;
  }

  .record-query-cursor {
    visibility: visible !important;
  }
}
