/* 404 Multi-Stage Animated Terminal Stylesheet */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.page-404 {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-404 :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.term-shell {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  width: 100%;
  padding: clamp(6px, 1.2vw, 14px);
}

.term-window {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
  background-color: rgba(11, 13, 13, 0.96);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel);
  box-shadow: var(--glass-highlight), 0 24px 64px rgba(0, 0, 0, 0.55);
}

.term-window::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
  opacity: calc(var(--card-grain-opacity) * 0.65);
  background-image: var(--grain-tex);
  background-size: 128px 128px;
}

.term-window::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
  opacity: 0;
  background: radial-gradient(75% 58% at 50% 40%, rgba(244, 63, 94, 0.14) 0%, rgba(244, 63, 94, 0.04) 48%, transparent 78%);
}

@media (prefers-reduced-motion: no-preference) {
  .term-window::after {
    transition: opacity 550ms var(--ease-out-expo);
  }
}

.term-window.is-error-state::after,
.term-window.is-settled::after {
  opacity: 1;
}

.term-window > * {
  position: relative;
  z-index: 2;
}

/* Titlebar */
.term-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-100);
  padding: var(--sp-100) var(--sp-200);
  border-bottom: 1px solid var(--border);
  background-color: rgba(20, 22, 22, 0.92);
  min-width: 0;
}

.term-bar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-100);
  min-width: 0;
}

.term-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.term-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.term-dot--red {
  background-color: rgba(244, 63, 94, 0.72);
}

.term-dot--amber {
  background-color: rgba(245, 158, 11, 0.55);
}

.term-dot--green {
  background-color: rgba(52, 211, 153, 0.65);
}

.term-title {
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.term-title-host {
  color: var(--ink-muted);
}

.term-bar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-100);
  flex-shrink: 0;
}

.term-stage-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-75);
  padding: 4px 10px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--border);
  background-color: rgba(14, 16, 16, 0.85);
  color: var(--ink-secondary);
  white-space: nowrap;
}

.term-stage-pill.is-compiling {
  border-color: rgba(52, 211, 153, 0.32);
  background-color: var(--accent-tint);
  color: var(--accent-hover);
}

.term-stage-pill.is-error {
  border-color: rgba(244, 63, 94, 0.36);
  background-color: var(--accent-alt-tint);
  color: #fda4af;
}

.term-skip-btn {
  min-height: 36px;
}

/* Terminal body & 3-zone grid: 404 stage / elevated help card / bottom clutter pile */
.term-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(180px, 1fr) auto clamp(76px, 11vh, 104px);
  overflow: hidden;
}

.term-canvas {
  grid-row: 1 / -1;
  grid-column: 1;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 1;
}

.term-noscript {
  grid-row: 1;
  grid-column: 1;
  display: grid;
  place-items: center;
  padding: var(--sp-400);
  text-align: center;
  z-index: 2;
}

.term-noscript-404 {
  font-family: var(--font-mono);
  font-size: clamp(4rem, 18vw, 9.5rem);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-alt);
  text-shadow: 0 0 36px rgba(244, 63, 94, 0.35);
}

.term-noscript-note {
  margin-top: var(--sp-100);
  color: var(--ink-secondary);
  text-wrap: pretty;
}

/* Settled elevated recovery prompt card */
.term-recovery {
  grid-row: 2;
  grid-column: 1;
  position: relative;
  z-index: 2;
  width: min(calc(100% - var(--sp-400)), 760px);
  justify-self: center;
  align-self: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  background: linear-gradient(180deg, rgba(16, 18, 18, 0.94) 0%, rgba(20, 22, 22, 0.97) 100%);
  box-shadow: var(--glass-highlight), 0 16px 40px rgba(0, 0, 0, 0.48);
  padding: var(--sp-200) var(--sp-300);
}

.term-window.is-js-animated:not(.is-recovery-visible):not(.is-settled) .term-recovery {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .term-window.is-js-animated .term-recovery {
    transition:
      opacity 420ms var(--ease-out-expo),
      transform 420ms var(--ease-out-expo),
      visibility 0ms linear;
  }

  .term-window.is-js-animated:not(.is-recovery-visible):not(.is-settled) .term-recovery {
    transform: translateY(12px);
    transition:
      opacity 220ms var(--ease-out-expo),
      transform 220ms var(--ease-out-expo),
      visibility 0ms linear 220ms;
  }

  .term-window.is-js-animated.is-recovery-visible .term-recovery,
  .term-window.is-js-animated.is-settled .term-recovery {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

.term-recovery-inner {
  max-width: 760px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.term-help-cmd {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-75);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--ink);
  cursor: var(--cursor-text);
}

.term-sigil {
  color: var(--accent);
  font-weight: 700;
  user-select: none;
}

.term-cursor {
  display: inline-block;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(52, 211, 153, 0.45);
  user-select: none;
}

@media (prefers-reduced-motion: no-preference) {
  .term-cursor {
    animation: term-cursor-blink 1.04s steps(1, end) infinite;
  }
}

@keyframes term-cursor-blink {
  0%,
  55% {
    opacity: 1;
  }

  55.01%,
  100% {
    opacity: 0;
  }
}

.term-help-output {
  border-left: 2px solid var(--border-strong);
  padding-left: var(--sp-200);
  display: flex;
  flex-direction: column;
  gap: var(--sp-50);
  color: var(--ink-secondary);
}

.term-help-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-100);
}

.term-help-key {
  min-width: 64px;
  color: var(--ink-muted);
}

.term-help-val {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-100);
  min-width: 0;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.term-url-link {
  color: var(--accent-hover);
  font-weight: 500;
  text-decoration-color: rgba(52, 211, 153, 0.45);
}

.term-ready-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px;
  border-radius: var(--radius-inner);
  background-color: var(--accent-tint);
  color: var(--accent);
  font-size: 0.75rem;
  line-height: 1.3;
  font-weight: 500;
}

.term-recovery-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-200);
  padding-top: var(--sp-50);
}

.term-exit-meta {
  color: var(--ink-muted);
  text-wrap: pretty;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .term-title-host {
    display: none;
  }

  .term-skip-btn {
    min-height: 44px;
  }

  .term-recovery {
    width: min(calc(100% - var(--sp-300)), 760px);
    padding: var(--sp-200);
  }
}

@media (max-width: 480px) {
  .term-shell {
    padding: 0;
  }

  .term-window {
    border-radius: 0;
    border-inline: 0;
    border-block: 0;
  }

  .term-bar {
    padding: var(--sp-75) var(--sp-200);
  }

  .term-body {
    grid-template-rows: minmax(160px, 1fr) auto clamp(64px, 9.5vh, 84px);
  }

  .term-recovery {
    width: calc(100% - var(--sp-200));
    padding: var(--sp-200);
  }

  .term-recovery-inner {
    gap: var(--sp-100);
  }

  .term-recovery-actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-100);
  }

  .term-recovery-actions .btn-primary {
    width: 100%;
  }
}

@media (max-height: 540px) {
  .page-404 {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
  }

  .term-body {
    grid-template-rows: minmax(140px, 1fr) auto 60px;
  }

  .term-recovery {
    padding: var(--sp-200);
  }
}

@media (forced-colors: active) {
  .page-404 :focus-visible {
    outline: 2px solid CanvasText;
    outline-offset: 2px;
  }

  .term-window,
  .term-stage-pill,
  .term-ready-tag {
    border: 1px solid CanvasText;
  }
}
