  :root {
    --mobile-scale: 1;
    
    /* CRT Theme CSS Custom Properties (default: green-p1) */
    --crt-foreground: #00ff00;
    --crt-background: #080808;
    --crt-phosphor-base: #00ff00;
    --crt-glow-color: rgba(0, 255, 0, 0.85);
    --crt-glow-intensity: 0.85;
    --crt-phosphor-blend-opacity: 1.0;
  }

  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  html {
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }

  body {
    width: 100vw;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    background: #0a1822;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 5px; /* Reduced from 20px 10px for larger CRT */
    /* Prevent text selection on mobile */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  /* Allow text selection only in terminal */
  #xterm-container,
  #xterm-container * {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
  }
  
  canvas {
    display: block;
  }

  #xterm-container {
    background: #000000;
    font-family: 'VT323', "Courier New", monospace;
    line-height: 1.0;
    /* MUST fill 4:3 CRT screen exactly */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden !important;
    contain: strict;
  }

  /* Mobile adjustments */
  @media (max-width: 768px) {
    #xterm-container {
      /* Same sizing on mobile */
    }
  }

  .xterm {
    cursor: text;
    width: 100%;
    height: 100%;
    /* CRITICAL: Force container to respect xterm.js fontSize setting */
    font-size: inherit !important;
    /* Font rendering optimizations for crisp monospace */
    font-variant-ligatures: none !important; /* Disable ligatures */
    font-variant-numeric: tabular-nums !important; /* Force tabular numbers */
    font-feature-settings: "liga" 0, "clig" 0, "kern" 0, "calt" 0 !important; /* Disable all ligatures, kerning, contextual alternates */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeSpeed; /* Changed from optimizeLegibility for strict grid */
    letter-spacing: 0 !important;
    font-kerning: none !important;
    word-spacing: 0 !important;
  }

  /* Force uniform character spacing on all xterm text elements */
  .xterm .xterm-rows,
  .xterm .xterm-rows > div {
    font-variant-ligatures: none !important;
    font-feature-settings: "liga" 0, "clig" 0, "kern" 0, "calt" 0 !important;
    font-kerning: none !important;
    letter-spacing: 0 !important;
  }

  /* CRITICAL: Fix 'f' character gap - Firefox 130 ligature bug */
  /* https://github.com/xtermjs/xterm.js/discussions/5155 */
  .xterm-width-cache-measure-container {
    font-variant-ligatures: none !important;
    font-feature-settings: "liga" 0, "clig" 0, "kern" 0, "calt" 0 !important;
  }

  .xterm-screen {
    overflow: hidden !important;
  }

  .xterm-viewport {
    overflow-y: hidden !important;
    overflow-x: hidden !important;
    overflow: hidden !important;
  }

  /* Disable scrollbar in xterm */
  .xterm-viewport::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
  }

  /* Subtle CRT Scan Lines (4px pattern, reduced opacity) */
  #xterm-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background: linear-gradient(
      to bottom,
      rgba(18, 16, 16, 0) 50%,
      rgba(0, 0, 0, 0.15) 50%
    );
    background-size: 100% 4px;
    z-index: 20;
    mix-blend-mode: multiply;
  }

  /* RGB color separation on text (chromatic aberration) */
  .xterm-row {
    animation: rgb-shift 0.3s infinite;
  }

  @keyframes rgb-shift {
    0%, 100% {
      text-shadow:
        0.05em 0 0 #ff0080,
        -0.025em -0.03em 0 #0080ff,
        0 0 4px var(--crt-glow-color),
        0 0 12px calc(var(--crt-glow-color) * var(--crt-glow-intensity));
    }
    50% {
      text-shadow:
        -0.05em 0 0 #0080ff,
        0.025em 0.03em 0 #ff0080,
        0 0 4px var(--crt-glow-color),
        0 0 12px calc(var(--crt-glow-color) * var(--crt-glow-intensity));
    }
  }

  /* Intense phosphor glow on green text */
  .xterm .xterm-fg-2 {
    color: var(--crt-foreground);
    text-shadow:
      0 0 4px var(--crt-glow-color),
      0 0 10px calc(var(--crt-glow-color) * 0.75),
      0 0 18px calc(var(--crt-glow-color) * 0.5);
  }

  /* CRT Pixel Grid Overlay - Non-square pixels (taller than wide) */
  #xterm-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background-image:
      radial-gradient(ellipse 1px 1.35px, rgba(0, 0, 0, 0.08) 60%, transparent 70%);
    background-size: 2.5px 3.4px; /* Non-square: 1:1.35 pixel aspect ratio */
    background-position: 0 0;
    z-index: 19;
    mix-blend-mode: overlay;
  }

  /* Animated Electron Beam - CRT scan effect */
  #xterm-container .crt-beam {
    position: absolute;
    width: 100%;
    height: 120px;
    top: -120px;
    left: 0;
    pointer-events: none;
    background: linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0.04) 50%,
      rgba(255, 255, 255, 0) 100%
    );
    z-index: 21;
    animation: crt-scan 16s linear infinite;
  }

  @keyframes crt-scan {
    0% { top: -120px; }
    100% { top: 100%; }
  }


  /* CRT Monitor Frame - 4:3 Aspect Ratio */
  .crt-monitor {
    width: 95vw;
    max-width: 1000px;
    background: #2a2a2a;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    padding: 20px;
    position: relative;
    margin: auto;
    /* Enable GPU acceleration for smooth transitions */
    will-change: transform;
    transform: translateZ(0);
  }

  /* Responsive scaling for mobile */
  @media (max-width: 768px) {
    .crt-monitor {
      width: 98vw;
      padding: 15px;
      transform: scale(var(--mobile-scale)) translateZ(0);
    }
  }

  @media (max-width: 480px) {
    .crt-monitor {
      width: 100vw;
      padding: 10px;
      border-radius: 10px;
    }
  }

  .crt-bezel {
    background: #1a1a1a;
    border-radius: 15px;
    padding: 15px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
  }

  @media (max-width: 768px) {
    .crt-bezel {
      padding: 10px;
    }
  }

  .crt-screen {
    background: #000;
    border-radius: 10px;
    overflow: hidden !important;
    box-shadow:
      0 0 20px calc(var(--crt-glow-color) * 0.1),
      inset 0 0 60px rgba(0, 0, 0, 0.3);
    position: relative;
    clip-path: inset(0);
    /* Force 4:3 aspect ratio - MUST be exactly 4:3 */
    aspect-ratio: 4 / 3;
    width: 100%;
  }

  /* CRT barrel distortion (subtle darkening at edges) */
  .crt-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center,
      transparent 0%,
      transparent 50%,
      rgba(0, 0, 0, 0.05) 80%,
      rgba(0, 0, 0, 0.15) 100%
    );
    pointer-events: none;
    z-index: 10;
  }

  /* CRT glare/reflection overlay */
  .crt-screen::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
      120deg,
      transparent 20%,
      rgba(255, 255, 255, 0.03) 30%,
      rgba(255, 255, 255, 0.08) 35%,
      rgba(255, 255, 255, 0.03) 40%,
      transparent 50%
    );
    transform: rotate(-15deg);
    pointer-events: none;
    z-index: 11;
  }

  .crt-power-light {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #333;
    transition: all 0.3s;
  }

  .crt-power-light.active {
    background: #ff6600;
    box-shadow: 0 0 10px #ff6600, 0 0 20px #ff6600;
  }

  /* Modem Panel */
  .modem-panel {
    margin-top: 15px;
    background: #1a1a1a;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px;
  }

  @media (max-width: 768px) {
    .modem-panel {
      margin-top: 10px;
      padding: 10px;
    }
  }

  /* Modem display - hidden (CRT sits directly on modem) */
  .modem-display {
    display: none !important;
  }

  /* Legacy CSS - kept for future reference
  .modem-display {
    min-height: 50px;
    background: #000;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 8px;
    margin-bottom: 12px;
    font-family: "Courier New", monospace;
    font-size: 11px;
    color: #00ff00;
    line-height: 1.4;
  }

  @media (max-width: 768px) {
    .modem-display {
      min-height: 40px;
      padding: 6px;
      margin-bottom: 8px;
      font-size: 10px;
    }
  }
  */

  .modem-line {
    margin: 2px 0;
  }

  /* Modem Indicator Lights */
  .modem-lights {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 15px;
  }

  .modem-light {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
  }

  .light-led {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #333;
    transition: all 0.2s;
  }

  .light-led.red.active {
    background: #ff3333;
    box-shadow: 0 0 10px #ff3333, 0 0 20px #ff3333;
  }

  .light-led.amber.active {
    background: #ffaa00;
    box-shadow: 0 0 10px #ffaa00, 0 0 20px #ffaa00;
  }

  .light-led.green.active {
    background: #33ff33;
    box-shadow: 0 0 10px #33ff33, 0 0 20px #33ff33;
  }

  .light-label {
    font-family: "Courier New", monospace;
    font-size: 9px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  @media (max-width: 768px) {
    .modem-light {
      gap: 3px;
    }
    .light-led {
      width: 10px;
      height: 10px;
    }
    .light-label {
      font-size: 8px;
    }
  }

  .game-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: none; /* Hidden for now */
    gap: 10px;
    z-index: 1000;
  }
  
  .game-button {
    background: rgba(98, 241, 255, 0.9);
    color: #0a1822;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
  }
  
  .game-button:hover {
    background: #62f1ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(98, 241, 255, 0.4);
  }
  
  .game-button.secondary {
    background: rgba(30, 30, 40, 0.9);
    color: #62f1ff;
    border: 1px solid rgba(98, 241, 255, 0.3);
  }
  
  .game-button.secondary:hover {
    background: rgba(50, 50, 60, 0.9);
    border-color: #62f1ff;
  }

  /* CRT Brand Badge */
  .crt-brand-badge {
    position: absolute;
    bottom: 5px;
    right: 25px;
    font-family: "Arial", sans-serif;
    font-size: 9px;
    font-weight: 600;
    color: #555;
    letter-spacing: 2px;
    text-transform: uppercase;
    opacity: 0.7;
    text-shadow: 0 1px 0 #000, 0 -1px 0 #444;
    z-index: 10;
  }

  /* Modem Faceplate Layout */
  .modem-faceplate {
    display: flex;
    align-items: center;
    gap: 15px;
    background: linear-gradient(to bottom, #2a2a2a 0%, #1a1a1a 100%);
    border-radius: 4px;
    padding: 10px 15px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  }

  @media (max-width: 768px) {
    .modem-faceplate {
      flex-wrap: wrap;
      gap: 10px;
      padding: 8px 12px;
    }
  }

  /* Modem Brand Section */
  .modem-brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 20px;
    border-right: 1px solid #333;
    min-width: 120px;
  }

  .brand-logo {
    font-family: "Arial", sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #999;
    text-transform: uppercase;
    text-shadow:
      0 1px 0 #000,
      0 -1px 0 #444,
      1px 0 0 #444,
      -1px 0 0 #000;
  }

  .speed-indicator {
    font-family: "Courier New", monospace;
    font-size: 10px;
    color: #666;
    letter-spacing: 1px;
    font-weight: 600;
  }

  /* Update modem lights for horizontal layout */
  .modem-lights {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 18px;
    flex: 1;
  }

  /* Volume Knob */
  .volume-knob-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-left: 20px;
  }

  .volume-knob-dial {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #444, #222);
    border: 2px solid #333;
    box-shadow:
      inset 0 0 5px rgba(0, 0, 0, 0.5),
      0 2px 5px rgba(0, 0, 0, 0.3);
    position: relative;
    cursor: pointer;
    user-select: none;
    transform: rotate(0deg); /* Start at half volume */
    transition: transform 0.05s ease-out;
  }

  .volume-knob-dial:active {
    transform: scale(0.98);
  }

  .volume-knob-indicator {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 12px;
    background: #ff6600;
    border-radius: 2px;
    box-shadow: 0 0 4px #ff6600;
  }

  .volume-knob-label {
    font-family: "Courier New", monospace;
    font-size: 9px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  /* Speaker Button - Period-Accurate Modem Control */
  .spkr-button-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-left: 20px;
  }

  .spkr-button {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    background: #2a2a2a;
    border: 2px solid #444;
    box-shadow:
      inset 0 2px 4px rgba(0, 0, 0, 0.5),
      0 1px 3px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .spkr-button:hover {
    background: #333;
    border-color: #555;
  }

  .spkr-button:active {
    transform: scale(0.95);
    box-shadow:
      inset 0 3px 6px rgba(0, 0, 0, 0.6),
      inset 0 -1px 2px rgba(255, 255, 255, 0.1);
  }

  .spkr-button-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #444;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
    transition: all 0.2s;
  }

  .spkr-button.active .spkr-button-light {
    background: #00ff00;
    box-shadow: 0 0 8px #00ff00, inset 0 1px 2px rgba(0, 0, 0, 0.4);
  }

  .spkr-button-label {
    font-family: "Courier New", monospace;
    font-size: 9px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  @media (max-width: 768px) {
    .modem-lights {
      gap: 10px;
    }
    .modem-brand {
      min-width: 90px;
      font-size: 11px;
    }
    .brand-logo {
      font-size: 11px;
    }
    .volume-knob-container {
      margin-left: 10px;
    }
    .volume-knob-dial {
      width: 35px;
      height: 35px;
    }
    .volume-knob-indicator {
      height: 10px;
    }
    .volume-knob-label {
      font-size: 8px;
    }
    .spkr-button-container {
      margin-left: 10px;
    }
    .spkr-button {
      width: 35px;
      height: 35px;
    }
    .spkr-button-light {
      width: 8px;
      height: 8px;
    }
    .spkr-button-label {
      font-size: 8px;
    }
    .speed-indicator {
      font-size: 9px;
    }
  }
