@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --yellow: #ffd900;
  --yellow-dark: #b99f00;
  --black: #151515;
  --screen: #292929;
  --white: #f4f4ee;
  --red: #ff1919;
  --blue: #5148ff;
  --line: #ffffff;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(circle at 50% 35%, #f7f7f4 0 25%, #e7e7e4 70%, #d5d5d2 100%);
  color: var(--black);
  font-family: 'VT323', monospace;
  display: grid;
  place-items: center;
  overflow-x: hidden;
}

button { font: inherit; }

.arcade {
  width: min(900px, 96vw);
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 0;
}

.machine-wrap {
  width: min(820px, 92vw);
  aspect-ratio: 1.24 / 1;
  position: relative;
}

.machine-shell {
  position: absolute;
  inset: 0;
  background: var(--yellow);
  border-radius: 78px 78px 65px 65px;
  border: 5px solid #f0c900;
  box-shadow: 0 15px 0 var(--yellow-dark), 0 28px 30px #0002;
  padding: 34px 43px 30px;
}

.machine-top {
  height: 78px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.brand {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(13px, 2vw, 20px);
  letter-spacing: -2px;
  margin-top: 4px;
  pointer-events: none;
}

.brand span { color: #333; }

.player-lamp {
  position: absolute;
  top: 4px;
  width: 48px;
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  height: 38px;
}

.player-lamp.player-one { left: 14px; }
.player-lamp.player-two { right: 14px; }

.player-lamp i {
  display: block;
  width: 38px;
  height: 38px;
  margin: auto;
  border-radius: 50%;
  background: #706c65;
  box-shadow: inset 0 4px 6px #0005;
  transition: .18s;
}

.player-lamp.player-one i {
  background: var(--red);
  box-shadow: 0 0 5px #ff191944, inset 0 4px 6px #0005;
}
.player-lamp.player-two i {
  background: var(--blue);
  box-shadow: 0 0 5px #5148ff44, inset 0 4px 6px #0005;
}

.player-lamp.active i { animation: lampPulse .9s steps(2, end) infinite; }

.player-lamp.player-one.active i {
  background: var(--red);
  box-shadow: 0 0 10px var(--red), 0 0 25px #ff191955, inset 0 3px 4px #fff5;
}

.player-lamp.player-two.active i {
  background: var(--blue);
  box-shadow: 0 0 10px var(--blue), 0 0 25px #5148ff55, inset 0 3px 4px #fff5;
}

.screen-frame {
  height: calc(100% - 122px);
  background: #0b0b0b;
  border-radius: 48% 48% 46% 46% / 39% 39% 44% 44%;
  padding: 11px;
  box-shadow: inset 0 4px 0 #000, 0 4px 0 #806e00;
}

.screen {
  height: 100%;
  position: relative;
  overflow: hidden;
  background: #020202;
  border-radius: 48% 48% 46% 46% / 39% 39% 44% 44%;
  padding: 48px 45px 28px;
  transition: background .25s;
}

.screen.running {
  background:
    linear-gradient(#ffffff08 50%, #00000008 50%),
    var(--screen);
  background-size: 100% 4px, auto;
}

.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, #0002 4px 5px);
  opacity: .7;
  z-index: 8;
}

.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, #fff0 20%, #fff1 45%, #fff0 58%);
  transform: translateX(-130%);
  animation: scanShine 5s linear infinite;
  z-index: 9;
}

.boot-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: #020202;
  color: #ddd;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(8px, 1.5vw, 13px);
  transition: opacity .25s;
}

.boot-overlay.booting { animation: bootFlicker .25s steps(2, end) infinite; }

.boot-overlay.booted {
  opacity: 0;
  pointer-events: none;
}

.boot-progress {
  width: min(250px, 55vw);
  height: 8px;
  border: 2px solid #777;
  padding: 1px;
}

.boot-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: #eee;
  transition: width .55s steps(8, end);
}

.boot-overlay.ready .boot-progress i { width: 0; }
.boot-overlay.booting .boot-progress i { width: 100%; }

.screen-header {
  width: min(390px, 72%);
  margin: 0 auto;
  color: #c9c9c9;
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  letter-spacing: 1px;
  position: relative;
  z-index: 2;
}

.round { opacity: .65; }

.board {
  width: min(390px, 72%);
  aspect-ratio: 1;
  margin: 5px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: scale(.92);
}

.screen.running .board {
  animation: boardBoot .35s steps(4, end) forwards;
}

.cell {
  appearance: none;
  border: 0;
  background: transparent;
  position: relative;
  cursor: pointer;
  min-width: 0;
  opacity: 0;
}

.screen.running .cell { animation: cellBoot .3s steps(2, end) forwards; }
.screen.running .cell:nth-child(1) { animation-delay: .02s; }
.screen.running .cell:nth-child(2) { animation-delay: .05s; }
.screen.running .cell:nth-child(3) { animation-delay: .08s; }
.screen.running .cell:nth-child(4) { animation-delay: .11s; }
.screen.running .cell:nth-child(5) { animation-delay: .14s; }
.screen.running .cell:nth-child(6) { animation-delay: .17s; }
.screen.running .cell:nth-child(7) { animation-delay: .20s; }
.screen.running .cell:nth-child(8) { animation-delay: .23s; }
.screen.running .cell:nth-child(9) { animation-delay: .26s; }

.cell:nth-child(-n+6) { border-bottom: 4px solid var(--line); }
.cell:nth-child(3n+1), .cell:nth-child(3n+2) { border-right: 4px solid var(--line); }

.cell:hover:not(:disabled) {
  background: #ffffff0a;
  filter: brightness(1.35);
}

.cell:disabled { cursor: default; }

.mark {
  position: absolute;
  inset: 13%;
  display: grid;
  place-items: center;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(28px, 6vw, 52px);
  line-height: 1;
  text-shadow: 3px 3px 0 #000;
  animation: tetrisDrop .42s cubic-bezier(.2,.9,.3,1) both;
}

.mark.x { color: var(--red); }
.mark.o {
  color: var(--blue);
  border: 7px solid currentColor;
  border-radius: 50%;
  font-size: 0;
  inset: 19%;
  box-shadow: inset 0 0 0 3px #0005;
}

.mark::before, .mark::after {
  content: "";
  position: absolute;
  background: currentColor;
  opacity: .18;
}
.win-line {
  position: absolute;
  height: 7px;
  background: #fff;
  box-shadow: 0 0 7px #fff, 0 0 16px #fff;
  border-radius: 99px;
  opacity: 0;
  transform-origin: left center;
  will-change: width, opacity;
  pointer-events: none;
  z-index: 4;
}

.win-line.show { animation: winLine .55s cubic-bezier(.1,.8,.2,1) forwards; }

.win-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 13px;
  background: #111d;
  opacity: 0;
  visibility: hidden;
  z-index: 6;
  backdrop-filter: blur(2px);
}

.win-screen.show {
  visibility: visible;
  animation: winFlash .7s steps(2, end) forwards;
}

.win-glitch { color: var(--yellow); font-size: 34px; animation: glitch .3s steps(2, end) infinite; }

.win-title {
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(15px, 3vw, 28px);
  text-align: center;
  text-shadow: 4px 4px 0 #000;
}

.win-sub { color: #aaa; font-size: 21px; }

.round-btn, .pixel-btn {
  border: 0;
  cursor: pointer;
  background: var(--black);
  color: white;
  padding: 10px 15px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  box-shadow: 0 4px 0 #000;
  transition: transform .12s, box-shadow .12s, filter .12s;
}

.round-btn:hover, .pixel-btn:hover {
  filter: brightness(1.25);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #000;
}

.round-btn:active, .pixel-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000;
}

.round-btn:disabled { opacity: 1; cursor: not-allowed; transform: none; }
.reset-btn { background: #7b0909; }

.machine-controls {
  height: 60px;
  display: flex;
  align-items: end;
  gap: 10px;
}


@keyframes lampPulse { 50% { transform: scale(.94); } }
@keyframes scanShine { to { transform: translateX(130%); } }
@keyframes bootFlicker { 50% { opacity: .55; } }
@keyframes boardBoot { 0% { opacity: 0; transform: scale(.92); } 100% { opacity: 1; transform: scale(1); } }
@keyframes cellBoot { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 1; } }
@keyframes tetrisDrop {
  0% { opacity: 0; transform: translateY(-70px) scale(.6); }
  60% { opacity: 1; transform: translateY(5px) scale(1.08); }
  78% { transform: translateY(-3px) scale(.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes winLine { from { opacity: 1; width: 0; } to { opacity: 1; } }
@keyframes winFlash { 0% { opacity: 0; } 30% { opacity: 1; } 45% { opacity: .55; } 60% { opacity: 1; } 100% { opacity: 1; } }
@keyframes glitch { 50% { transform: translate(3px, -2px); } }

@media (max-width: 650px) {
  .machine-wrap { aspect-ratio: .9 / 1; }
  .machine-shell { padding: 22px 20px 18px; border-radius: 50px; }
  .machine-top { height: 66px; padding-right: 80px; }
  .player-lamp { top: 5px; }
  .player-lamp i { width: 28px; height: 28px; }
  .screen { padding: 42px 20px 20px; }
  .screen-frame { border-radius: 48%; }
  .board { width: 88%; }
  .screen-header { width: 88%; }
  .machine-controls { height: 54px; gap: 7px; }
  .round-btn { padding: 8px 9px; font-size: 8px; }
  .brand { font-size: 11px; }
  .status-line { font-size: 13px; }
}


/* The controls are always solid; disabled state never fades them. */
.round-btn:disabled { opacity: 1; }

/* Keep all turn/round information inside the CRT. */
.screen-header {
  position: absolute;
  top: 22px;
  left: 0;
  right: 0;
  width: min(390px, 72%);
}

@media (max-width: 650px) {
  .screen-header { top: 17px; width: 88%; }
  .player-lamp.player-one { left: 5px; }
  .player-lamp.player-two { right: 5px; }
}