/* ========================================
   CF3 Terminal Theme
   ======================================== */

:root {
  --color-bg: #010302;
  --color-bg-alt: #04110a;
  --color-grid: rgba(57, 255, 20, 0.04);
  --color-grid-accent: rgba(57, 255, 20, 0.16);
  --color-text: #39ff14;
  --color-text-muted: #1ecb6f;
  --color-accent-primary: #24ff72;
  --color-accent-secondary: #19e68c;
  --color-danger: #ff3b58;
  --font-primary: 'VT323', 'IBM Plex Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --glow: 0 0 12px rgba(57, 255, 20, 0.42);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.85);
  --mobile-keyboard-height: calc(215px + 1em);
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  font-family: var(--font-primary);
  font-size: 18px;
  line-height: 1.35;
  color: var(--color-text);
  background:
    radial-gradient(1200px 680px at 72% -10%, rgba(32, 120, 60, 0.35) 0%, rgba(1, 4, 3, 0.9) 60%),
    radial-gradient(900px 600px at 18% 120%, rgba(12, 63, 39, 0.4) 0%, rgba(0, 0, 0, 0) 78%),
    linear-gradient(135deg, #021008 0%, #040806 45%, #010302 100%);
  text-shadow: var(--glow);
}

a {
  color: var(--color-accent-primary);
  text-decoration: none;
  border-bottom: 1px dotted rgba(36, 255, 114, 0.5);
  transition: color 120ms ease, border-color 120ms ease;
}

a:hover {
  color: #7dffb7;
  border-bottom-color: rgba(101, 255, 170, 0.85);
}

#terminal {
  width: min(1000px, 96vw);
  height: min(680px, 92vh);
  overflow: hidden;
  padding: 18px 20px 24px;
  border-radius: 14px;
  border: 1px solid var(--color-grid-accent);
  background:
    radial-gradient(130% 100% at 50% 0%, rgba(32, 120, 60, 0.18), rgba(1, 6, 4, 0.92)),
    linear-gradient(180deg, rgba(4, 20, 12, 0.96), rgba(0, 2, 1, 0.96)),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0) 0 1px, rgba(57, 255, 20, 0.08) 1px 2px);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(36, 255, 114, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  isolation: isolate;
  min-height: 0;
}

#terminal::before,
#terminal::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

#terminal::before {
  background: repeating-linear-gradient(180deg, rgba(36, 255, 114, 0.04) 0, rgba(36, 255, 114, 0.04) 1px, transparent 1px, transparent 3px);
  opacity: 0.35;
  mix-blend-mode: screen;
}

#terminal::after {
  background: radial-gradient(120% 120% at 50% 50%, rgba(57, 255, 20, 0.12), transparent 55%);
  mix-blend-mode: color-dodge;
  opacity: 0.85;
}

#terminal > * {
  position: relative;
  z-index: 1;
}

#terminal-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

#terminal-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 12px;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(57, 255, 20, 0.35) transparent;
  scroll-behavior: smooth;
  min-height: 0;
}

#terminal-log::-webkit-scrollbar {
  width: 6px;
}

#terminal-log::-webkit-scrollbar-track {
  background: transparent;
}

#terminal-log::-webkit-scrollbar-thumb {
  background: rgba(57, 255, 20, 0.3);
  border-radius: 12px;
}

#terminal-log::-webkit-scrollbar-thumb:hover {
  background: rgba(57, 255, 20, 0.45);
}

pre,
code {
  font-family: var(--font-primary);
}

.prompt {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5ch;
  line-height: 1;
}

.prompt-user {
  color: #f4f6f5;
  line-height: 1;
}

.prompt-path {
  color: var(--color-accent-secondary);
}

.command {
  flex: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  white-space: pre;
  min-height: 1em;
}

.command-text {
  white-space: pre;
  line-height: 1;
  min-height: 1em;
  display: inline-block;
}

.output {
  color: var(--color-text);
  white-space: pre-wrap;
}

.header-message {
  color: var(--color-text);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  text-shadow: var(--glow);
  margin-top: 0.25rem;
}

.fullscreen-hint {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.25);
  margin-top: 0.5rem;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.output p {
  margin: 0 0 1.1em;
  line-height: 1.35;
}

.output p:last-child {
  margin-bottom: 0;
}

pre.output {
  font-family: 'IBM Plex Mono', 'Cascadia Mono', 'Fira Code', monospace;
  font-size: 0.98em;
  line-height: 1;
  letter-spacing: 0;
  margin: 0;
  text-shadow: none;
}

.output.ascii-art {
  font-family: 'IBM Plex Mono', 'Cascadia Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 1.08em;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #6aff47;
  text-shadow: 0 0 16px rgba(57, 255, 20, 0.58);
  white-space: pre;
  overflow-x: auto;
}

.output.ascii-art + .output {
  margin-top: 0.5rem;
}

.cursor {
  display: inline-block;
  width: 1ch;
  height: 1.1em;
  background-color: var(--color-text);
  animation: blink 1s steps(2, start) infinite;
  border-radius: 1px;
  box-shadow: 0 0 6px rgba(57, 255, 20, 0.45);
  align-self: flex-end;
  margin-left: 0.1ch;
}

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

.game-selection {
  margin-top: 0.5rem;
}

.game-list {
  list-style: none;
  padding: 0;
}

.game-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.6rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  transition: color 120ms ease;
}

.game-list-item .selector {
  width: 18px;
  height: 18px;
  opacity: 0;
  color: var(--color-accent-secondary);
}

.game-list-item.selected {
  color: var(--color-text);
}

.game-list-item.selected .selector {
  opacity: 1;
}

.nav-arrows {
  margin-top: 1rem;
  color: var(--color-accent-secondary);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-arrow {
  font-size: 1.8rem;
  cursor: pointer;
  display: inline-block;
  user-select: none;
  transition: color 120ms ease, transform 120ms ease;
}

.nav-arrow:hover {
  color: var(--color-text);
  transform: scale(1.1);
}

.nav-arrow:active {
  transform: scale(0.95);
}

.play-game-btn {
  appearance: none;
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.15), rgba(25, 230, 140, 0.15));
  border: 2px solid var(--color-accent-primary);
  border-radius: 6px;
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 1.3rem;
  font-weight: bold;
  padding: 0.5rem 1.5rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  transition: all 150ms ease;
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.3);
  margin-left: auto;
}

.play-game-btn:hover {
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.25), rgba(25, 230, 140, 0.25));
  border-color: var(--color-text);
  box-shadow: 0 0 25px rgba(57, 255, 20, 0.6);
  transform: translateY(-2px);
}

.play-game-btn:active {
  transform: translateY(0);
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.4);
}

#tictactoe-board {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 8px;
}

.cell {
  width: 80px;
  height: 80px;
  border: 2px solid rgba(204, 255, 217, 0.35);
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.2rem;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.cell:hover {
  background-color: rgba(20, 40, 32, 0.65);
  border-color: rgba(204, 255, 217, 0.8);
}

.cell:active {
  transform: translateZ(0);
}

.ascii-map {
  font-size: 14px;
  line-height: 1.15;
  white-space: pre;
  color: var(--color-text);
  margin-top: 1rem;
}

.hud {
  color: var(--color-text-muted);
  font-size: 0.9em;
}

.warn {
  color: var(--color-accent-secondary);
}

.bad {
  color: var(--color-danger);
}

.game-of-life-container {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.game-of-life-status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--color-text);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  text-shadow: 0 0 12px rgba(57, 255, 20, 0.35);
}

.game-of-life-status span {
  color: var(--color-text-muted);
  font-size: 0.92rem;
}

.game-of-life-board {
  margin: 0;
  padding: 16px 18px;
  border: 1px solid rgba(57, 255, 20, 0.25);
  border-radius: 12px;
  background: rgba(5, 20, 11, 0.75);
  font-size: 0.85rem;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: none;
  box-shadow: inset 0 0 18px rgba(57, 255, 20, 0.12);
}

.snake-container {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.snake-status {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--color-text);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  text-shadow: 0 0 12px rgba(57, 255, 20, 0.35);
}

.snake-status span {
  color: var(--color-text-muted);
  font-size: 0.92rem;
}

#snake-board {
  display: grid;
  grid-template-columns: repeat(24, 18px);
  grid-auto-rows: 18px;
  gap: 2px;
  align-self: center;
  padding: 16px;
  border-radius: 12px;
  background: rgba(5, 20, 11, 0.82);
  border: 1px solid rgba(57, 255, 20, 0.25);
  box-shadow: inset 0 0 18px rgba(57, 255, 20, 0.12);
}

.snake-cell {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: rgba(20, 45, 28, 0.28);
  transition: background 80ms ease, box-shadow 120ms ease;
}

.snake-cell.snake {
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.85), rgba(12, 120, 45, 0.85));
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.5);
}

.snake-cell.head {
  background: linear-gradient(135deg, rgba(140, 255, 120, 0.9), rgba(32, 150, 60, 0.9));
  box-shadow: 0 0 14px rgba(140, 255, 120, 0.7);
}

.snake-cell.food {
  background: radial-gradient(circle at 50% 50%, rgba(255, 94, 98, 0.95), rgba(120, 12, 32, 0.8));
  box-shadow: 0 0 12px rgba(255, 94, 98, 0.6);
}

.snake-gameover {
  margin-top: 1.25rem;
  padding: 1.25rem;
  border-radius: 12px;
  border: 1px solid rgba(57, 255, 20, 0.22);
  background: rgba(5, 20, 11, 0.78);
  box-shadow: inset 0 0 18px rgba(57, 255, 20, 0.14);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.snake-gameover h3 {
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text);
}

.snake-gameover-copy {
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

.snake-final-score {
  font-size: 1rem;
}

.snake-final-score strong {
  color: var(--color-accent-primary);
}

.snake-score-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.snake-score-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  flex: 1;
  min-width: 180px;
}

.snake-score-label span {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.snake-score-label input {
  appearance: none;
  background: rgba(9, 36, 21, 0.92);
  border: 1px solid rgba(57, 255, 20, 0.3);
  border-radius: 8px;
  color: var(--color-text);
  padding: 0.6rem 0.75rem;
  font-family: var(--font-primary);
  font-size: 1rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.snake-score-label input:focus {
  outline: none;
  border-color: rgba(57, 255, 20, 0.6);
  box-shadow: 0 0 12px rgba(57, 255, 20, 0.35);
}

.snake-score-label input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.snake-save-btn {
  appearance: none;
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.18), rgba(25, 230, 140, 0.18));
  border: 1px solid rgba(36, 255, 114, 0.55);
  border-radius: 8px;
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  padding: 0.6rem 1.1rem;
  text-transform: uppercase;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.snake-save-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--color-text);
  box-shadow: 0 0 16px rgba(57, 255, 20, 0.35);
}

.snake-save-btn:active:not(:disabled) {
  transform: translateY(0);
}

.snake-save-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.snake-leaderboard {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.snake-leaderboard h4 {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  color: var(--color-text);
}

.snake-leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.snake-leaderboard-entry {
  display: grid;
  grid-template-columns: 0.5fr 1fr auto;
  gap: 0.5rem;
  align-items: center;
  background: rgba(20, 45, 28, 0.35);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

.snake-leaderboard-entry .rank {
  color: var(--color-text-muted);
}

.snake-leaderboard-entry .name {
  color: var(--color-text);
}

.snake-leaderboard-entry .score {
  font-weight: bold;
  color: var(--color-accent-primary);
  justify-self: end;
}

.snake-leaderboard-entry.recent {
  background: rgba(57, 255, 20, 0.28);
  box-shadow: 0 0 16px rgba(57, 255, 20, 0.28);
}

.snake-leaderboard-empty {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

.snake-score-actions {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.snake-score-actions button {
  appearance: none;
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.15), rgba(25, 230, 140, 0.15));
  border: 1px solid rgba(57, 255, 20, 0.4);
  border-radius: 8px;
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  padding: 0.6rem 1.4rem;
  text-transform: uppercase;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.snake-score-actions button:hover {
  transform: translateY(-1px);
  border-color: var(--color-text);
  box-shadow: 0 0 16px rgba(57, 255, 20, 0.35);
}

.snake-score-actions button:active {
  transform: translateY(0);
}

.snake-score-actions button:last-child {
  background: linear-gradient(135deg, rgba(255, 59, 88, 0.15), rgba(255, 130, 150, 0.15));
  border-color: rgba(255, 59, 88, 0.4);
}

.snake-score-actions button:last-child:hover {
  box-shadow: 0 0 16px rgba(255, 59, 88, 0.32);
}

.snake-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
  padding: 0 1rem;
}

.snake-btn {
  appearance: none;
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.18), rgba(25, 230, 140, 0.18));
  border: 2px solid var(--color-accent-primary);
  border-radius: 12px;
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 1.4rem;
  font-weight: bold;
  padding: 1.2rem 2rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  transition: all 120ms ease;
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.3);
  flex: 1;
  max-width: 200px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.snake-btn:active {
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.35), rgba(25, 230, 140, 0.35));
  border-color: var(--color-text);
  box-shadow: 0 0 25px rgba(57, 255, 20, 0.6);
  transform: scale(0.96);
}

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

#terminal::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

#terminal::-webkit-scrollbar-thumb {
  background: rgba(204, 255, 217, 0.2);
  border-radius: 6px;
}

#terminal::-webkit-scrollbar-thumb:hover {
  background: rgba(204, 255, 217, 0.35);
}

@media (max-width: 768px) {
  body {
    font-size: 16px;
    padding: 12px;
  }

  #terminal {
    width: 100%;
    height: calc(100vh - 24px);
    padding: 16px;
  }

  #tictactoe-board {
    grid-template-columns: repeat(3, 70px);
    gap: 6px;
  }

  .cell {
    width: 70px;
    height: 70px;
    font-size: 2rem;
  }

  .nav-arrows {
    display: block;
  }
}

@media (max-width: 520px) {
  body {
    padding: 8px;
  }

  #terminal {
    padding: 14px;
  }

  .prompt {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .cursor {
    width: 0.6rem;
    height: 1rem;
  }

  .game-list-item {
    font-size: 1.3rem;
  }

  body.keyboard-open {
    padding: 0;
    padding-top: 6px;
  }

  body.keyboard-open #terminal {
    padding: 12px;
    border-radius: 12px;
  }

  #snake-board {
    grid-template-columns: repeat(24, 12px);
    grid-auto-rows: 12px;
    gap: 1px;
    padding: 10px;
  }

  .snake-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
  }

  .snake-btn {
    font-size: 1.2rem;
    padding: 1rem 1.5rem;
  }
}

.output {
  color: var(--color-text);
  white-space: pre-wrap;
}

pre.output {
  font-family: 'IBM Plex Mono', 'Cascadia Mono', 'Fira Code', monospace;
  font-size: 0.98em;
  line-height: 1;
  letter-spacing: 0;
  margin: 0;
  text-shadow: none;
}

.output.ascii-art {
  font-family: 'IBM Plex Mono', 'Cascadia Mono', 'Fira Code', monospace;
  font-size: 1.08em;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #6aff47;
  text-shadow: 0 0 16px rgba(57, 255, 20, 0.58);
  margin-bottom: 0.5rem;
}

.output.adventure-ascii {
  font-family: 'IBM Plex Mono', 'Cascadia Mono', 'Fira Code', monospace;
  font-size: 0.9em;
  line-height: 1.1;
  color: #7cff4f;
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.4);
  margin: 0.75rem 0 0.25rem;
  white-space: pre;
}

.adventure-video {
  margin-top: 1.5rem;
  width: 100%;
  display: flex;
  justify-content: center;
}

.adventure-video .video-frame {
  position: relative;
  width: min(560px, 100%);
  padding-bottom: 56.25%;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45);
}

.adventure-video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.mobile-keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  background: rgba(5, 20, 11, 0.96);
  border-top: 1px solid rgba(57, 255, 20, 0.35);
  border-radius: 12px 12px 0 0;
  padding: 0.8rem 0.65rem calc(0.8rem + env(safe-area-inset-bottom));
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  transform: translateY(100%);
  transition: transform 160ms ease;
  z-index: 1000;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.6);
}

.mobile-keyboard.hidden {
  display: none;
}

body.keyboard-open .mobile-keyboard {
  transform: translateY(0);
}

body.keyboard-open {
  padding: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
}

body.keyboard-open #terminal {
  height: calc(100vh - var(--mobile-keyboard-height) - 16px);
  max-height: calc(100vh - var(--mobile-keyboard-height) - 16px);
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}

body.keyboard-open #terminal-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  max-height: 100%;
  padding-bottom: 6rem;
  overscroll-behavior: contain;
  scroll-padding-bottom: 6rem;
}

.mobile-key-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
}

.mobile-key {
  flex: 1;
  appearance: none;
  border: 1px solid rgba(57, 255, 20, 0.35);
  border-radius: 6px;
  background: rgba(9, 36, 21, 0.95);
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 1.05rem;
  text-transform: uppercase;
  padding: 0.55rem 0.6rem;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.mobile-key:active {
  transform: scale(0.94);
  box-shadow: 0 0 12px rgba(140, 255, 120, 0.3);
}

.mobile-key-row:last-child .mobile-key:first-child {
  flex: 3;
}

.mobile-key-row:last-child .mobile-key:nth-child(2),
.mobile-key-row:last-child .mobile-key:nth-child(3) {
  flex: 1.5;
}

@media (hover: hover) {
  .mobile-key:hover {
    border-color: rgba(140, 255, 120, 0.55);
    box-shadow: 0 0 12px rgba(140, 255, 120, 0.35);
  }
}

@media (max-width: 640px) {
  .output.ascii-art {
    font-size: 0.75em;
    line-height: 1;
    letter-spacing: -0.02em;
    margin-bottom: 0.75rem;
  }

  #terminal-header .ascii-art {
    font-size: 0.68em;
    line-height: 1;
    letter-spacing: -0.02em;
  }

  body.keyboard-open #terminal-header {
    gap: 0.4rem;
  }

  body.keyboard-open #terminal-header .ascii-art {
    font-size: 0.6em;
    line-height: 1;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
  }
}

@media (max-width: 400px) {
  #terminal-header .ascii-art {
    font-size: 0.6em;
  }

  body.keyboard-open #terminal-header .ascii-art {
    font-size: 0.55em;
  }

  #snake-board {
    grid-template-columns: repeat(24, 10px);
    grid-auto-rows: 10px;
    gap: 1px;
    padding: 8px;
  }

  .snake-cell {
    width: 10px;
    height: 10px;
  }

  .snake-btn {
    font-size: 1rem;
    padding: 0.9rem 1.2rem;
  }
}
.terminal-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  border: 0;
  padding: 0;
  pointer-events: none;
  resize: none;
  background: transparent;
}

/* Global Thermonuclear War Styles */

.war-target-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 1rem 0;
}

.war-target-item {
  font-size: 0.95rem;
  color: var(--color-text);
  padding: 0.25rem 0;
}

@media (max-width: 768px) {
  .war-target-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Two-column simulation layout */
.war-simulation-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  height: 100%;
  min-height: 0;
}

.war-events-column {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  padding-right: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(57, 255, 20, 0.35) transparent;
}

.war-events-column::-webkit-scrollbar {
  width: 4px;
}

.war-events-column::-webkit-scrollbar-thumb {
  background: rgba(57, 255, 20, 0.3);
  border-radius: 4px;
}

.war-map-column {
  position: sticky;
  top: 0;
  height: fit-content;
  max-height: 100%;
  overflow: hidden;
}

.war-map {
  font-family: 'IBM Plex Mono', 'Cascadia Mono', 'Courier New', monospace;
  font-size: 0.65rem;
  line-height: 1.15;
  letter-spacing: 0;
  color: var(--color-accent-secondary);
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.35);
  background: rgba(5, 20, 11, 0.7);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid rgba(57, 255, 20, 0.25);
  box-shadow: inset 0 0 15px rgba(57, 255, 20, 0.1);
  white-space: pre;
  overflow-x: auto;
}

@media (max-width: 768px) {
  .war-simulation-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .war-map-column {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 220px;
    z-index: 1000;
    background: var(--color-bg);
    border-top: 1px solid rgba(57, 255, 20, 0.25);
    padding: 0.5rem;
    max-height: 220px;
    overflow-y: auto;
  }

  .war-map {
    font-size: 0.45rem;
    padding: 0.5rem;
    line-height: 1.1;
  }

  .war-events-column {
    padding-bottom: 230px;
  }
}

@media (max-width: 520px) {
  .war-map {
    font-size: 0.38rem;
    padding: 0.4rem;
  }
}

/* City markers with colors */
.city-active {
  color: var(--color-accent-secondary);
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.6);
  font-weight: bold;
}

.city-destroyed {
  color: var(--color-danger);
  text-shadow: 0 0 12px rgba(255, 59, 88, 0.8);
  font-weight: bold;
  animation: pulse-red 1.5s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}

.war-missile {
  color: var(--color-accent-primary);
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.55);
  animation: war-missile-pulse 0.3s linear infinite alternate;
}

.war-impact {
  color: var(--color-danger);
  text-shadow: 0 0 18px rgba(255, 59, 88, 0.85);
  animation: war-impact-flash 0.35s ease-in-out 3;
}

@keyframes war-missile-pulse {
  0% { opacity: 0.55; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1.05); }
}

@keyframes war-impact-flash {
  0%, 100% { opacity: 0.6; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.4); }
}

/* Next Turn Button */
.war-next-turn-container {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  padding: 1rem 0;
}

.war-next-turn-button {
  appearance: none;
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.15), rgba(25, 230, 140, 0.15));
  border: 2px solid var(--color-accent-primary);
  border-radius: 6px;
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 1.2rem;
  font-weight: bold;
  padding: 0.8rem 2rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: all 150ms ease;
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.3);
}

.war-next-turn-button:hover {
  background: linear-gradient(135deg, rgba(57, 255, 20, 0.25), rgba(25, 230, 140, 0.25));
  border-color: var(--color-text);
  box-shadow: 0 0 25px rgba(57, 255, 20, 0.6);
  transform: translateY(-2px);
}

.war-next-turn-button:active {
  transform: translateY(0);
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.4);
}
