:root {
  --bg-1: #060111;
  --bg-2: #14002a;
  --panel: rgba(8, 11, 35, 0.82);
  --text: #e8f8ff;
  --line: rgba(96, 253, 255, 0.45);
  --cyan: #60fdff;
  --pink: #ff4fd8;
  --green: #6bffb3;
  --shadow: 0 0 20px rgba(96, 253, 255, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  background: radial-gradient(circle at 15% 15%, #2a0d4b, transparent 35%),
    radial-gradient(circle at 80% 10%, #0e3a4f, transparent 30%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
  color: var(--text);
  overflow: hidden;
  position: relative;
}

body::before,
body::after {
  content: "";
  position: absolute;
  width: 40vmax;
  height: 40vmax;
  border-radius: 50%;
  filter: blur(32px);
  opacity: 0.35;
  pointer-events: none;
  animation: drift 8s ease-in-out infinite alternate;
}

body::before {
  background: var(--pink);
  left: -12vmax;
  top: -10vmax;
}

body::after {
  background: var(--cyan);
  right: -10vmax;
  bottom: -14vmax;
  animation-delay: 1.5s;
}

.app {
  width: min(100vw, 440px);
  height: min(100dvh, 920px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 0 32px rgba(12, 227, 255, 0.28);
  backdrop-filter: blur(6px);
  position: relative;
  z-index: 2;
  animation: panelEnter 0.9s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

.hidden {
  display: none;
}

.menu-screen {
  display: grid;
  place-items: center;
  padding: 1rem;
}

h1 {
  margin: 0 0 0.4rem;
  font-size: 1.8rem;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(96, 253, 255, 0.8);
  letter-spacing: 0.04em;
}

.menu-card {
  width: min(95%, 390px);
  border: 1px solid rgba(96, 253, 255, 0.3);
  border-radius: 14px;
  background: rgba(7, 20, 46, 0.62);
  box-shadow: 0 0 24px rgba(96, 253, 255, 0.15);
  padding: 1rem;
  text-align: center;
}

.menu-subtitle {
  margin: 0 0 0.85rem;
  color: #c8f5ff;
  font-size: 0.9rem;
}

.menu-step {
  margin-top: 0.5rem;
}

.menu-actions,
.difficulty-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.difficulty-btn {
  padding: 0.6rem 0.45rem;
  font-size: 0.88rem;
}

#impossibleDifficulty {
  border-color: rgba(255, 90, 90, 0.65);
  background: rgba(255, 90, 90, 0.14);
}

#impossibleDifficulty:hover {
  background: rgba(255, 90, 90, 0.24);
}

.menu-title {
  margin: 0 0 0.45rem;
  color: #bdefff;
  font-weight: 800;
  letter-spacing: 0.03em;
  font-size: 0.82rem;
}

.link-btn {
  margin-top: 0.7rem;
  border: none;
  background: transparent;
  color: #9befff;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.menu-btn {
  border: 1px solid rgba(255, 79, 216, 0.5);
  border-radius: 9px;
  background: rgba(255, 79, 216, 0.12);
  color: #ffe9fb;
  padding: 0.65rem 0.7rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.menu-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 79, 216, 0.24);
}

.menu-btn.active {
  border-color: var(--cyan);
  background: rgba(96, 253, 255, 0.15);
  box-shadow: var(--shadow);
}

.game-screen {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  padding: 0.65rem;
}

.game-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgba(96, 253, 255, 0.3);
  border-radius: 10px;
  background: rgba(7, 20, 46, 0.58);
  padding: 0.4rem 0.5rem;
}

.bar-btn {
  border: 1px solid rgba(96, 253, 255, 0.45);
  border-radius: 8px;
  background: rgba(96, 253, 255, 0.12);
  color: #dbffff;
  padding: 0.33rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.bar-center {
  text-align: center;
}

.bar-title {
  margin: 0;
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.score-mini {
  margin: 0.1rem 0 0;
  color: #d2f9ff;
  font-size: 0.68rem;
  font-weight: 700;
}

.score-panel {
  margin-top: 0.45rem;
  border: 1px solid rgba(96, 253, 255, 0.26);
  border-radius: 10px;
  background: rgba(7, 20, 46, 0.58);
  padding: 0.45rem;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition: max-height 0.2s ease, opacity 0.2s ease;
}

.score-panel.open {
  max-height: 180px;
  opacity: 1;
  pointer-events: auto;
}

.status {
  margin: 0.48rem 0 0.22rem;
  font-weight: 600;
  color: #d4feff;
  min-height: 1rem;
  text-align: center;
  font-size: 0.78rem;
}

.status.status-update {
  animation: statusPulse 0.45s ease;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.3rem;
  margin-bottom: 0;
}

.score-card {
  border: 1px solid rgba(96, 253, 255, 0.35);
  border-radius: 10px;
  padding: 0.5rem 0.35rem;
  background: rgba(8, 25, 54, 0.55);
  box-shadow: inset 0 0 10px rgba(96, 253, 255, 0.14);
}

.score-label {
  margin: 0;
  color: #bdefff;
  font-size: 0.58rem;
  letter-spacing: 0.03em;
}

.score-value {
  margin: 0.2rem 0 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: #ecfeff;
  text-shadow: 0 0 10px rgba(96, 253, 255, 0.65);
}

.board-wrap {
  display: grid;
  place-items: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.34rem;
  width: min(88vw, 360px);
  animation: boardBreathe 2.8s ease-in-out infinite;
}

.cell {
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 20, 52, 0.85);
  font-size: clamp(1.65rem, 9vw, 2.3rem);
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  box-shadow: inset 0 0 10px rgba(96, 253, 255, 0.2);
  transition: transform 0.16s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.cell:hover:enabled {
  border-color: var(--cyan);
  box-shadow: inset 0 0 14px rgba(96, 253, 255, 0.36), 0 0 10px rgba(96, 253, 255, 0.3);
  transform: translateY(-1px);
}

.cell:disabled {
  cursor: default;
  opacity: 0.95;
}

.cell.x-mark {
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(96, 253, 255, 0.95);
}

.cell.o-mark {
  color: var(--pink);
  text-shadow: 0 0 12px rgba(255, 79, 216, 0.95);
}

.cell.pop-in {
  animation: markPop 0.24s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.cell.win-cell {
  border-color: var(--green);
  box-shadow: inset 0 0 16px rgba(107, 255, 179, 0.35), 0 0 16px rgba(107, 255, 179, 0.6);
  animation: winBlink 0.8s ease-in-out infinite;
}

.board.celebrate {
  animation: celebratePulse 0.5s ease-in-out 3;
}

.reset {
  margin-top: 0;
  border: 1px solid rgba(107, 255, 179, 0.55);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  background: rgba(107, 255, 179, 0.14);
  color: #e9ffee;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  width: 100%;
}

.reset:hover {
  background: rgba(107, 255, 179, 0.24);
  transform: translateY(-1px);
  box-shadow: 0 0 14px rgba(107, 255, 179, 0.45);
}

.footer-actions {
  margin-top: 0.35rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
  width: min(88vw, 360px);
  margin-inline: auto;
}

.reset-scores {
  margin-top: 0.42rem;
  border-color: rgba(255, 79, 216, 0.55);
  background: rgba(255, 79, 216, 0.14);
  color: #ffe9fb;
}

.reset-scores:hover {
  background: rgba(255, 79, 216, 0.24);
  box-shadow: 0 0 14px rgba(255, 79, 216, 0.45);
}

.reset-menu {
  border-color: rgba(96, 253, 255, 0.55);
  background: rgba(96, 253, 255, 0.14);
  color: #dcfeff;
}

.reset-menu:hover {
  background: rgba(96, 253, 255, 0.24);
  box-shadow: 0 0 14px rgba(96, 253, 255, 0.45);
}

@keyframes drift {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(6vmax, 3vmax) scale(1.15);
  }
}

@keyframes panelEnter {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes statusPulse {
  0% {
    transform: translateY(-2px);
    opacity: 0.6;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes boardBreathe {
  0% {
    filter: drop-shadow(0 0 0 rgba(96, 253, 255, 0));
  }
  50% {
    filter: drop-shadow(0 0 8px rgba(96, 253, 255, 0.22));
  }
  100% {
    filter: drop-shadow(0 0 0 rgba(96, 253, 255, 0));
  }
}

@keyframes markPop {
  from {
    transform: scale(0.6);
    opacity: 0.35;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes winBlink {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

@keyframes celebratePulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.01);
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after,
  .board,
  .board.celebrate,
  .cell.pop-in,
  .cell.win-cell,
  .status.status-update,
  .app {
    animation: none;
  }
}

@media (max-width: 520px) {
  body {
    overflow: hidden;
    padding: 0.1rem;
    min-height: 100dvh;
  }

  body::before,
  body::after {
    opacity: 0.2;
  }

  .app {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  h1 {
    font-size: 1.55rem;
  }

  .menu-screen {
    padding: 0.8rem;
  }

  .menu-card {
    padding: 0.85rem;
  }

  .game-screen {
    padding: 0.45rem;
  }

  .score-panel.open {
    max-height: 165px;
  }

  .board {
    width: min(92vw, 360px);
    gap: 0.32rem;
  }

  .footer-actions {
    width: min(92vw, 360px);
  }

  .cell {
    font-size: clamp(1.55rem, 10vw, 2.1rem);
  }

  .reset {
    padding: 0.52rem 0.4rem;
    font-size: 0.76rem;
  }
}
