:root {
  --desktop-grad-1: #2a0a47;
  --desktop-grad-2: #151c52;
  --desktop-grad-3: #090b1f;

  --terminal-bg: #030308;
  --terminal-fg: #00ff9c;
  --terminal-muted: #64dca9;
  --terminal-prompt: #00ff9c;
  --terminal-border: rgba(0, 255, 156, 0.25);
  --terminal-focus: #c0ffd8;
  --terminal-link: #8dfed1;
  --terminal-shadow: 0 30px 70px rgba(0, 0, 0, 0.55);
  --terminal-glow: 0 0 22px rgba(0, 255, 156, 0.2);
  --window-titlebar-bg: rgba(7, 16, 18, 0.86);
  --window-title-color: rgba(227, 255, 247, 0.92);
  --window-close-bg: rgba(255, 104, 90, 0.92);
  --window-close-fg: #2d0909;

  --kernel-fg: #00ff9c;
  --boot-fg: #d8ffe9;
}

body[data-theme="dark"] {
  --desktop-grad-1: #2a0a47;
  --desktop-grad-2: #151c52;
  --desktop-grad-3: #090b1f;

  --terminal-bg: #030308;
  --terminal-fg: #00ff9c;
  --terminal-muted: #64dca9;
  --terminal-prompt: #00ff9c;
  --terminal-border: rgba(0, 255, 156, 0.25);
  --terminal-focus: #c0ffd8;
  --terminal-link: #8dfed1;
  --terminal-shadow: 0 30px 70px rgba(0, 0, 0, 0.55);
  --terminal-glow: 0 0 22px rgba(0, 255, 156, 0.2);
  --window-titlebar-bg: rgba(7, 16, 18, 0.86);
  --window-title-color: rgba(227, 255, 247, 0.92);
  --window-close-bg: rgba(255, 104, 90, 0.92);
  --window-close-fg: #2d0909;
}

body[data-theme="light"] {
  --desktop-grad-1: #6a4a8b;
  --desktop-grad-2: #354f8f;
  --desktop-grad-3: #223048;

  --terminal-bg: #f8fdfb;
  --terminal-fg: #1a4433;
  --terminal-muted: #3c6a57;
  --terminal-prompt: #225842;
  --terminal-border: rgba(34, 88, 66, 0.28);
  --terminal-focus: #225842;
  --terminal-link: #225842;
  --terminal-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
  --terminal-glow: 0 0 16px rgba(34, 88, 66, 0.16);
  --window-titlebar-bg: rgba(229, 246, 238, 0.9);
  --window-title-color: rgba(20, 48, 36, 0.95);
  --window-close-bg: rgba(224, 91, 78, 0.92);
  --window-close-fg: #fff;
}

body[data-theme="matrix"] {
  --desktop-grad-1: #061605;
  --desktop-grad-2: #071f0a;
  --desktop-grad-3: #020805;

  --terminal-bg: #010c01;
  --terminal-fg: #39ff14;
  --terminal-muted: #9ce68a;
  --terminal-prompt: #7dff60;
  --terminal-border: rgba(57, 255, 20, 0.28);
  --terminal-focus: #a9ff95;
  --terminal-link: #adff9b;
  --terminal-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
  --terminal-glow: 0 0 24px rgba(57, 255, 20, 0.28);
  --window-titlebar-bg: rgba(8, 24, 8, 0.9);
  --window-title-color: rgba(189, 255, 175, 0.94);
  --window-close-bg: rgba(127, 255, 96, 0.92);
  --window-close-fg: #052304;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 16px;
  line-height: 1.45;
  color: var(--terminal-fg);
  background: #000;
}

#boot-sequence {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  opacity: 1;
  transition: opacity 260ms ease;
}

#boot-sequence.hidden {
  opacity: 0;
  pointer-events: none;
}

.boot-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease;
}

.boot-screen.active {
  opacity: 1;
  visibility: visible;
}

.boot-copy {
  margin: 0;
  color: var(--boot-fg);
  font-size: clamp(0.84rem, 1.8vw, 1.05rem);
  white-space: pre-wrap;
  text-align: center;
  text-shadow: 0 0 8px rgba(120, 255, 182, 0.18);
}

#kernel-screen {
  justify-content: flex-start;
  align-items: flex-start;
}

#kernel-log {
  width: min(980px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 1.5rem;
  color: var(--kernel-fg);
  font-size: clamp(0.82rem, 1.8vw, 0.98rem);
  text-shadow: 0 0 7px rgba(57, 255, 20, 0.2);
}

.kernel-line {
  margin: 0 0 0.33rem;
  white-space: pre-wrap;
}

#ascii-screen {
  flex-direction: column;
  gap: 0.7rem;
}

#ascii-banner {
  margin: 0;
  color: var(--kernel-fg);
  font-size: clamp(0.45rem, 1.45vw, 1rem);
  line-height: 1.2;
  text-align: center;
  white-space: pre;
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.2);
}

.ascii-title,
.ascii-subtitle,
.ascii-ready {
  margin: 0;
  text-align: center;
}

.ascii-title {
  font-size: clamp(0.9rem, 2.2vw, 1.2rem);
  font-weight: 700;
  color: #f5fff9;
}

.ascii-subtitle {
  font-size: clamp(0.78rem, 1.9vw, 0.95rem);
  color: #adff9b;
}

.ascii-ready {
  margin-top: 0.25rem;
  color: #f5fff9;
}

#desktop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 12%, rgba(255, 76, 184, 0.2), transparent 40%),
    linear-gradient(135deg, var(--desktop-grad-1) 0%, var(--desktop-grad-2) 45%, var(--desktop-grad-3) 100%);
  transition: opacity 340ms ease;
}

#desktop.active {
  opacity: 1;
  pointer-events: auto;
}

#desktop::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.46) 100%);
}

#desktop::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 84px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 84px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.18) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.14) 0 1px, transparent 1px 4px);
}

#os-brand {
  position: absolute;
  top: 0.85rem;
  left: 1rem;
  z-index: 2;
  margin: 0;
  font-size: 0.74rem;
  color: rgba(241, 247, 255, 0.66);
  letter-spacing: 0.04em;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.45);
}

#desktop-launcher {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.launcher-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.36rem;
}

.launcher-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  width: 2.55rem;
  height: 2.55rem;
  display: grid;
  place-items: center;
  color: #f5fffe;
  background: linear-gradient(180deg, rgba(78, 118, 255, 0.42), rgba(31, 48, 112, 0.45));
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background-color 150ms ease;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

.launcher-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 22px rgba(89, 188, 255, 0.36);
  border-color: rgba(189, 239, 255, 0.75);
}

.launcher-button.selected {
  background: linear-gradient(180deg, rgba(114, 161, 255, 0.58), rgba(46, 73, 168, 0.48));
  border-color: rgba(220, 245, 255, 0.88);
}

.launcher-button:focus {
  outline: none;
}

.launcher-button:focus-visible {
  outline: 2px solid rgba(228, 248, 255, 0.95);
  outline-offset: 2px;
}

.launcher-icon {
  font-size: 0.9rem;
  line-height: 1;
  font-weight: 700;
}

.launcher-label {
  font-size: 0.64rem;
  color: rgba(236, 247, 255, 0.86);
  letter-spacing: 0.02em;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.52);
}

#desktop-popup {
  position: absolute;
  left: 50%;
  bottom: 1.35rem;
  z-index: 5;
  transform: translateX(-50%) translateY(10px);
  padding: 0.42rem 0.72rem;
  border-radius: 8px;
  border: 1px solid rgba(228, 242, 255, 0.32);
  background: rgba(13, 18, 35, 0.74);
  color: rgba(234, 244, 255, 0.94);
  font-size: 0.66rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}

#desktop-popup.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#pip-video {
  position: absolute;
  top: 0.95rem;
  right: 1rem;
  z-index: 3;
  width: min(318px, 36vw);
  padding: 0.44rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  background: rgba(10, 12, 18, 0.52);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.45);
}

@supports ((-webkit-backdrop-filter: blur(10px)) or (backdrop-filter: blur(10px))) {
  #pip-video {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}

.pip-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background:
    radial-gradient(circle at 16% 20%, rgba(255, 195, 131, 0.24), transparent 36%),
    linear-gradient(155deg, rgba(63, 97, 205, 0.45), rgba(38, 22, 82, 0.55));
}

.pip-title {
  margin: 0.44rem 0 0.1rem;
  color: rgba(247, 251, 255, 0.92);
  font-size: 0.72rem;
}

.pip-subtitle {
  margin: 0;
  color: rgba(233, 240, 255, 0.74);
  font-size: 0.68rem;
}

#system-monitor {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 3;
  width: min(294px, 33vw);
  padding: 0.6rem 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(142, 255, 196, 0.28);
  background: rgba(4, 12, 12, 0.5);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.38);
}

.monitor-title {
  margin: 0 0 0.32rem;
  font-size: 0.68rem;
  color: rgba(154, 255, 216, 0.86);
  letter-spacing: 0.02em;
}

#system-monitor-stats {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.68rem;
  line-height: 1.35;
  color: rgba(183, 255, 227, 0.9);
}

#desktop-mode {
  position: absolute;
  left: 1rem;
  bottom: 0.85rem;
  z-index: 2;
  margin: 0;
  font-size: 0.67rem;
  line-height: 1.35;
  color: rgba(241, 247, 255, 0.58);
  white-space: pre-line;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.42);
}

#terminal-window {
  position: relative;
  z-index: 6;
  display: flex;
  flex-direction: column;
  width: min(980px, 100%);
  height: min(78vh, 720px);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(6, 6, 10, 0.84);
  box-shadow: var(--terminal-shadow), 0 0 60px rgba(195, 0, 255, 0.16);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.95);
}

#terminal-window::after {
  content: "";
  position: absolute;
  inset: 14% 10% auto;
  height: 40%;
  z-index: -1;
  pointer-events: none;
  filter: blur(38px);
  background: radial-gradient(circle at center, rgba(125, 255, 96, 0.18), transparent 70%);
}

#terminal-window.launched {
  animation: terminal-launch 300ms cubic-bezier(0.2, 0.86, 0.25, 1) forwards;
}

#terminal-window.closing {
  visibility: visible;
  pointer-events: none;
  animation: terminal-close 200ms ease forwards;
}

#terminal-window.open {
  visibility: visible;
  pointer-events: auto;
}

#window-titlebar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--terminal-border);
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  background: var(--window-titlebar-bg);
}

.window-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.window-close {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0;
  display: inline-grid;
  place-items: center;
  width: 1.42rem;
  height: 1.42rem;
  border-radius: 8px;
  background: var(--window-close-bg);
  color: var(--window-close-fg);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}

.window-close:hover {
  filter: brightness(1.08);
}

.window-close:focus {
  outline: none;
}

.window-close:focus-visible {
  box-shadow: 0 0 0 2px rgba(239, 248, 255, 0.82), inset 0 0 0 1px rgba(0, 0, 0, 0.26);
}

.window-title {
  margin: 0;
  color: var(--window-title-color);
  font-size: 0.89rem;
}

#terminal {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  flex: 1;
  min-height: 0;
  padding: 1.1rem;
  background: var(--terminal-bg);
  border: 1px solid var(--terminal-border);
  border-radius: 0 0 14px 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), var(--terminal-glow);
}

body[data-theme="matrix"] #terminal::before {
  content: "";
  position: absolute;
  inset: -120%;
  z-index: -1;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(57, 255, 20, 0.07) 0,
      rgba(57, 255, 20, 0.07) 2px,
      rgba(0, 0, 0, 0) 2px,
      rgba(0, 0, 0, 0) 8px
    );
  animation: matrix-drift 18s linear infinite;
}

#terminal:focus-within {
  box-shadow: inset 0 0 0 1px var(--terminal-focus), 0 0 24px rgba(0, 255, 156, 0.24);
}

#output {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--terminal-muted) transparent;
}

#output::-webkit-scrollbar {
  width: 10px;
}

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

#output::-webkit-scrollbar-thumb {
  background: var(--terminal-muted);
}

.output-line {
  margin: 0 0 0.54rem;
  white-space: pre-wrap;
  text-shadow: 0 0 6px rgba(0, 255, 156, 0.2);
  animation: line-in 120ms ease-out both;
}

.output-line.command-echo {
  color: var(--terminal-muted);
}

.output-line a {
  color: var(--terminal-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.output-line a:hover {
  opacity: 0.88;
}

#command-form {
  margin: 0;
}

.prompt-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
}

.prompt {
  color: var(--terminal-prompt);
  flex: 0 0 auto;
  text-shadow: 0 0 8px rgba(0, 255, 156, 0.35);
}

.input-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

#command-input {
  width: 100%;
  min-width: 0;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  color: var(--terminal-fg);
  font: inherit;
  caret-color: var(--terminal-fg);
}

#command-input:focus {
  outline: none;
}

#command-input:focus-visible {
  outline: 2px solid var(--terminal-focus);
  outline-offset: 2px;
}

.cursor {
  width: 0.7ch;
  height: 1.1em;
  margin-left: 0.15rem;
  background: var(--terminal-fg);
  box-shadow: 0 0 8px var(--terminal-fg);
  animation: blink 1s steps(2, start) infinite;
  flex: 0 0 auto;
}

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

@keyframes terminal-launch {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes terminal-close {
  from {
    opacity: 1;
    transform: scale(1);
  }

  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }

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

@keyframes line-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes matrix-drift {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(60%);
  }
}

@media (max-width: 880px) {
  #desktop {
    padding: 1rem;
  }

  #desktop-launcher {
    left: 14px;
  }

  #pip-video {
    width: min(286px, 42vw);
  }

  #system-monitor {
    width: min(272px, 40vw);
  }

  #terminal-window {
    width: min(94vw, 980px);
    height: min(86vh, 760px);
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  #os-brand {
    left: 0.8rem;
    top: 0.7rem;
    font-size: 0.67rem;
  }

  #desktop-launcher {
    left: 50%;
    top: auto;
    bottom: 0.68rem;
    transform: translateX(-50%);
    flex-direction: row;
    gap: 0.72rem;
  }

  .launcher-entry {
    gap: 0.24rem;
  }

  .launcher-button {
    width: 2.2rem;
    height: 2.2rem;
  }

  .launcher-icon {
    font-size: 0.74rem;
  }

  .launcher-label {
    font-size: 0.52rem;
  }

  #pip-video {
    top: 0.65rem;
    right: 0.62rem;
    width: min(192px, 46vw);
    padding: 0.34rem;
  }

  .pip-title {
    font-size: 0.61rem;
  }

  .pip-subtitle {
    font-size: 0.58rem;
  }

  #system-monitor {
    right: 0.62rem;
    bottom: 4rem;
    width: min(198px, 50vw);
    padding: 0.42rem 0.5rem;
  }

  .monitor-title {
    font-size: 0.58rem;
  }

  #system-monitor-stats {
    font-size: 0.57rem;
  }

  #desktop-mode {
    left: 0.72rem;
    bottom: 3.95rem;
    font-size: 0.56rem;
  }

  #desktop-popup {
    bottom: 4.1rem;
    font-size: 0.58rem;
  }

  #window-titlebar {
    padding: 0.62rem 0.78rem;
  }

  .window-title {
    font-size: 0.8rem;
  }

  #terminal-window {
    width: 96vw;
    height: 82vh;
    margin-bottom: 3rem;
  }

  #terminal {
    padding: 0.86rem;
  }

  .prompt-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
  }

  .input-wrap {
    width: 100%;
  }
}
