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

:root {
  --cyan:   #00f5ff;
  --pink:   #ff0080;
  --purple: #9b00ff;
  --green:  #00ff41;
  --dark:   #070710;
  --panel:  #0d0d1a;
  --border: #1a1a3a;
}

body {
  background: var(--dark);
  color: #e0e0e0;
  font-family: 'Courier New', Courier, monospace;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* CRT scanlines overlay */
.scanlines {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.18) 2px,
    rgba(0,0,0,0.18) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

#app {
  width: 580px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 2px solid var(--pink);
}

#title-block {
  position: relative;
}

h1#game-title {
  font-size: 1.5rem;
  letter-spacing: 4px;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan), 0 0 20px rgba(0,245,255,0.4);
}

/* Glitch animation on title */
#title-glitch {
  position: absolute;
  top: 0; left: 0;
  font-size: 1.5rem;
  letter-spacing: 4px;
  color: var(--pink);
  animation: glitch-title 6s infinite;
  clip-path: inset(0);
  opacity: 0;
}

@keyframes glitch-title {
  0%, 90%, 100% { opacity: 0; transform: none; }
  91%  { opacity: 1; transform: translate(-3px, 0); clip-path: inset(20% 0 60% 0); }
  92%  { opacity: 1; transform: translate(3px, 0);  clip-path: inset(50% 0 10% 0); }
  93%  { opacity: 0; }
  95%  { opacity: 1; transform: translate(-2px, 1px); clip-path: inset(30% 0 40% 0); }
  96%  { opacity: 0; }
}

#hud { display: flex; gap: 20px; }

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.hud-item .label {
  font-size: 0.55rem;
  letter-spacing: 2px;
  color: #555;
}

.hud-item span:last-child {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(0,245,255,0.5);
}

/* Bonus bar */
#bonus-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  background: #0a0a1f;
  border: 1px solid var(--purple);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
}

#bonus-bar.hidden { display: none; }

#bonus-label { color: var(--purple); }
#spins-remaining { color: #ccc; }
#session-win { color: var(--green); text-shadow: 0 0 6px rgba(0,255,65,0.4); }

#bonus-bar.killscreen {
  border-color: var(--pink);
  background: #1a000d;
  animation: ks-pulse 2s ease-in-out infinite;
}

#bonus-bar.killscreen #bonus-label {
  color: var(--pink);
  text-shadow: 0 0 8px rgba(255,0,128,0.6);
}

@keyframes ks-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255,0,128,0.2); }
  50%       { box-shadow: 0 0 20px rgba(255,0,128,0.5); }
}

/* Grid container */
#grid-container {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--cyan);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* Corner accents */
#grid-container::before, #grid-container::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--cyan);
  border-style: solid;
  opacity: 0.5;
}
#grid-container::before { top: 4px; left: 4px; border-width: 2px 0 0 2px; }
#grid-container::after  { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; }

#grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

/* Cells */
.cell {
  width: 74px;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.06);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  transition: opacity 0.12s;
  cursor: default;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* Pixel-art inner texture */
.cell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0px, transparent 3px,
    rgba(0,0,0,0.08) 3px, rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
}

/* White pre-laser highlight — shown before the Corruptor fires */
.cell.pre-laser-win {
  border-color: rgba(255,255,255,0.9);
  box-shadow: 0 0 10px rgba(255,255,255,0.7), inset 0 0 6px rgba(255,255,255,0.15);
  z-index: 2;
}

.cell.winning {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(0,245,255,0.7), inset 0 0 8px rgba(0,245,255,0.15);
  z-index: 2;
  animation: pulse-win 0.5s ease-in-out infinite alternate;
}

@keyframes pulse-win {
  from { box-shadow: 0 0 8px rgba(0,245,255,0.5); }
  to   { box-shadow: 0 0 20px rgba(0,245,255,0.9), inset 0 0 12px rgba(0,245,255,0.2); }
}

.cell.cleared {
  background: transparent !important;
  border-color: transparent;
  box-shadow: none;
  opacity: 0;
}

/* Laser beam — bright yellow/white travelling cell */
.cell.laser-beam {
  animation: laser-beam-hit 0.45s ease-out forwards;
  z-index: 3;
}

@keyframes laser-beam-hit {
  0%   {
    background: #ffff00 !important;
    border-color: #ffff00;
    box-shadow: 0 0 24px 8px #ffff00, 0 0 6px 2px #fff inset;
    filter: brightness(4);
    color: #000;
  }
  35%  {
    background: rgba(255,220,0,0.6) !important;
    border-color: #ffdd00;
    box-shadow: 0 0 14px 4px #ffdd00;
    filter: brightness(2);
  }
  100% {
    background: rgba(255,200,0,0.1) !important;
    border-color: rgba(255,200,0,0.3);
    box-shadow: none;
    filter: brightness(1);
  }
}

/* Dead Pixel cell */
.cell.dead-pixel {
  background: #1a0a2e !important;
  border-color: var(--purple);
  color: var(--purple);
  font-size: 0.8rem;
  text-shadow: 0 0 6px rgba(155,0,255,0.7);
}

.cell.dead-pixel.activated {
  animation: dp-activate 0.6s ease-out forwards;
}

@keyframes dp-activate {
  0%   { box-shadow: none; filter: brightness(1); }
  25%  { box-shadow: 0 0 24px 8px rgba(155,0,255,0.9); filter: brightness(2.5); border-color: #fff; }
  60%  { box-shadow: 0 0 12px 4px rgba(155,0,255,0.5); filter: brightness(1.5); }
  100% { box-shadow: 0 0 6px rgba(155,0,255,0.3); filter: brightness(1); }
}

/* Corruptor wild cell */
.cell.corruptor {
  background: #111 !important;
  border-color: rgba(255,255,255,0.3);
  font-size: 1.1rem;
  animation: static-flicker 1.2s steps(2) infinite;
}

@keyframes static-flicker {
  0%, 100% { filter: brightness(1); }
  50%       { filter: brightness(0.7) contrast(1.4); }
}

/* Plain wild (laser-converted cell) */
.cell.plain-wild {
  background: #111 !important;
  border-color: rgba(255,255,255,0.3);
  font-size: 1.1rem;
  color: rgba(255,255,255,0.7);
}

@keyframes wild-spawn {
  0%   { transform: scale(0.4); opacity: 0; filter: brightness(3); }
  50%  { transform: scale(1.2); opacity: 1; filter: brightness(2); }
  100% { transform: scale(1);   opacity: 1; filter: brightness(1); }
}

.cell.wild-spawn {
  animation: wild-spawn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Scatter */
.cell.scatter {
  background: #1a1200 !important;
  border-color: gold;
  color: gold;
  text-shadow: 0 0 8px gold;
  font-size: 1rem;
}

/* Fall-in animation */
@keyframes fall-in {
  from { transform: translateY(-420px); opacity: 0; }
  to   { transform: translateY(0);      opacity: 1; }
}

.cell.falling {
  animation: fall-in 0.3s cubic-bezier(0.25, 1, 0.5, 1) both;
}

/* Footer */
footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

#controls { display: flex; gap: 10px; }

.btn {
  padding: 10px 24px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 2px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.08s, box-shadow 0.12s;
  text-transform: uppercase;
}

.btn:disabled { opacity: 0.3; cursor: not-allowed; }
.btn:not(:disabled):hover { opacity: 0.85; }
.btn:not(:disabled):active { transform: scale(0.97); }

.btn-primary {
  background: var(--pink);
  color: #fff;
  border-color: var(--pink);
  box-shadow: 0 0 10px rgba(255,0,128,0.3);
}

.btn-primary:not(:disabled):hover {
  box-shadow: 0 0 18px rgba(255,0,128,0.6);
}

.btn-secondary { background: #1a1a2e; color: #888; border-color: #333; }

.btn-buy {
  background: #1a1a2e;
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 8px rgba(0,255,255,0.2);
}
.btn-buy:not(:disabled):hover { box-shadow: 0 0 16px rgba(0,255,255,0.5); }
.btn-buy-ks {
  color: var(--pink);
  border-color: var(--pink);
  box-shadow: 0 0 8px rgba(255,0,128,0.2);
}
.btn-buy-ks:not(:disabled):hover { box-shadow: 0 0 16px rgba(255,0,128,0.5); }

#message {
  min-height: 20px;
  font-size: 0.78rem;
  color: var(--cyan);
  letter-spacing: 2px;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0 6px rgba(0,245,255,0.4);
}

/* Dead Pixel collect overlay */
#dp-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
}

#dp-overlay.hidden { display: none; }

.dp-popup {
  text-align: center;
  animation: dp-popup-enter 2.8s ease-out forwards;
}

@keyframes dp-popup-enter {
  0%   { opacity: 0; transform: scale(0.3) translateY(20px); }
  10%  { opacity: 1; transform: scale(1.15); }
  18%  { transform: scale(0.95); }
  25%  { transform: scale(1); opacity: 1; }
  75%  { opacity: 1; }
  90%  { opacity: 0.5; }
  100% { opacity: 0; }
}

.dp-popup-label {
  font-size: 0.65rem;
  letter-spacing: 5px;
  color: #888;
  margin-bottom: 4px;
}

.dp-popup-value {
  font-size: 80px;
  font-weight: 900;
  color: var(--purple);
  text-shadow: 0 0 20px var(--purple), 0 0 50px rgba(155,0,255,0.5);
  line-height: 1;
  letter-spacing: 2px;
}

.dp-popup-detail {
  font-size: 0.7rem;
  color: #aaa;
  letter-spacing: 3px;
  margin-top: 8px;
}

/* Win breakdown text */
.win-breakdown {
  font-size: 0.68rem;
  color: #666;
  letter-spacing: 1px;
  line-height: 1.6;
}

.dp-mult-tag {
  color: var(--cyan);
  font-size: 0.65rem;
}
