/**
 * UnixCore Terminal Playground — self-contained styles
 * Pair with terminal.js on #unix-terminal
 */

#unix-terminal {
  width: 100%;
  min-width: 0;
}

.uxt-widget {
  --uxt-bg: #0d1117;
  --uxt-bg-bar: #161b22;
  --uxt-border: #30363d;
  --uxt-green: #39ff14;
  --uxt-input: #ffffff;
  --uxt-prompt: #888888;
  --uxt-muted: #6e7681;
  --uxt-tip: #555555;
  --uxt-dir: #58a6ff;
  --uxt-exe: #3fb950;
  --uxt-file: #39ff14;
  --uxt-err: #f85149;
  --uxt-font: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  --uxt-height: 400px;
  --uxt-radius: 10px;
  --uxt-scrollbar-track: #0a0e14;
  --uxt-scrollbar-thumb: rgba(57, 255, 20, 0.28);
  --uxt-scrollbar-thumb-hover: rgba(57, 255, 20, 0.48);

  position: relative;
  font-family: var(--uxt-font);
  font-size: 14px;
  line-height: 1.55;
  border: 1px solid var(--uxt-border);
  border-radius: var(--uxt-radius);
  background: var(--uxt-bg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

@media (max-width: 640px) {
  .uxt-widget {
    --uxt-height: 300px;
    font-size: 14px;
  }

  .uxt-input {
    font-size: 16px;
  }

  .uxt-output,
  .uxt-out,
  .uxt-line {
    font-size: 14px;
  }

  .uxt-screen {
    -webkit-tap-highlight-color: transparent;
  }
}

/* CRT scanlines (toggleable) */
.uxt-widget--scanlines .uxt-scanlines {
  opacity: 0.06;
  pointer-events: none;
}

.uxt-scanlines {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  transition: opacity 0.2s ease;
}

.uxt-widget--scanlines::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.35) 100%);
}

/* Title bar */
.uxt-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--uxt-bg-bar);
  border-bottom: 1px solid var(--uxt-border);
  position: relative;
  z-index: 4;
}

.uxt-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.uxt-dot--red { background: #ff5f57; }
.uxt-dot--yellow { background: #ffbd2e; }
.uxt-dot--green { background: #28ca41; }

.uxt-titlebar__label {
  flex: 1;
  min-width: 0;
  margin-left: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--uxt-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.uxt-titlebar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.uxt-titlebar__btn {
  appearance: none;
  padding: 4px 10px;
  border: 1px solid var(--uxt-border);
  border-radius: 6px;
  background: var(--uxt-bg);
  color: var(--uxt-muted);
  font-family: var(--uxt-font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.uxt-titlebar__btn:hover {
  color: var(--uxt-green);
  border-color: var(--uxt-green);
}

.uxt-titlebar__btn--help {
  width: 28px;
  padding: 4px 0;
  text-align: center;
}

.uxt-help-popover {
  position: absolute;
  top: 48px;
  right: 12px;
  z-index: 20;
  width: min(280px, calc(100% - 24px));
  padding: 12px 14px;
  border: 1px solid var(--uxt-border);
  border-radius: 8px;
  background: var(--uxt-bg-bar);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.uxt-help-popover__title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--uxt-green);
}

.uxt-help-popover__list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--uxt-muted);
  line-height: 1.7;
}

/* Screen area */
.uxt-screen {
  position: relative;
  height: var(--uxt-height);
  max-height: var(--uxt-height);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px 8px;
  background: var(--uxt-bg);
  cursor: text;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
  scrollbar-width: thin;
  scrollbar-color: var(--uxt-scrollbar-thumb) var(--uxt-scrollbar-track);
}

.uxt-screen:focus {
  outline: none;
}

.uxt-screen::-webkit-scrollbar {
  width: 10px;
}

.uxt-screen::-webkit-scrollbar-track {
  background: var(--uxt-scrollbar-track);
  border-left: 1px solid var(--uxt-border);
}

.uxt-screen::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    var(--uxt-scrollbar-thumb-hover) 0%,
    var(--uxt-scrollbar-thumb) 100%
  );
  border: 2px solid var(--uxt-scrollbar-track);
  border-radius: 6px;
  box-shadow: inset 0 0 6px rgba(57, 255, 20, 0.15);
}

.uxt-screen::-webkit-scrollbar-thumb:hover {
  background: var(--uxt-scrollbar-thumb-hover);
}

.uxt-screen::-webkit-scrollbar-corner {
  background: var(--uxt-scrollbar-track);
}

.uxt-output {
  user-select: text;
  -webkit-user-select: text;
}

.uxt-line {
  margin: 0 0 2px;
  white-space: pre-wrap;
  word-break: break-word;
}

.uxt-out {
  color: var(--uxt-green);
}

.uxt-muted {
  color: var(--uxt-muted);
}

.uxt-err {
  color: var(--uxt-err);
}

.uxt-tip {
  color: var(--uxt-tip);
  font-size: 12px;
  margin-top: 4px;
  margin-bottom: 8px;
  font-style: italic;
}

.uxt-dir {
  color: var(--uxt-dir);
  font-weight: 600;
}

.uxt-exe {
  color: var(--uxt-exe);
  font-weight: 600;
}

.uxt-file {
  color: var(--uxt-file);
}

.uxt-line--echo .uxt-prompt-static {
  color: var(--uxt-prompt);
}

.uxt-line--echo .uxt-input-echo {
  color: var(--uxt-input);
}

.uxt-prompt-static {
  color: var(--uxt-prompt);
}

/* Input row */
.uxt-inputline {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0;
  margin-top: 6px;
  padding-bottom: 6px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, var(--uxt-bg) 12px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.uxt-inputline__wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  cursor: text;
  -webkit-tap-highlight-color: transparent;
}

.uxt-prompt {
  color: var(--uxt-prompt);
  white-space: nowrap;
  flex-shrink: 0;
  font-size: inherit;
}

.uxt-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--uxt-input);
  font-family: var(--uxt-font);
  font-size: inherit;
  line-height: inherit;
  outline: none;
  caret-color: var(--uxt-green);
}

.uxt-input::placeholder {
  color: var(--uxt-muted);
  opacity: 0.85;
}

.uxt-input:disabled {
  opacity: 0.6;
}

.uxt-cursor {
  display: inline-block;
  width: 9px;
  height: 1.15em;
  margin-left: 1px;
  background: var(--uxt-green);
  vertical-align: text-bottom;
  animation: uxt-blink 1s step-end infinite;
  flex-shrink: 0;
}

.uxt-cursor--inline {
  margin-left: 0;
}

@keyframes uxt-blink {
  50% {
    opacity: 0;
  }
}

/* Processing indicator */
.uxt-processing {
  display: flex;
  gap: 4px;
  padding: 4px 0 8px;
}

.uxt-processing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--uxt-green);
  animation: uxt-pulse 0.9s ease-in-out infinite;
}

.uxt-processing span:nth-child(2) {
  animation-delay: 0.15s;
}

.uxt-processing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes uxt-pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Tab autocomplete */
.uxt-autocomplete {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 52px;
  z-index: 10;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  border: 1px solid var(--uxt-border);
  border-radius: 6px;
  background: var(--uxt-bg-bar);
  max-height: 140px;
  overflow-y: auto;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  scrollbar-width: thin;
  scrollbar-color: var(--uxt-scrollbar-thumb) var(--uxt-scrollbar-track);
}

.uxt-autocomplete::-webkit-scrollbar {
  width: 8px;
}

.uxt-autocomplete::-webkit-scrollbar-track {
  background: var(--uxt-scrollbar-track);
}

.uxt-autocomplete::-webkit-scrollbar-thumb {
  background: var(--uxt-scrollbar-thumb);
  border-radius: 4px;
}

.uxt-autocomplete li {
  padding: 4px 12px;
  font-size: 12px;
  color: var(--uxt-green);
  cursor: default;
}

.uxt-autocomplete li:hover {
  background: rgba(57, 255, 20, 0.08);
}

/* ── SL locomotive (CSS motion + JS-built DOM) ── */

.uxt-sl-wrap {
  overflow: hidden;
  margin: 8px 0 4px;
}

.uxt-sl-stage {
  position: relative;
  height: 108px;
  overflow: hidden;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.25) 0%, transparent 45%);
}

.uxt-sl-rails {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  height: 8px;
  z-index: 0;
}

.uxt-sl-rails span {
  display: block;
  height: 2px;
  background: repeating-linear-gradient(
    90deg,
    #484f58 0,
    #484f58 12px,
    transparent 12px,
    transparent 20px
  );
  animation: uxt-sl-rail-scroll 0.4s linear infinite;
}

.uxt-sl-rails span:last-child {
  margin-top: 4px;
  opacity: 0.5;
  animation-duration: 0.55s;
  animation-direction: reverse;
}

@keyframes uxt-sl-rail-scroll {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 40px 0;
  }
}

.uxt-sl-smoke {
  position: absolute;
  left: 12%;
  bottom: 52px;
  z-index: 2;
  width: 48px;
  height: 40px;
  pointer-events: none;
}

.uxt-sl-smoke__puff {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 200, 200, 0.35) 0%, transparent 70%);
  animation: uxt-sl-smoke-rise 1.4s ease-out infinite;
  opacity: 0;
}

.uxt-sl-smoke__puff:nth-child(1) {
  animation-delay: 0s;
  left: 0;
}

.uxt-sl-smoke__puff:nth-child(2) {
  animation-delay: 0.45s;
  left: 12px;
  width: 18px;
  height: 18px;
}

.uxt-sl-smoke__puff:nth-child(3) {
  animation-delay: 0.9s;
  left: 24px;
}

@keyframes uxt-sl-smoke-rise {
  0% {
    transform: translate(0, 0) scale(0.4);
    opacity: 0;
  }
  15% {
    opacity: 0.7;
  }
  100% {
    transform: translate(18px, -36px) scale(1.4);
    opacity: 0;
  }
}

.uxt-sl-train {
  position: absolute;
  bottom: 22px;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  white-space: pre;
  color: var(--uxt-green);
  text-shadow: 0 0 12px rgba(57, 255, 20, 0.35);
  animation: uxt-sl-train-run 2.8s cubic-bezier(0.35, 0, 0.2, 1) forwards;
  will-change: transform;
}

.uxt-sl-carriage {
  margin: 0;
  font-size: 11px;
  line-height: 1.15;
  font-family: var(--uxt-font);
}

.uxt-sl-engine {
  color: #7ee787;
}

.uxt-sl-carriage--caboose {
  color: #d29922;
}

@keyframes uxt-sl-train-run {
  0% {
    transform: translateX(105%);
  }
  100% {
    transform: translateX(-115%);
  }
}

.uxt-sl-wheels {
  position: absolute;
  bottom: 14px;
  left: 0;
  z-index: 2;
  display: flex;
  gap: 28px;
  padding-left: 8%;
  animation: uxt-sl-train-run 2.8s cubic-bezier(0.35, 0, 0.2, 1) forwards;
  pointer-events: none;
}

.uxt-sl-wheels i {
  display: block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--uxt-muted);
  border-radius: 50%;
  border-top-color: var(--uxt-green);
  animation: uxt-sl-wheel-spin 0.35s linear infinite;
}

.uxt-sl-wheels i:nth-child(odd) {
  animation-direction: reverse;
}

@keyframes uxt-sl-wheel-spin {
  to {
    transform: rotate(360deg);
  }
}

.uxt-sl-caption {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--uxt-muted);
  text-align: center;
  animation: uxt-sl-caption-fade 2.8s ease forwards;
}

@keyframes uxt-sl-caption-fade {
  0%,
  70% {
    opacity: 0;
  }
  85%,
  100% {
    opacity: 1;
  }
}

/* ── Matrix rain (CSS columns + JS glyph updates) ── */

.uxt-matrix {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.82);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.uxt-matrix--in {
  opacity: 1;
}

.uxt-matrix--out {
  opacity: 0;
}

.uxt-matrix__col {
  position: absolute;
  top: 0;
  width: 1.1em;
  height: 100%;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.05;
  animation: uxt-matrix-rain var(--uxt-matrix-dur, 1.4s) linear infinite;
  animation-delay: var(--uxt-matrix-delay, 0s);
}

.uxt-matrix__strand {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: uxt-matrix-strand-drift 0.15s steps(2) infinite;
}

.uxt-matrix__glyph {
  display: block;
  color: #1a6b2e;
  text-shadow: 0 0 4px rgba(57, 255, 20, 0.25);
  transition: color 0.08s ease;
}

.uxt-matrix__glyph--dim {
  color: #0d3d18;
  opacity: 0.55;
}

.uxt-matrix__glyph--head {
  color: #ffffff;
  font-weight: 600;
  text-shadow:
    0 0 8px #39ff14,
    0 0 16px rgba(57, 255, 20, 0.6);
}

@keyframes uxt-matrix-rain {
  0% {
    transform: translateY(-105%);
  }
  100% {
    transform: translateY(105%);
  }
}

@keyframes uxt-matrix-strand-drift {
  50% {
    transform: translateX(1px);
  }
}

.uxt-matrix__col:nth-child(3n) .uxt-matrix__glyph--head {
  color: #b8ffd0;
}

.uxt-matrix__col:nth-child(5n) {
  animation-duration: calc(var(--uxt-matrix-dur, 1.4s) * 1.15);
}

/* Page section wrapper (index / terminal.html) */
.ux-terminal-playground {
  margin-bottom: 56px;
}

.ux-terminal-playground__head {
  margin-bottom: 20px;
}

.ux-terminal-playground__title {
  margin: 0 0 8px;
  font-family: var(--ux-font-display, "Syne", sans-serif);
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: 700;
  color: var(--ux-text, #e6edf3);
}

.ux-terminal-playground__lede {
  margin: 0;
  max-width: 62ch;
  color: var(--ux-text-muted, #8b949e);
  font-size: 14px;
  line-height: 1.65;
}

.ux-terminal-playground__meta {
  margin-top: 12px;
  font-size: 12px;
}

.ux-terminal-playground__meta a {
  color: var(--ux-green, #3fb950);
}

.ux-terminal-page .ux-terminal-playground--full {
  max-width: none;
}

.ux-terminal-page #unix-terminal .uxt-widget {
  --uxt-height: min(70vh, 560px);
}

@media (max-width: 640px) {
  .ux-terminal-page #unix-terminal .uxt-widget {
    --uxt-height: min(65vh, 420px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .uxt-cursor,
  .uxt-sl-train,
  .uxt-sl-wheels,
  .uxt-sl-rails span,
  .uxt-sl-smoke__puff,
  .uxt-matrix__col,
  .uxt-matrix__strand,
  .uxt-processing span {
    animation: none;
  }

  .uxt-sl-train,
  .uxt-sl-wheels {
    transform: translateX(0);
  }

  .uxt-matrix--in {
    opacity: 0.9;
  }
}
