/* =============================================
   TERMINAL-OVERLAY.CSS — macOS-inspired terminal
   ============================================= */

body.terminal-overlay-open {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}

.terminal-overlay[hidden] {
  display: none;
}

.terminal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(clamp(18px, 3vw, 38px), env(safe-area-inset-top, 0px))
    max(clamp(18px, 3vw, 38px), env(safe-area-inset-right, 0px))
    max(clamp(18px, 3vw, 38px), env(safe-area-inset-bottom, 0px))
    max(clamp(18px, 3vw, 38px), env(safe-area-inset-left, 0px));
  color: #f2f2f2;
  background:
    radial-gradient(circle at 15% 5%, rgba(249, 115, 22, 0.08), transparent 30%),
    #050505;
  font-family: "SFMono-Regular", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  opacity: 0.22;
  transform: translate3d(var(--terminal-origin-x, 50vw), var(--terminal-origin-y, 50vh), 0)
    scale(var(--terminal-origin-scale-x, 0.08), var(--terminal-origin-scale-y, 0.05));
  transform-origin: top left;
  border-radius: var(--terminal-origin-radius, 10px);
  overflow: hidden;
  will-change: transform, opacity, border-radius;
  transition:
    transform 460ms cubic-bezier(0.22, 0.78, 0.18, 1),
    opacity 360ms ease-out,
    border-radius 420ms ease-out;
}

.terminal-overlay.is-open {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1, 1);
  border-radius: 0;
}

.terminal-overlay.is-closing {
  pointer-events: none;
}

.terminal-overlay-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: calc(100dvh - clamp(36px, 6vw, 76px));
  overflow: hidden;
  background: #0b0b0b;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  box-shadow:
    0 32px 100px rgba(0, 0, 0, 0.72),
    0 8px 26px rgba(0, 0, 0, 0.52);
  opacity: 0;
  transform: scale(0.985);
  will-change: transform, opacity;
  transition:
    opacity 220ms ease-out,
    transform 400ms cubic-bezier(0.22, 0.78, 0.18, 1);
}

.terminal-overlay.is-open .terminal-overlay-shell {
  opacity: 1;
  transform: scale(1);
  transition-delay: 100ms, 40ms;
}

.terminal-overlay.is-closing .terminal-overlay-shell {
  transition-delay: 0ms;
}

.terminal-overlay-header {
  display: grid;
  grid-template-columns: minmax(84px, 1fr) auto minmax(84px, 1fr);
  align-items: center;
  min-height: 46px;
  padding: 0 14px;
  background: linear-gradient(180deg, #3a3a3a 0%, #2a2a2a 100%);
  border-bottom: 1px solid #171717;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  user-select: none;
}

.terminal-window-controls {
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 8px;
}

.terminal-window-control {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.34),
    0 0 0 0.5px rgba(0, 0, 0, 0.12);
}

.terminal-window-close {
  width: 28px;
  height: 28px;
  margin: -7.5px;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}

.terminal-window-close::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ff5f57;
  box-shadow:
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.34),
    0 0 0 0.5px rgba(0, 0, 0, 0.12);
  transform: translate(-50%, -50%);
}

.terminal-window-minimize {
  background: #febc2e;
}

.terminal-window-expand {
  background: #28c840;
}

.terminal-window-close::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(91, 0, 0, 0.72);
  font-family: Arial, sans-serif;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  opacity: 0;
  transition: opacity 120ms ease;
}

.terminal-window-controls:hover .terminal-window-close::after,
.terminal-window-close:focus-visible::after {
  opacity: 1;
}

.terminal-window-close:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 4px;
}

.terminal-overlay-identity {
  justify-self: center;
  min-width: 0;
  color: #dedede;
  font-size: clamp(0.7rem, 1.1vw, 0.78rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.72);
}

.terminal-overlay-header-spacer {
  min-width: 84px;
}

.terminal-overlay-body {
  flex: 1;
  padding: clamp(24px, 4vw, 48px) clamp(22px, 5vw, 68px);
  overflow: auto;
  background: #0b0b0b;
  font-size: clamp(0.82rem, 1.45vw, 0.98rem);
  line-height: 1.62;
}

.terminal-sequence-stage {
  width: 100%;
  min-width: 0;
}

.terminal-session-intro {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 7px;
  font-size: 0.92em;
  line-height: 1.55;
}

.terminal-session-login {
  color: #8f8f8f;
}

.terminal-session-prompt {
  color: #f3f3f3;
}

.terminal-session-prompt strong {
  color: #67d17a;
  font-weight: 600;
}

.terminal-sequence-editor {
  width: 100%;
  min-height: clamp(280px, 52vh, 540px);
  padding: 0;
  overflow: visible;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: inherit;
  line-height: 1.68;
}

.terminal-sequence-line {
  display: block;
  min-width: 0;
}

.terminal-sequence-code {
  min-width: 0;
  color: #f2f2f2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.terminal-token-keyword { color: #ff7b72; }
.terminal-token-property { color: #79c0ff; }
.terminal-token-string { color: #f2cc60; }
.terminal-token-number { color: #d2a8ff; }
.terminal-token-comment { color: #7d8590; }
.terminal-token-plain { color: #f2f2f2; }

.terminal-sequence-cursor {
  display: inline-block;
  width: 0.58em;
  height: 1.08em;
  margin-left: 2px;
  vertical-align: -0.16em;
  background: rgba(244, 244, 244, 0.92);
  animation: terminal-sequence-cursor-blink 760ms steps(1, end) infinite;
}

.terminal-overlay.sequence-typing .terminal-sequence-cursor {
  animation: none;
  opacity: 1;
}

.terminal-overlay.sequence-complete .terminal-sequence-cursor {
  animation-duration: 1.05s;
}

@keyframes terminal-sequence-cursor-blink {
  0%, 52% { opacity: 1; }
  53%, 100% { opacity: 0; }
}

@media (max-width: 640px) {
  .terminal-overlay {
    padding:
      env(safe-area-inset-top, 0px)
      env(safe-area-inset-right, 0px)
      env(safe-area-inset-bottom, 0px)
      env(safe-area-inset-left, 0px);
  }

  .terminal-overlay-shell {
    min-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    min-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    border-width: 0;
    border-radius: 0;
  }

  .terminal-overlay-header {
    grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
    min-height: 50px;
    padding-inline: 14px;
  }

  .terminal-window-control {
    width: 14px;
    height: 14px;
  }

  .terminal-window-close {
    width: 44px;
    height: 44px;
    margin: -15px;
  }

  .terminal-window-close::before {
    width: 14px;
    height: 14px;
  }

  .terminal-overlay-identity {
    max-width: 44vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .terminal-overlay-header-spacer {
    min-width: 72px;
  }

  .terminal-overlay-body {
    padding: 24px 16px;
  }

  .terminal-sequence-editor {
    min-height: calc(100dvh - 128px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .terminal-overlay,
  .terminal-overlay-shell,
  .terminal-window-close::after {
    transition: none;
  }

  .terminal-sequence-cursor {
    animation: none;
  }
}
