:root {
  --phosphor: #6cff6c;
  --phosphor-dim: #2a7a2a;
  --bg: #050a05;
  --warn: #ffb84d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #000;
  color: var(--phosphor);
  font-family: "Menlo", "Monaco", "Courier New", monospace;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 28px);
  padding: clamp(8px, 2vw, 24px);
  min-height: 100vh;
}

.crt {
  position: relative;
  padding: clamp(12px, 3vw, 32px) clamp(16px, 4vw, 48px);
  background: var(--bg);
  border-radius: 16px;
  box-shadow:
    0 0 60px rgba(108, 255, 108, 0.15),
    inset 0 0 80px rgba(108, 255, 108, 0.05);
  max-width: 100%;
}

.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.25) 2px,
    rgba(0, 0, 0, 0.25) 3px
  );
  border-radius: 16px;
  mix-blend-mode: multiply;
}

#scene {
  margin: 0;
  /* Scale by whichever dimension is more constraining: 3.4vw for width-bound
     portrait phones, 3.5vh for height-bound landscape phones. */
  font-size: clamp(6px, min(3.4vw, 2.6vh), 16px);
  line-height: 1.0;
  letter-spacing: 0.02em;
  white-space: pre;
  color: var(--phosphor);
  text-shadow:
    0 0 4px rgba(108, 255, 108, 0.6),
    0 0 12px rgba(108, 255, 108, 0.25);
}

#scene .key-hit {
  background: var(--phosphor);
  color: var(--bg);
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.97; }
}

.crt { animation: flicker 4s infinite; }

/* ============ On-screen ASCII controls ============ */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 4vw, 24px);
  font-family: "Menlo", "Monaco", "Courier New", monospace;
}

.controls button {
  font-family: inherit;
  font-size: clamp(28px, 9vw, 44px);
  font-weight: bold;
  line-height: 1;
  background: transparent;
  color: var(--phosphor);
  border: none;
  padding: 8px 14px;
  margin: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  text-shadow:
    0 0 4px rgba(108, 255, 108, 0.6),
    0 0 12px rgba(108, 255, 108, 0.25);
}

.controls button:active {
  color: var(--bg);
  background: var(--phosphor);
  text-shadow: none;
}

#btn-y {
  font-size: clamp(36px, 12vw, 56px);
  padding: 6px 18px;
}

/* Hide on viewports wide enough that there's almost certainly a keyboard.
   Touch devices (phones, tablets) keep the buttons. */
@media (min-width: 1024px) {
  .controls { display: none; }
}

/* On non-desktop viewports (phones + tablets), pin the controls to the
   bottom edge and reserve space at the bottom of the body so they don't
   cover the CRT. Threshold matches the desktop-hide cutoff above. */
@media (max-width: 1023px) {
  body {
    justify-content: center;
    padding-top: clamp(8px, 3vw, 24px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(80px, 22vw, 120px));
  }
  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: clamp(8px, 2vw, 14px) clamp(8px, 4vw, 24px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(8px, 2vw, 14px));
    background: linear-gradient(to top, rgba(0,0,0,0.92), rgba(0,0,0,0));
    z-index: 10;
  }
}
