@import url("https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=VT323&display=swap");

:root {
  --bg: #0d0d0d;
  --frame: #161616;
  --frame-edge: #2a2a2a;
  --panel: #020402;
  --text: #8dfca6;
  --prompt: #f9d66b;
  --muted: #5d806c;
  --system: #6de6ff;
  --good: #9dff7a;
  --warn: #ffaf45;
  --bad: #ff6a8b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Share Tech Mono", "VT323", monospace;
  overflow: hidden;
  position: relative;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0.015)),
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.22) 0,
      rgba(0, 0, 0, 0.22) 1px,
      transparent 1px,
      transparent 3px
    );
  opacity: 0.45;
  z-index: 2;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
  z-index: 2;
  animation: crt-flicker 0.2s infinite alternate;
}

.shell-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding:
    calc(1.05rem + env(safe-area-inset-top))
    calc(0.95rem + env(safe-area-inset-right))
    calc(0.75rem + env(safe-area-inset-bottom))
    calc(0.95rem + env(safe-area-inset-left));
}

@supports (height: 100dvh) {
  .shell-wrap {
    height: 100dvh;
  }
}

.titlebar {
  margin-bottom: 0.55rem;
  text-align: left;
  letter-spacing: 0.06em;
}

.titlebar h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-family: "VT323", "Share Tech Mono", monospace;
  color: var(--text);
  text-shadow: 0 0 8px rgba(141, 252, 166, 0.65);
}

.titlebar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.titlebar code {
  color: var(--prompt);
}

.terminal {
  border: 12px solid var(--frame);
  border-radius: 18px;
  background: linear-gradient(180deg, #020502 0%, #010301 100%);
  box-shadow:
    0 0 0 2px var(--frame-edge) inset,
    0 0 24px rgba(120, 255, 175, 0.2),
    0 24px 44px rgba(0, 0, 0, 0.65);
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.terminal::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(120, 255, 175, 0.03) 0%,
    transparent 32%,
    transparent 70%,
    rgba(120, 255, 175, 0.04) 100%
  );
}

.terminal,
.terminal * {
  text-shadow:
    0 0 4px rgba(120, 255, 175, 0.5),
    0 0 10px rgba(120, 255, 175, 0.22);
}

.output {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1.1rem 0.7rem;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(109, 230, 255, 0.75) transparent;
}

.output::-webkit-scrollbar {
  width: 8px;
}

.output::-webkit-scrollbar-track {
  background: transparent;
}

.output::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(141, 252, 166, 0.95), rgba(109, 230, 255, 0.8));
  border-radius: 999px;
}

.line {
  white-space: pre-wrap;
  line-height: 1.5;
  margin: 0 0 0.22rem;
  word-break: break-word;
}

.line.command {
  color: var(--prompt);
}

.line.system {
  color: var(--system);
}

.line.success {
  color: var(--good);
}

.line.error {
  color: var(--bad);
}

.line.warning {
  color: var(--warn);
}

.line a {
  color: var(--system);
}

.line a:hover {
  color: #b8f4ff;
}

.input-row {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.85rem 1.1rem 1rem;
  border-top: 1px solid rgba(141, 252, 166, 0.22);
  background: rgba(4, 8, 5, 0.9);
}

.prompt {
  color: var(--prompt);
  flex-shrink: 0;
  white-space: nowrap;
  font-size: clamp(0.78rem, 1.75vw, 1rem);
}

.input-shell {
  position: relative;
  flex: 1;
  min-width: 0;
  --cursor-col: 0;
}

#command-input {
  border: 0;
  background: transparent;
  color: var(--text);
  width: 100%;
  font: inherit;
  line-height: 1.4;
  font-size: 16px;
  outline: none;
  caret-color: transparent;
  padding: 0;
}

#command-input::selection {
  background: rgba(141, 252, 166, 0.3);
}

.fake-cursor {
  position: absolute;
  top: 0;
  left: calc(var(--cursor-col, 0) * 1ch);
  color: var(--text);
  line-height: 1.4;
  font-size: 16px;
  pointer-events: none;
  animation: blink-cursor 1s steps(1, end) infinite;
}

#command-input:disabled + .fake-cursor,
.input-shell.locked .fake-cursor {
  display: none;
}

#command-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.matrix-overlay {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: #020702;
}

.matrix-overlay.hidden {
  display: none;
}

#matrix-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

@keyframes blink-cursor {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@keyframes crt-flicker {
  from {
    opacity: 0.22;
  }
  to {
    opacity: 0.28;
  }
}

@media (max-width: 720px) {
  .shell-wrap {
    width: 100%;
    padding:
      calc(0.65rem + env(safe-area-inset-top))
      calc(0.55rem + env(safe-area-inset-right))
      calc(0.55rem + env(safe-area-inset-bottom))
      calc(0.55rem + env(safe-area-inset-left));
  }

  .terminal {
    border-width: 9px;
    border-radius: 14px;
  }

  .input-row {
    gap: 0.45rem;
    padding: 0.75rem 0.8rem 0.85rem;
  }

  .output {
    padding: 0.9rem 0.85rem 0.55rem;
  }
}

@media (max-width: 480px) {
  .titlebar h1 {
    font-size: clamp(1.2rem, 8.2vw, 1.7rem);
    line-height: 1.1;
  }

  .titlebar p {
    font-size: 0.82rem;
  }

  .terminal {
    border-width: 7px;
    border-radius: 11px;
  }

  .input-row {
    gap: 0.4rem;
    padding: 0.72rem 0.68rem 0.78rem;
  }

  .prompt {
    font-size: clamp(0.72rem, 3vw, 0.86rem);
  }

  #command-input,
  .fake-cursor {
    font-size: 16px;
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  .shell-wrap {
    padding:
      calc(0.45rem + env(safe-area-inset-top))
      calc(0.5rem + env(safe-area-inset-right))
      calc(0.45rem + env(safe-area-inset-bottom))
      calc(0.5rem + env(safe-area-inset-left));
  }

  .titlebar {
    margin-bottom: 0.32rem;
  }

  .titlebar h1 {
    font-size: clamp(1.1rem, 3.2vw, 1.5rem);
  }

  .titlebar p {
    display: none;
  }

  .terminal {
    border-width: 7px;
    border-radius: 11px;
  }

  .output {
    padding: 0.68rem 0.72rem 0.4rem;
  }

  .input-row {
    padding: 0.55rem 0.68rem 0.66rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::after {
    animation: none;
  }

  .fake-cursor {
    animation: none;
    opacity: 1;
  }
}
