/* Shared status-lamp terminal. All selectors are deliberately namespaced. */
.system-status-cluster {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 3px;
}

.system-status-cluster > a {
  min-width: 0;
}

.system-status-cluster > a::before {
  display: none !important;
}

.system-power-button {
  position: relative;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  margin: -7px 0 -7px -7px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.system-power-button::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border: 1px solid rgb(255 255 255 / .72);
  border-radius: 50%;
  background: var(--lime, #c9ff00);
  box-shadow:
    0 0 4px var(--lime, #c9ff00),
    0 0 11px var(--lime, #c9ff00);
  transform: translate(-50%, -50%);
  transition: background-color 140ms linear, box-shadow 140ms linear, transform 140ms ease;
  content: "";
}

.system-power-button.is-alert::before,
.system-power-button.is-terminal-active::before {
  background: var(--signal-red, #ff3158);
  box-shadow:
    0 0 4px var(--signal-red, #ff3158),
    0 0 12px var(--signal-red, #ff3158);
}

.system-power-button:hover::before { transform: translate(-50%, -50%) scale(1.28); }
.system-power-button:active::before { transform: translate(-50%, -50%) scale(.76); }

.system-power-button:focus-visible {
  outline: 3px solid var(--lime, #c9ff00);
  outline-offset: 1px;
}

html.terminal-powering-down,
html.terminal-is-open,
html.terminal-powering-up,
html.terminal-restarting {
  overflow: hidden;
}

html.terminal-powering-down :is(.site-shell, .error-shell) {
  transform-origin: 50% var(--terminal-origin-y, 50vh);
  animation: terminal-site-power-down var(--terminal-shutdown-duration, 900ms) cubic-bezier(.62, 0, .85, .22) both;
}

html.terminal-is-open :is(.site-shell, .error-shell),
html.terminal-restarting :is(.site-shell, .error-shell) {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

html.terminal-powering-up :is(.site-shell, .error-shell) {
  transform-origin: 50% var(--terminal-origin-y, 50vh);
  animation: terminal-site-power-up var(--terminal-boot-duration, 1050ms) cubic-bezier(.16, .72, .22, 1) both;
}

.system-terminal {
  position: fixed;
  top: var(--terminal-viewport-top, 0px);
  left: var(--terminal-viewport-left, 0px);
  z-index: 2147483200;
  display: grid;
  visibility: hidden;
  box-sizing: border-box;
  width: 100vw;
  width: var(--terminal-viewport-width, 100vw);
  height: 100vh;
  height: var(--terminal-viewport-height, 100dvh);
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  place-items: center;
  overflow: hidden;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  font-family: "Courier Prime", "Courier New", monospace;
  isolation: isolate;
}

.system-terminal.is-active,
.system-terminal.is-open,
.system-terminal.is-booting,
.system-terminal.is-restarting {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.system-terminal.is-shutting-down {
  animation: terminal-overlay-shut var(--terminal-shutdown-duration, 900ms) linear both;
}

.system-terminal.is-open,
.system-terminal.is-crashing,
.system-terminal.is-restarting {
  background: #020504;
}

.system-terminal.is-booting {
  animation: terminal-overlay-boot var(--terminal-boot-duration, 1050ms) linear both;
}

.system-terminal::before,
.system-terminal::after {
  position: absolute;
  z-index: 1;
  display: block;
  pointer-events: none;
  content: "";
}

.system-terminal::before {
  top: 50%;
  left: 50%;
  width: 0;
  height: 3px;
  border-radius: 50%;
  background: #effff1;
  box-shadow:
    0 0 8px #fff,
    0 0 24px #c9ff00,
    0 0 54px #52f7ff;
  opacity: 0;
  transform: translate(-50%, -50%);
}

.system-terminal::after {
  inset: 0;
  opacity: 0;
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / .035) 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at center, transparent 0 38%, rgb(0 0 0 / .92) 100%);
}

.system-terminal.is-shutting-down::before {
  animation: terminal-power-line-off var(--terminal-shutdown-duration, 900ms) linear both;
}

.system-terminal.is-booting::before {
  animation: terminal-power-line-on var(--terminal-boot-duration, 1050ms) linear both;
}

.system-terminal.is-shutting-down::after,
.system-terminal.is-booting::after {
  animation: terminal-static-flicker 90ms steps(2, end) infinite;
}

.system-terminal__window {
  position: relative;
  z-index: 2;
  display: none;
  width: min(900px, 94vw);
  height: min(700px, 78dvh);
  max-height: calc(100% - 24px);
  min-height: 390px;
  border: 2px solid #e7e7e7;
  border-right-color: #171717;
  border-bottom-color: #171717;
  background: #bdbdbd;
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -1px -1px 0 #5b5b5b,
    12px 14px 0 rgb(0 0 0 / .5),
    0 0 0 1px #000;
  color: #f4fff2;
  overflow: hidden;
}

.system-terminal.is-open .system-terminal__window,
.system-terminal.is-crashing .system-terminal__window,
.system-terminal.is-booting .system-terminal__window,
.system-terminal.is-restarting .system-terminal__window {
  display: flex;
  flex-direction: column;
}

.system-terminal.is-page-boot .system-terminal__window { display: none; }

.system-terminal.is-open .system-terminal__window {
  animation: terminal-window-open 310ms steps(5, end) both;
}

.system-terminal.is-booting .system-terminal__window {
  animation: terminal-window-close 240ms steps(4, end) both;
}

.system-terminal.is-restarting .system-terminal__window {
  animation: terminal-window-restart 760ms steps(7, end) both;
}

.system-terminal.is-crashing .system-terminal__window {
  animation: terminal-window-crash var(--terminal-crash-duration, 2700ms) steps(2, end) both;
}

.system-terminal__titlebar {
  display: flex;
  flex: 0 0 auto;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 3px 3px 0;
  padding: 3px 4px 3px 9px;
  background: linear-gradient(90deg, #001a73, #1438f0 70%, #0f83c9);
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .015em;
  line-height: 1.2;
  text-shadow: 1px 1px 0 #000;
}

.system-terminal__title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-terminal__close {
  display: grid;
  flex: 0 0 26px;
  width: 26px;
  height: 25px;
  border: 2px solid #f5f5f5;
  border-right-color: #272727;
  border-bottom-color: #272727;
  padding: 0;
  place-items: center;
  background: #c7c7c7;
  color: #111;
  cursor: pointer;
  font: 900 18px/1 Arial, Helvetica, sans-serif;
  text-shadow: none;
}

.system-terminal__close:hover { background: #efefef; }
.system-terminal__close:active {
  border-color: #292929 #f5f5f5 #f5f5f5 #292929;
  padding: 2px 0 0 2px;
}

.system-terminal__close:focus-visible {
  outline: 3px solid #c9ff00;
  outline-offset: 3px;
}

.system-terminal__screen {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  margin: 3px;
  border: 2px solid #242424;
  border-right-color: #f2f2f2;
  border-bottom-color: #f2f2f2;
  padding: clamp(13px, 2.4vw, 24px);
  flex-direction: column;
  background:
    linear-gradient(rgb(13 28 20 / .3), rgb(0 0 0 / .08)),
    #030705;
  box-shadow: inset 0 0 34px rgb(0 0 0 / .72);
  overflow: hidden;
}

.system-terminal__output {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-color: #75a979 #061309;
  scrollbar-width: thin;
}

.system-terminal__line {
  margin: 0 0 7px;
  color: #b9efbd;
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.38;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.system-terminal__line.is-command { color: #fff; }
.system-terminal__line.is-command::before { color: #c9ff00; content: attr(data-prompt) " "; }
.system-terminal__line.is-system { color: #52f7ff; }
.system-terminal__line.is-error { color: #ff718e; }
.system-terminal__line.is-root { color: #ffd35a; }

.system-terminal__form {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  margin-top: 4px;
  border-top: 1px solid rgb(185 239 189 / .22);
  padding-top: 10px;
  color: #c9ff00;
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.3;
}

.system-terminal__prompt { white-space: nowrap; }

.system-terminal__input {
  min-width: 0;
  width: 100%;
  border: 0;
  border-radius: 0;
  outline: 0;
  padding: 4px 0;
  background: transparent;
  color: #fff;
  caret-color: #c9ff00;
  font: inherit;
  line-height: inherit;
}

.system-terminal__input::selection { background: #c9ff00; color: #050805; }
.system-terminal__input:disabled { opacity: .35; }

.system-terminal__effects,
.system-terminal__sprite-canvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.system-terminal__sprite-canvas {
  image-rendering: pixelated;
  opacity: 1;
  transition: opacity var(--terminal-sprite-fade-duration, 1600ms) linear;
}

.system-terminal__sprite-canvas.is-fading { opacity: 0; }

.system-terminal__jon {
  position: absolute;
  width: clamp(54px, 10vw, 92px);
  aspect-ratio: 1;
  border: 3px solid #c9ff00;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 5px 5px 0 #101018, 0 0 18px #52f7ff;
  opacity: 0;
  animation: terminal-jon-bounce 5200ms cubic-bezier(.2, .82, .25, 1) var(--jon-delay, 0ms) both;
}

.system-terminal__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

html.cursor-ready .system-terminal,
html.cursor-ready .system-terminal * { cursor: auto; }
html.cursor-ready .system-terminal__close { cursor: pointer; }
html.cursor-ready .system-terminal__input { cursor: text; }

@keyframes terminal-site-power-down {
  0% { opacity: 1; filter: brightness(1) saturate(1); transform: scale(1); }
  35% { opacity: 1; filter: brightness(1.35) saturate(.55) contrast(1.2); transform: scale(1.006, .97); }
  63% { opacity: 1; filter: brightness(2.5) saturate(0) contrast(1.8); transform: scale(.985, .075); }
  82% { opacity: 1; filter: brightness(5) saturate(0); transform: scale(.58, .008); }
  100% { opacity: 0; filter: brightness(7) saturate(0); transform: scale(.03, .002); }
}

@keyframes terminal-site-power-up {
  0% { opacity: 0; filter: brightness(6) saturate(0); transform: scale(.03, .002); }
  23% { opacity: 1; filter: brightness(4) saturate(0); transform: scale(.58, .008); }
  50% { opacity: 1; filter: brightness(1.9) saturate(.45) contrast(1.45); transform: scale(.985, .075); }
  78% { opacity: 1; filter: brightness(1.16) saturate(.8); transform: scale(1.006, 1.025); }
  100% { opacity: 1; filter: brightness(1) saturate(1); transform: scale(1); }
}

@keyframes terminal-overlay-shut {
  0% { background: rgb(0 0 0 / 0); }
  50% { background: rgb(0 0 0 / .35); }
  82%, 100% { background: #020504; }
}

@keyframes terminal-overlay-boot {
  0%, 24% { background: #020504; }
  66% { background: rgb(0 0 0 / .46); }
  100% { background: rgb(0 0 0 / 0); }
}

@keyframes terminal-power-line-off {
  0%, 49% { width: 96vw; opacity: 0; }
  64% { width: 96vw; opacity: 1; }
  82% { width: 34vw; height: 3px; opacity: 1; }
  94% { width: 5px; height: 5px; opacity: 1; }
  100% { width: 0; height: 0; opacity: 0; }
}

@keyframes terminal-power-line-on {
  0% { width: 0; height: 0; opacity: 0; }
  10% { width: 5px; height: 5px; opacity: 1; }
  28% { width: 42vw; height: 3px; opacity: 1; }
  47% { width: 96vw; height: 4px; opacity: 1; }
  68% { width: 96vw; height: 22vh; opacity: .74; }
  90% { width: 100vw; height: 100vh; opacity: .12; }
  100% { width: 100vw; height: 100vh; opacity: 0; }
}

@keyframes terminal-static-flicker {
  0% { opacity: .08; transform: translateY(-1px); }
  50% { opacity: .22; transform: translateY(1px); }
  100% { opacity: .12; transform: translateY(0); }
}

@keyframes terminal-window-open {
  0% { opacity: 0; transform: scale(.18, .01); }
  45% { opacity: 1; transform: scale(1, .025); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes terminal-window-close {
  0% { opacity: 1; transform: scale(1); }
  55% { opacity: 1; transform: scale(1, .018); }
  100% { opacity: 0; transform: scale(.08, .004); }
}

@keyframes terminal-window-restart {
  0% { opacity: 1; filter: none; transform: translate(0) skew(0); }
  18% { opacity: 1; filter: contrast(2) hue-rotate(40deg); transform: translate(-8px, 2px) skew(2deg); }
  36% { opacity: .7; filter: invert(1); transform: translate(11px, -3px) skew(-4deg); }
  58% { opacity: 1; filter: brightness(3); transform: scale(1, .035); }
  100% { opacity: 0; filter: brightness(5); transform: scale(.08, .003); }
}

@keyframes terminal-window-crash {
  0% { opacity: 1; filter: none; transform: translate(0); }
  8% { filter: hue-rotate(90deg) contrast(2); transform: translate(-9px, 4px); }
  16% { filter: invert(1); transform: translate(12px, -5px) skewX(5deg); }
  28% { opacity: 1; filter: brightness(4); transform: scale(1, .03); }
  38%, 68% { opacity: 0; filter: brightness(5); transform: scale(.08, .003); }
  78% { opacity: 1; filter: brightness(3); transform: scale(1, .02); }
  100% { opacity: 1; filter: none; transform: scale(1); }
}

@keyframes terminal-jon-bounce {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.18) rotate(-18deg); }
  12% { opacity: 1; transform: translate(-50%, -62%) scale(1.16) rotate(6deg); }
  34% { opacity: 1; transform: translate(calc(-50% + var(--jon-dx, 0px)), calc(-50% + var(--jon-dy, 0px))) scale(.94) rotate(var(--jon-spin, 8deg)); }
  76% { opacity: 1; transform: translate(calc(-50% + var(--jon-dx2, 0px)), calc(-50% + var(--jon-dy2, 0px))) scale(1.04) rotate(var(--jon-spin-neg, -8deg)); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--jon-dx3, 0px)), calc(-50% + var(--jon-dy3, 0px))) scale(.45) rotate(var(--jon-spin, 8deg)); }
}

@keyframes terminal-jon-fade {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.94); }
  10%, 76% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.96); }
}

@media (max-width: 640px) {
  .system-power-button {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
    margin-block: -9px;
  }

  .system-terminal {
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
    align-items: stretch;
  }

  .system-terminal__window {
    width: 100%;
    height: min(100%, 100dvh);
    max-height: 100%;
    min-height: 0;
    margin: auto;
    box-shadow: 5px 6px 0 rgb(0 0 0 / .5), 0 0 0 1px #000;
  }

  .system-terminal__titlebar { min-height: 38px; font-size: 13px; }
  .system-terminal__close { width: 30px; height: 29px; flex-basis: 30px; }
  .system-terminal__screen { padding: 13px 11px max(13px, env(safe-area-inset-bottom)); }
  .system-terminal__line { font-size: 15px; }
  .system-terminal__form { font-size: 16px; }
}

.system-terminal.is-keyboard-open {
  padding:
    max(3px, env(safe-area-inset-top))
    max(3px, env(safe-area-inset-right))
    max(3px, env(safe-area-inset-bottom))
    max(3px, env(safe-area-inset-left));
  align-items: stretch;
}

.system-terminal.is-keyboard-open .system-terminal__window {
  width: 100%;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  margin: 0 auto;
  box-shadow: 2px 2px 0 rgb(0 0 0 / .5), 0 0 0 1px #000;
}

.system-terminal.is-keyboard-open .system-terminal__titlebar {
  min-height: 31px;
  margin: 2px 2px 0;
  padding-block: 2px;
}

.system-terminal.is-keyboard-open .system-terminal__close {
  flex-basis: 28px;
  width: 28px;
  height: 27px;
}

.system-terminal.is-keyboard-open .system-terminal__screen {
  margin: 2px;
  padding: 7px 8px max(7px, env(safe-area-inset-bottom));
}

.system-terminal.is-keyboard-open .system-terminal__line {
  margin-bottom: 5px;
  font-size: clamp(13px, 3.7vw, 15px);
  line-height: 1.28;
}

.system-terminal.is-keyboard-open .system-terminal__form {
  margin-top: 2px;
  padding-top: 6px;
  font-size: 16px;
}

@media (max-width: 390px) {
  .system-status-cluster > a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .system-terminal__prompt { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html.terminal-powering-down :is(.site-shell, .error-shell),
  html.terminal-powering-up :is(.site-shell, .error-shell) {
    animation-duration: 160ms;
    animation-timing-function: linear;
  }

  .system-terminal.is-shutting-down,
  .system-terminal.is-booting,
  .system-terminal.is-shutting-down::before,
  .system-terminal.is-booting::before,
  .system-terminal.is-shutting-down::after,
  .system-terminal.is-booting::after,
  .system-terminal.is-open .system-terminal__window,
  .system-terminal.is-booting .system-terminal__window,
  .system-terminal.is-restarting .system-terminal__window,
  .system-terminal.is-crashing .system-terminal__window {
    animation-duration: 160ms;
    animation-iteration-count: 1;
  }

  .system-terminal__jon {
    animation-name: terminal-jon-fade;
    animation-duration: 4400ms;
    animation-timing-function: linear;
    animation-iteration-count: 1;
  }
}
