.terminal-game[hidden] { display: none !important; }

.terminal-game {
  width: min(1080px, calc(100vw - 96px));
  height: min(680px, calc(100dvh - 96px));
  min-height: 0;
  margin: 24px auto;
  border: 1px solid #393939;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  overflow: hidden;
  background: #090909;
  color: #f4f4ef;
  font-family: Consolas, "Courier New", monospace;
  box-shadow: 14px 14px 0 rgba(255, 15, 116, .18), -8px -8px 0 rgba(197, 255, 18, .05);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.terminal-game.is-running { border-color: #52524d; box-shadow: 14px 14px 0 rgba(255,15,116,.22), -8px -8px 0 rgba(197,255,18,.09); }
.terminal-game.is-skill { animation: runner-skill-frame 420ms steps(2, end); }
.terminal-game.is-impact { border-color: var(--pink); box-shadow: 18px 12px 0 rgba(255,15,116,.46), -10px -7px 0 rgba(197,255,18,.12); }
.terminal-game.is-complete { border-color: var(--acid); box-shadow: 18px 14px 0 rgba(197,255,18,.28), -10px -8px 0 rgba(255,15,116,.2); }

.runner-header {
  min-height: 72px;
  padding: 12px var(--pad);
  border-bottom: 1px solid #353535;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: clamp(18px, 4vw, 60px);
}

.runner-identity { min-width: 0; display: flex; align-items: baseline; gap: 18px; }
.runner-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(14px, 1.8vw, 24px); letter-spacing: 0; }
.runner-index { flex: 0 0 auto; color: var(--pink); font-size: 10px; }
.runner-score { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 9px; }
.runner-score b { color: var(--acid); font-size: 28px; line-height: 1; text-shadow: 0 0 18px rgba(197,255,18,.45); }
.runner-score span { color: #777; font-size: 9px; text-transform: uppercase; }
.runner-header-actions { display: flex; align-items: center; gap: 7px; direction: ltr; }

.runner-back,
.runner-sound,
.runner-start {
  min-height: 36px;
  padding: 9px 12px;
  border: 1px solid #555;
  border-radius: 0;
  background: transparent;
  color: #f4f4ef;
  cursor: pointer;
  font: 700 10px/1 Consolas, "Courier New", monospace;
  text-transform: uppercase;
}
.runner-back:hover,
.runner-back:focus-visible,
.runner-sound:hover,
.runner-sound:focus-visible,
.runner-start:hover,
.runner-start:focus-visible { border-color: var(--acid); color: var(--acid); outline: none; }
.runner-sound { position: relative; width: 36px; padding: 0; color: var(--acid); font-size: 17px; }
.runner-sound.is-muted { color: #666; border-color: #3c3c3c; }
.runner-sound.is-muted::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 1px;
  left: 8px;
  top: 17px;
  background: var(--pink);
  transform: rotate(-45deg);
}

.runner-stage { position: relative; min-height: 0; overflow: hidden; background: #090909; isolation: isolate; }
.runner-stage::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, rgba(255,255,255,.055) 4px);
  mix-blend-mode: screen;
}
.runner-stage::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  top: -4px;
  height: 2px;
  pointer-events: none;
  background: var(--acid);
  opacity: 0;
  box-shadow: 0 0 18px var(--acid);
}
.terminal-game.is-running .runner-stage::after { opacity: .35; animation: runner-scan 2.8s linear infinite; }
.runner-canvas { position: absolute; inset: 0; display: block; touch-action: manipulation; cursor: pointer; }
.runner-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

.runner-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(9, 9, 9, .72);
}
.runner-overlay[hidden] { display: none; }
.runner-overlay > span { margin-bottom: 22px; color: var(--pink); font-size: 11px; }
.runner-overlay strong { max-width: 920px; font-family: Arial, sans-serif; font-size: clamp(30px, 6vw, 88px); line-height: .94; letter-spacing: 0; text-wrap: balance; }
.runner-overlay p { max-width: 680px; margin: 22px 0 30px; color: #a1a19c; font-size: clamp(12px, 1.3vw, 16px); line-height: 1.6; }
.runner-start { min-width: 160px; border-color: var(--acid); background: var(--acid); color: #090909; }
.runner-start:hover,
.runner-start:focus-visible { background: transparent; }

.runner-footer {
  min-height: 118px;
  padding: 15px var(--pad) 18px;
  border-top: 1px solid #353535;
  display: grid;
  grid-template-columns: minmax(150px, .42fr) minmax(0, 1.4fr) auto;
  align-items: center;
  gap: clamp(26px, 6vw, 90px);
}
.runner-footer > p { color: #797974; font-size: 10px; line-height: 1.5; text-transform: uppercase; }
.runner-progress {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 4px;
  list-style: none;
}
.runner-progress li {
  min-width: 0;
  height: 38px;
  border-top: 3px solid #333;
  padding-top: 7px;
  overflow: hidden;
  color: #555;
  font-size: 8px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: uppercase;
  transition: color 180ms ease, border-color 180ms ease;
}
.runner-progress li.is-earned { border-color: var(--acid); color: var(--acid); animation: runner-earned 360ms cubic-bezier(.16,1,.3,1); }

.runner-controls { display: grid; grid-template-columns: repeat(3, 38px); gap: 5px; direction: ltr; }
.runner-controls button {
  width: 38px;
  height: 38px;
  border: 1px solid #555;
  border-radius: 0;
  background: transparent;
  color: #f4f4ef;
  cursor: pointer;
  font: 700 18px/1 Arial, sans-serif;
  touch-action: none;
}
.runner-controls button:hover,
.runner-controls button:focus-visible,
.runner-controls button:active { border-color: var(--acid); background: var(--acid); color: #090909; outline: none; }
.runner-controls .runner-jump { border-color: var(--pink); color: var(--pink); }

html[dir="rtl"] .terminal-game { direction: rtl; }
html[dir="rtl"] .runner-back { direction: ltr; }
html[lang="ar"] .runner-identity strong,
html[lang="ar"] .runner-score span,
html[lang="ar"] .runner-overlay strong,
html[lang="ar"] .runner-overlay p,
html[lang="ar"] .runner-footer > p,
html[lang="ar"] .runner-progress li { font-family: "IBM Plex Sans Arabic", Arial, sans-serif; }

@keyframes runner-scan {
  from { transform: translateY(0); }
  to { transform: translateY(560px); }
}

@keyframes runner-skill-frame {
  0% { transform: translate(0); }
  25% { transform: translate(5px, -2px); }
  50% { transform: translate(-4px, 2px); }
  75% { transform: translate(2px, 1px); }
  100% { transform: translate(0); }
}

@keyframes runner-earned {
  0% { transform: translateY(6px); filter: brightness(2); }
  100% { transform: translateY(0); filter: brightness(1); }
}

@media (max-width: 700px) {
  .terminal-game { width: calc(100% - 20px); height: min(620px, calc(100dvh - 70px)); margin: 10px auto; }
  .runner-header { min-height: 62px; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 10px 15px; }
  .runner-identity { display: block; }
  .runner-identity strong { display: block; margin-top: 5px; font-size: 13px; }
  .runner-score { display: none; }
  .runner-back { padding-inline: 9px; }
  .runner-stage { min-height: 360px; }
  .runner-overlay { padding: 18px; }
  .runner-overlay strong { font-size: clamp(32px, 10vw, 48px); }
  .runner-footer { min-height: 110px; padding: 10px 15px; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
  .runner-footer > p { grid-column: 1 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .runner-progress li { height: 15px; padding: 0; border-width: 4px; color: transparent; }
  .runner-controls { grid-template-columns: repeat(3, 34px); }
  .runner-controls button { width: 34px; height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .runner-progress li,
  .terminal-game,
  .terminal-game.is-skill,
  .terminal-game.is-running .runner-stage::after { transition: none; animation: none; }
}
