:root {
  color-scheme: dark;

  /* Color palette - Professional and modern */
  --bg: #041019;
  --ink: #d4f9ff;
  --ink-dim: #8fdcf2;
  --ink-warn: #ff5f64;
  --accent: #18d2ff;
  --accent-soft: rgba(24, 210, 255, 0.35);
  --accent-glow: rgba(24, 210, 255, 0.08);
  --ps1: #82e8ff;

  /* Effects */
  --scan-opacity: 0.12;
  --noise-opacity: 0.07;

  /* Typography */
  --font: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --font-size-base: 15px;
  --font-size-sm: 14px;
  --line-height: 1.6;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 0.75rem;
  --spacing-lg: 1rem;
  --spacing-xl: 1.5rem;

  /* Border radius */
  --radius-sm: 8px;
  --radius-md: 12px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

/* Modern CSS Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  /* Dynamic viewport height for mobile */
  font-family: var(--font);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--ink);
  background: radial-gradient(1200px 600px at 50% 0%, #072235 0%, var(--bg) 60%);
  overflow: hidden;
  position: relative;
}

/* Matrix rain background - Performance optimized */
#rain {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  will-change: transform;
  /* GPU acceleration hint */
}

/* Visual effects overlays */
.overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.noise {
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.scanlines {
  background: repeating-linear-gradient(to bottom,
      rgba(255, 255, 255, var(--scan-opacity)) 0px,
      rgba(0, 0, 0, 0) 2px,
      rgba(0, 0, 0, 0) 3px);
  background-size: 100% 4px;
  animation: scanlineText 0.3s linear infinite;
}

@keyframes scanlineText {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(3px);
  }
}

/* Main container - Improved layout */
.wrap {
  position: relative;
  z-index: 3;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--spacing-lg);
}

/* Terminal window - Enhanced design */
.terminal {
  width: min(980px, 92vw);
  max-width: 100%;
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(6, 20, 32, 0.85), rgba(6, 12, 18, 0.9));
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent),
    0 10px 80px var(--accent-glow),
    0 4px 16px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
  animation: terminalBreath 4s ease-in-out infinite alternate;
}

@keyframes terminalBreath {
  0% {
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent),
      0 10px 80px var(--accent-glow),
      0 4px 16px rgba(0, 0, 0, 0.3);
  }

  100% {
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent),
      0 12px 90px color-mix(in srgb, var(--accent) 12%, transparent),
      0 6px 20px rgba(0, 0, 0, 0.4);
    border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  }
}

.terminal:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent),
    0 16px 96px var(--accent-glow),
    0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Terminal header - Refined styling */
.term-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  background: rgba(0, 0, 0, 0.15);
}

.led {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%,
      color-mix(in srgb, var(--accent) 85%, white 15%),
      var(--accent) 60%,
      rgba(6, 26, 38, 0.9) 65%);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent);
  filter: saturate(1.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

.led.on {
  opacity: 1;
}

.title {
  flex: 1;
  opacity: 0.9;
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Action buttons - Modern interactive design */
.actions {
  display: flex;
  gap: var(--spacing-sm);
}

.actions .btn {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: transparent;
  color: var(--ink);
  padding: var(--spacing-xs) calc(var(--spacing-sm) + 0.05rem);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: 600 12px var(--font);
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.actions .btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.actions .btn:hover::before {
  opacity: 1;
}

.actions .btn:hover {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  transform: translateY(-1px);
}

.actions .btn:active {
  transform: translateY(1px);
}

.actions .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Terminal content area */
.term {
  padding: var(--spacing-lg) var(--spacing-lg) 0;
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  min-height: 40vh;
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-word;
  scroll-behavior: smooth;
}

/* Custom scrollbar for terminal */
.term::-webkit-scrollbar {
  width: 8px;
}

.term::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.term::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 4px;
}

.term::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent) 60%, transparent);
}

/* Terminal text styles */
.line {
  white-space: pre-wrap;
  margin-bottom: 0.25em;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

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

.muted {
  color: var(--ink-dim);
}

.error {
  color: var(--ink-warn);
}

.cmd {
  color: color-mix(in srgb, var(--accent) 80%, white 20%);
  font-weight: 400;
}

/* Link styling in terminal */
.line.link {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  flex-wrap: wrap;
}

.line.link .link-label {
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 600;
}

.line.link a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  transition: all var(--transition-fast);
  position: relative;
}

.line.link a:hover {
  border-bottom-style: solid;
  color: color-mix(in srgb, var(--accent) 85%, white 15%);
}

.line.link a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Command prompt area */
.prompt {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  border-top: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: var(--spacing-md) var(--spacing-lg);
  background: rgba(0, 0, 0, 0.1);
}

.prompt-icon {
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.85;
}

.ps1 {
  color: var(--ps1);
  opacity: 0.9;
  font-weight: 400;
  white-space: nowrap;
}

input#cli {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font: 400 var(--font-size-base) var(--font);
  color: var(--ink);
  min-width: 0;
  /* Allow flex shrinking */
}

input#cli::placeholder {
  color: color-mix(in srgb, var(--ink) 45%, transparent);
  font-style: italic;
}

input#cli:focus::placeholder {
  opacity: 0.5;
}

/* Responsive design - Mobile optimization */
@media (max-width: 768px) {
  body:not(.maintenance) {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }

  .wrap {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(env(safe-area-inset-top, 0px), 1.2rem) 1rem max(env(safe-area-inset-bottom, 0px), 1.8rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .terminal {
    width: 100%;
    margin: 0;
    border-radius: 10px;
  }

  .terminal:hover {
    transform: none;
    /* Disable hover effect on mobile */
  }

  .term-header {
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    align-items: flex-start;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .term-header .title {
    flex: 1 1 auto;
    font-size: 0.95rem;
  }

  .actions {
    display: flex;
    flex: 1 1 100%;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
    width: 100%;
  }

  .actions .btn {
    flex: 1 1 calc(50% - var(--spacing-xs) / 2);
    padding: 0.45rem var(--spacing-sm);
    font-size: 0.8rem;
    min-height: 42px;
    min-width: 0;
    touch-action: manipulation;
    /* Optimize for touch */
  }

  .term {
    padding: var(--spacing-md);
    font-size: var(--font-size-sm);
    min-height: 0;
    max-height: 50vh;
  }

  .prompt {
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    align-items: flex-start;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .prompt-icon {
    font-size: 0.95rem;
  }

  .ps1 {
    font-size: 0.85rem;
    word-break: break-all;
  }

  input#cli {
    flex: 1 1 160px;
    min-width: 0;
    font-size: 1rem;
    -webkit-text-size-adjust: 100%;
    /* Prevent zoom on iOS */
  }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
  .terminal {
    width: min(900px, 90vw);
  }

  .term {
    max-height: 55vh;
  }
}

/* Large screens optimization */
@media (min-width: 1400px) {
  .terminal {
    width: min(1100px, 85vw);
  }

  .term {
    max-height: 65vh;
  }
}

/* Accessibility - Reduced motion preference */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .scanlines {
    display: none;
  }

  .terminal {
    animation: none;
  }

  .noise {
    opacity: 0.03;
  }

  .led {
    animation: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --accent: #00e5ff;
    --ink: #ffffff;
  }

  .terminal {
    border-width: 2px;
  }
}

/* ByteFlux colour coding */
.line.byteflux-info {
  color: color-mix(in srgb, var(--accent) 70%, white 10%)
}

.line.byteflux-system {
  color: #b8f5ff
}

.line.byteflux-alert {
  color: #ffd27a
}

.line.byteflux-critical {
  color: #ff8e91
}

.line.byteflux-success {
  color: #9cf8ff
}

.line.byteflux-banner {
  color: #e3fbff;
  text-transform: uppercase;
}

/* Maintenance screen */
body.maintenance {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% 0%, #072235 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: var(--font);
}

.maintenance-shell {
  border: 1px solid var(--accent-soft);
  border-radius: 14px;
  padding: 2.75rem 2.4rem;
  max-width: 420px;
  width: 90vw;
  background: linear-gradient(180deg, rgba(6, 18, 28, .88), rgba(4, 12, 20, .92));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 15%, transparent),
    0 20px 80px var(--accent-glow);
  text-align: left;
}

.maintenance-shell h1 {
  margin: 0 0 1.2rem;
  font-size: 1.8rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.maintenance-shell p {
  margin: .4rem 0 0;
  font-size: 1rem;
  color: var(--ink);
}

.maintenance-shell .status {
  display: inline-block;
  margin-bottom: 1.2rem;
  padding: .25rem .65rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
  color: var(--ps1);
  font-size: .75rem;
  letter-spacing: .18em;
}

/* Load Time Indicator */
.load-time {
  position: absolute;
  bottom: 0.5rem;
  right: 1rem;
  font-size: 0.7rem;
  color: var(--ink-dim);
  opacity: 0.4;
  font-family: var(--font);
  pointer-events: none;
  z-index: 10;
  transition: opacity var(--transition-base);
}

.terminal:hover .load-time {
  opacity: 0.8;
}