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

:root {
  --green: #00ff41;
  --cyan: #00d4ff;
  --amber: #ffb000;
  --red: #ff3333;
  --orange: #ff6600;
  --bg: #080b10;
  --card-bg: #0d1117;
  --card-border: #1e3a2f;
  --text: #c9d1d9;
  --dim: #4a5568;
  --font: 'Courier New', 'Lucida Console', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  user-select: none;
}

#matrix-bg {
  position: fixed;
  inset: 0;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.5s;
}

/* scanlines */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent, transparent 2px,
    rgba(0,0,0,0.04) 2px, rgba(0,0,0,0.04) 4px
  );
  pointer-events: none;
  z-index: 999;
}

/* ---- SCREEN SHAKE ---- */
@keyframes shakeNormal {
  0%,100% { transform: translate(0,0); }
  10% { transform: translate(-4px,-3px); }
  20% { transform: translate(4px,2px); }
  30% { transform: translate(-3px,4px); }
  40% { transform: translate(3px,-2px); }
  50% { transform: translate(-5px,3px); }
  60% { transform: translate(5px,-3px); }
  70% { transform: translate(-2px,4px); }
  80% { transform: translate(2px,-4px); }
  90% { transform: translate(-3px,2px); }
}
@keyframes shakeHeavy {
  0%,100% { transform: translate(0,0); }
  10% { transform: translate(-9px,-6px); }
  20% { transform: translate(9px,5px); }
  30% { transform: translate(-7px,9px); }
  40% { transform: translate(7px,-6px); }
  50% { transform: translate(-12px,7px); }
  60% { transform: translate(12px,-7px); }
  70% { transform: translate(-6px,9px); }
  80% { transform: translate(6px,-9px); }
  90% { transform: translate(-7px,5px); }
}
@keyframes shakeLight {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-2px,-1px); }
  50% { transform: translate(2px,1px); }
  75% { transform: translate(-1px,2px); }
}

body.screen-shake       { animation: shakeNormal 0.4s ease-out; }
body.screen-shake-heavy { animation: shakeHeavy  0.45s ease-out; }
body.screen-shake-light { animation: shakeLight  0.3s ease-out; }

/* ---- HUD ---- */
#hud {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0.4rem 1rem;
  gap: 1.2rem;
  border-bottom: 1px solid #1e3a2f;
  background: rgba(8,11,16,0.97);
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 44px;
  transition: opacity 0.15s, filter 0.15s;
}

.hud-block {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.hud-block.hud-sanity {
  flex: 1;
  min-width: 160px;
}

.hud-lbl {
  font-size: 0.52rem;
  color: var(--dim);
  letter-spacing: 0.08em;
}

#hud-score  { color: var(--cyan);  font-weight: bold; font-size: 1rem; }
#hud-level  { color: var(--amber); font-weight: bold; }
#hud-streak { color: var(--green); font-weight: bold; }
#hud-reviewed { color: var(--dim); }

#sanity-wrap {
  flex: 1;
  height: 14px;
  background: #111820;
  border: 1px solid #2a3f30;
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

#sanity-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), #39d353);
  transition: width 0.3s, background 0.5s;
}

#sanity-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: bold;
  color: rgba(0,0,0,0.7);
}

/* ---- CARD AREA ---- */
#card-area {
  flex: 1;
  overflow: hidden;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.5rem;
  position: relative;
}

/* ---- PR CARDS ---- */
.pr-card {
  width: min(480px, 97vw);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  font-size: 0.72rem;
  box-shadow: 0 4px 18px rgba(0,0,0,0.7);
  transition: border-color 0.2s;
  flex-shrink: 0;
  animation: cardIn 0.22s ease-out;
}

@keyframes cardIn {
  from { transform: translateY(-14px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.pr-card:hover { border-color: #2a5040; }

.card-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.32rem 0.6rem;
  border-bottom: 1px solid #1a2a20;
  background: #0a1018;
  border-radius: 4px 4px 0 0;
}

.commit-hash { color: var(--amber); font-size: 0.6rem; flex-shrink: 0; }
.pr-num      { color: var(--cyan);  font-size: 0.6rem; flex-shrink: 0; }
.pr-title {
  color: #8b949e;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.67rem;
}

.hint-icon {
  font-size: 1rem;
  min-width: 22px;
  text-align: center;
  transition: opacity 0.5s;
  flex-shrink: 0;
}

.card-meta {
  padding: 0.2rem 0.6rem;
  font-size: 0.57rem;
  color: var(--dim);
  border-bottom: 1px solid #0f1a10;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-code {
  padding: 0.3rem 0.6rem;
  min-height: 50px;
}

.code-line {
  line-height: 1.52;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.66rem;
  font-family: var(--font);
}

.code-line.add    { color: #3fb950; }
.code-line.remove { color: #f85149; }
.code-line.ctx    { color: #6e7681; }

.timer-bar-wrap { height: 3px; background: #0a1018; }
.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--green);
  transition: background 0.5s;
}

.card-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  border-top: 1px solid #0f1a10;
}

.btn-approve, .btn-reject {
  flex: 1;
  padding: 0.27rem 0;
  border: 1px solid;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  transition: background 0.1s, box-shadow 0.1s, color 0.3s, border-color 0.3s;
}

.btn-approve {
  background: rgba(0,255,65,0.06);
  border-color: #00aa30;
  color: var(--green);
}
.btn-approve:hover {
  background: rgba(0,255,65,0.18);
  box-shadow: 0 0 8px rgba(0,255,65,0.25);
}

.btn-reject {
  background: rgba(255,51,51,0.06);
  border-color: #aa2020;
  color: var(--red);
}
.btn-reject:hover {
  background: rgba(255,51,51,0.18);
  box-shadow: 0 0 8px rgba(255,51,51,0.25);
}

/* controls reversed — swap button colours for visual chaos */
body.controls-reversed .btn-approve {
  background: rgba(255,51,51,0.08);
  border-color: #cc2020;
  color: var(--red);
}
body.controls-reversed .btn-approve:hover {
  background: rgba(255,51,51,0.2);
  box-shadow: 0 0 8px rgba(255,51,51,0.3);
}
body.controls-reversed .btn-reject {
  background: rgba(0,255,65,0.08);
  border-color: #00bb30;
  color: var(--green);
}
body.controls-reversed .btn-reject:hover {
  background: rgba(0,255,65,0.2);
  box-shadow: 0 0 8px rgba(0,255,65,0.3);
}

/* card result animations */
.card-correct {
  border-color: var(--green) !important;
  box-shadow: 0 0 22px rgba(0,255,65,0.4) !important;
  animation: resCorrect 0.45s ease-out forwards;
}
.card-wrong {
  border-color: var(--red) !important;
  box-shadow: 0 0 22px rgba(255,51,51,0.4) !important;
  animation: resWrong 0.45s ease-out forwards;
}
.card-miss {
  animation: resMiss 0.38s ease-out forwards;
}

@keyframes resCorrect {
  0%   { transform: scale(1); opacity: 1; }
  40%  { transform: scale(1.015); }
  100% { transform: scale(0.95); opacity: 0; }
}
@keyframes resWrong {
  0%   { transform: translateX(0); opacity: 1; }
  20%  { transform: translateX(-7px); }
  40%  { transform: translateX(7px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(3px); opacity: 0.5; }
  100% { opacity: 0; }
}
@keyframes resMiss {
  from { opacity: 0.25; }
  to   { opacity: 0; }
}

/* ---- POWERUP BAR ---- */
#powerup-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.32rem 1rem;
  border-top: 1px solid #1e3a2f;
  background: rgba(8,11,16,0.97);
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 38px;
  transition: opacity 0.15s;
}

.pu-btn {
  padding: 0.2rem 0.55rem;
  background: rgba(0,212,255,0.05);
  border: 1px solid #1e3a4f;
  border-radius: 3px;
  color: var(--dim);
  font-family: var(--font);
  font-size: 0.67rem;
  cursor: pointer;
  transition: all 0.12s;
}
.pu-btn:hover:not(:disabled) {
  background: rgba(0,212,255,0.12);
  border-color: var(--cyan);
  color: var(--cyan);
}
.pu-btn:disabled { opacity: 0.28; cursor: not-allowed; }

.pu-btn kbd, #powerup-bar kbd {
  background: #1a2a3a;
  border: 1px solid #2a3a4a;
  border-radius: 2px;
  padding: 0.08rem 0.28rem;
  font-family: var(--font);
  font-size: 0.62rem;
  color: var(--cyan);
  margin-right: 0.2rem;
}
.pu-btn span { color: var(--amber); margin-left: 0.25rem; }

#freeze-indicator {
  display: none;
  color: var(--cyan);
  font-size: 0.74rem;
  font-weight: bold;
  text-shadow: 0 0 8px rgba(0,212,255,0.5);
  animation: indicatorBlink 0.7s ease-in-out infinite;
}

#controls-indicator {
  display: none;
  color: var(--orange);
  font-size: 0.74rem;
  font-weight: bold;
  text-shadow: 0 0 8px rgba(255,102,0,0.6);
  animation: indicatorBlink 0.45s ease-in-out infinite;
}

@keyframes indicatorBlink { 0%,100%{opacity:1} 50%{opacity:0.25} }

.pu-hint {
  margin-left: auto;
  font-size: 0.58rem;
  color: #2a3a3a;
}

/* ---- OVERLAYS ---- */
#start-screen, #gameover-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8,11,16,0.97);
}

#gameover-screen { display: none; }

.overlay-content {
  text-align: center;
  max-width: 540px;
  padding: 2rem;
  width: 100%;
}

.glitch-title {
  font-size: clamp(2rem, 7vw, 3.5rem);
  font-weight: bold;
  color: var(--green);
  text-shadow: 0 0 22px rgba(0,255,65,0.4);
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  position: relative;
}
.glitch-title.error {
  color: var(--red);
  text-shadow: 0 0 22px rgba(255,51,51,0.4);
}

.overlay-sub {
  font-size: 0.78rem;
  color: var(--dim);
  margin-bottom: 1.5rem;
  font-style: italic;
}

.overlay-info {
  margin: 1.2rem 0;
  color: var(--text);
  font-size: 0.83rem;
  line-height: 2;
}

.action-btn {
  padding: 0.55rem 0;
  background: transparent;
  border: 2px solid var(--green);
  color: var(--green);
  font-family: var(--font);
  font-size: 0.95rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.18s;
  margin-top: 1.2rem;
  display: block;
  width: 100%;
}
.action-btn:hover {
  background: rgba(0,255,65,0.1);
  box-shadow: 0 0 18px rgba(0,255,65,0.22);
}

.key-legend {
  margin-top: 1.3rem;
  font-size: 0.6rem;
  color: var(--dim);
}
.key-legend kbd {
  background: #1a2a1a;
  border: 1px solid #2a4a2a;
  border-radius: 2px;
  padding: 0.08rem 0.3rem;
  font-family: var(--font);
  color: var(--green);
  font-size: 0.6rem;
}

/* ---- COMBO POPUP ---- */
#combo-pop {
  position: fixed;
  top: 36%;
  left: 50%;
  transform: translate(-50%,-50%) scale(0);
  font-size: 2rem;
  font-weight: bold;
  color: var(--amber);
  text-shadow: 0 0 16px rgba(255,176,0,0.5);
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  font-family: var(--font);
  letter-spacing: 0.05em;
}
#combo-pop.show {
  transform: translate(-50%,-50%) scale(1);
  opacity: 1;
}

/* ---- EVENT FLASH ---- */
#event-flash {
  position: fixed;
  top: 54px;
  left: 0; right: 0;
  text-align: center;
  padding: 0.38rem;
  font-size: 0.8rem;
  font-weight: bold;
  letter-spacing: 0.12em;
  z-index: 195;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  background: rgba(255,51,51,0.88);
  color: #fff;
}
#event-flash.show     { opacity: 1; background: rgba(255,51,51,0.88); }
#event-flash.show.inf { background: rgba(0,212,255,0.8); }

/* ---- SANITY STATES ---- */
body.sanity-warn #sanity-bar { background: var(--amber) !important; }
body.sanity-crit #sanity-bar { background: var(--red)   !important; }

body.sanity-crit #card-area {
  animation: areaGlitch 1.8s ease-in-out infinite;
}
@keyframes areaGlitch {
  0%,75%,100% { filter: none; }
  78% { filter: hue-rotate(180deg) brightness(1.2); }
  80% { filter: none; }
  84% { filter: hue-rotate(-90deg) saturate(2); }
  86% { filter: none; }
  90% { filter: brightness(1.3) contrast(1.5); }
  92% { filter: none; }
}

body.sanity-crit #matrix-bg { opacity: 0.16; }

/* ---- SANITY DYING (≤15%) ---- */
body.sanity-dying #sanity-bar {
  background: #ff0000 !important;
  animation: dyingBarFlash 0.18s ease-in-out infinite;
}
@keyframes dyingBarFlash { 0%,100%{opacity:1} 50%{opacity:0.2} }

body.sanity-dying #card-area {
  animation: areaDying 0.55s ease-in-out infinite;
}
@keyframes areaDying {
  0%,100% { filter: none; }
  12%  { filter: hue-rotate(180deg) brightness(1.5) saturate(3); }
  24%  { filter: none; }
  38%  { filter: hue-rotate(-90deg) brightness(0.5) contrast(2.5); }
  52%  { filter: none; }
  66%  { filter: hue-rotate(270deg) saturate(4) brightness(1.2); }
  80%  { filter: none; }
  92%  { filter: invert(0.15); }
}

body.sanity-dying::before {
  content: '';
  position: fixed;
  inset: 0;
  border: 4px solid var(--red);
  pointer-events: none;
  z-index: 50;
  animation: dyingBorder 0.22s ease-in-out infinite;
}
@keyframes dyingBorder {
  0%,100% { opacity: 1; border-color: var(--red); }
  50%     { opacity: 0.05; border-color: #ff6600; }
}

body.sanity-dying #matrix-bg { opacity: 0.38; animation: matrixPulse 0.4s ease-in-out infinite; }
@keyframes matrixPulse { 0%,100%{opacity:0.38} 50%{opacity:0.55} }

/* ---- MERGE HELL ---- */
body.merge-hell .timer-bar {
  background: var(--red) !important;
  animation: mergeHellFlash 0.25s ease-in-out infinite;
}
@keyframes mergeHellFlash { 0%,100%{opacity:1} 50%{opacity:0.35} }

body.merge-hell #card-area {
  animation: mergeHellGlow 0.5s ease-in-out infinite;
}
@keyframes mergeHellGlow {
  0%,100% { filter: none; }
  50%     { filter: hue-rotate(12deg) brightness(1.08) saturate(1.4); }
}

body.merge-hell #event-flash.show {
  animation: chaosFlashPulse 0.3s ease-in-out infinite;
}
@keyframes chaosFlashPulse { 0%,100%{opacity:1} 50%{opacity:0.7} }

/* ---- VPN DOWN ---- */
body.vpn-down #hud {
  opacity: 0;
  filter: blur(3px);
}
body.vpn-down #powerup-bar {
  opacity: 0.06;
}

/* ---- FROZEN STATE ---- */
body.frozen .pr-card { border-color: #004466 !important; box-shadow: 0 0 12px rgba(0,212,255,0.2) !important; }
