:root {
  --bg-dark: #050811;
  --bg-panel: #0b101d;
  --bg-panel-inner: #070b14;
  --bg-cell: #0e1526;
  --bg-cell-hover: #131d33;

  --neon-cyan: #00f0ff;
  --neon-cyan-glow: rgba(0, 240, 255, 0.5);
  --neon-cyan-dim: rgba(0, 240, 255, 0.12);

  --neon-magenta: #ff007f;
  --neon-magenta-glow: rgba(255, 0, 127, 0.5);
  --neon-magenta-dim: rgba(255, 0, 127, 0.12);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --border-subtle: rgba(0, 240, 255, 0.18);
  --border-dim: rgba(255, 255, 255, 0.08);

  --shadow-arcade:
    0 0 30px rgba(0, 0, 0, 0.9),
    0 0 15px rgba(0, 240, 255, 0.1);

  --shadow-cell:
    0 4px 8px rgba(0, 0, 0, 0.6);

  --shadow-modal:
    0 0 40px rgba(0, 0, 0, 0.95),
    0 0 20px rgba(0, 240, 255, 0.2);

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Oxygen,
    Ubuntu,
    sans-serif;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  min-height: 100vh;

  background-color: var(--bg-dark);

  background-image:
    linear-gradient(
      rgba(0, 240, 255, 0.03) 1px,
      transparent 1px
    ),
    linear-gradient(
      90deg,
      rgba(0, 240, 255, 0.03) 1px,
      transparent 1px
    ),
    radial-gradient(
      circle at 15% 15%,
      rgba(0, 240, 255, 0.08) 0%,
      transparent 45%
    ),
    radial-gradient(
      circle at 85% 85%,
      rgba(255, 0, 127, 0.08) 0%,
      transparent 45%
    );

  background-size:
    32px 32px,
    32px 32px,
    100% 100%,
    100% 100%;

  display: flex;
  justify-content: center;
  align-items: center;

  padding: 16px;

  color: var(--text-main);

  overflow-x: hidden;
}

button {
  font: inherit;
}

.game-container {
  width: 440px;
  max-width: 100%;

  background: var(--bg-panel);

  border:
    1px solid
    var(--border-subtle);

  border-radius:
    var(--radius-lg);

  padding:
    24px;

  box-shadow:
    var(--shadow-arcade);

  display: flex;
  flex-direction: column;
  align-items: center;

  gap: 14px;

  position: relative;
}

.game-header {
  width: 100%;
  text-align: center;
}

.game-title {
  font-size: 2.3rem;
  font-weight: 900;

  letter-spacing: 0.5px;
  line-height: 1.05;

  background:
    linear-gradient(
      135deg,
      var(--neon-cyan) 0%,
      #d946ef 55%,
      var(--neon-magenta) 100%
    );

  -webkit-background-clip: text;
  background-clip: text;

  -webkit-text-fill-color: transparent;

  filter:
    drop-shadow(
      0 0 10px
      rgba(0, 240, 255, 0.45)
    );
}

.controls-panel {
  width: 100%;

  display: flex;
  flex-direction: column;

  gap: 8px;
}

.mode-selector {
  width: 100%;

  display: flex;

  background: var(--bg-panel-inner);

  border:
    1px solid
    var(--border-dim);

  border-radius:
    var(--radius-md);

  padding: 4px;

  gap: 4px;
}

.mode-btn {
  flex: 1;

  min-width: 0;

  background: transparent;

  border:
    1px solid
    transparent;

  color:
    var(--text-muted);

  font-size: 0.84rem;

  font-weight: 700;

  padding:
    8px 10px;

  min-height: 40px;

  border-radius:
    var(--radius-sm);

  cursor: pointer;

  transition:
    background-color var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.mode-btn:hover:not(.active) {
  color:
    var(--text-main);

  background:
    rgba(0, 240, 255, 0.05);
}

.mode-btn.active {
  background:
    var(--neon-cyan-dim);

  color:
    var(--neon-cyan);

  border-color:
    var(--neon-cyan);

  box-shadow:
    0 0 10px
    rgba(0, 240, 255, 0.3);
}

.difficulty-selector {
  width: 100%;

  display: flex;
  align-items: center;

  gap: 8px;

  animation:
    fadeIn
    0.2s
    ease-in-out;
}

.difficulty-selector.hidden {
  display: none;
}

.difficulty-label {
  flex-shrink: 0;

  font-size: 0.78rem;
  font-weight: 700;

  color:
    var(--text-muted);

  white-space: nowrap;
}

.difficulty-options {
  flex: 1;

  display: flex;

  background:
    var(--bg-panel-inner);

  border:
    1px solid
    var(--border-dim);

  border-radius:
    var(--radius-md);

  padding: 3px;

  gap: 3px;
}

.diff-btn {
  flex: 1;

  min-width: 0;

  background: transparent;

  border:
    1px solid
    transparent;

  color:
    var(--text-muted);

  font-size: 0.74rem;

  font-weight: 700;

  padding:
    6px 5px;

  min-height: 30px;

  border-radius: 6px;

  cursor: pointer;

  transition:
    background-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.diff-btn:hover:not(.active) {
  color:
    var(--text-main);
}

.diff-btn.active {
  background:
    var(--neon-magenta-dim);

  color:
    var(--neon-magenta);

  border-color:
    var(--neon-magenta);

  box-shadow:
    0 0 8px
    rgba(255, 0, 127, 0.35);
}

.status-panel {
  width: 100%;

  text-align: center;

  background:
    var(--bg-panel-inner);

  border:
    1px solid
    rgba(0, 240, 255, 0.18);

  border-radius:
    var(--radius-md);

  padding:
    9px 12px;

  min-height: 42px;

  display: flex;

  justify-content: center;
  align-items: center;

  box-shadow:
    inset 0 0 10px
    rgba(0, 240, 255, 0.04);
}

.status-text {
  font-size: 0.95rem;
  font-weight: 700;

  line-height: 1.2;

  color:
    var(--text-main);
}

.player-tag {
  font-weight: 900;
  padding:
    2px 4px;
}

.player-tag.x-tag {
  color:
    var(--neon-cyan);

  text-shadow:
    0 0 8px
    var(--neon-cyan-glow);
}

.player-tag.o-tag {
  color:
    var(--neon-magenta);

  text-shadow:
    0 0 8px
    var(--neon-magenta-glow);
}

.board-container {
  width: 100%;

  display: flex;

  justify-content: center;
  align-items: center;
}

.board {
  width: 100%;

  aspect-ratio: 1 / 1;

  display: grid;

  grid-template-columns:
    repeat(3, minmax(0, 1fr));

  grid-template-rows:
    repeat(3, minmax(0, 1fr));

  gap: 9px;
}

.cell {
  width: 100%;
  height: 100%;

  min-width: 0;
  min-height: 0;

  background-color:
    var(--bg-cell);

  border:
    1px solid
    rgba(0, 240, 255, 0.15);

  border-radius:
    12px;

  font-size:
    clamp(
      2.4rem,
      9vw,
      3.7rem
    );

  font-weight: 900;

  cursor: pointer;

  display: flex;

  justify-content: center;
  align-items: center;

  padding: 0;

  line-height: 1;

  box-shadow:
    var(--shadow-cell);

  transition:
    background-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    border-color var(--transition-fast);

  user-select: none;

  -webkit-tap-highlight-color:
    transparent;
}

.cell:hover:not(.x):not(.o):not(:disabled) {
  background-color:
    var(--bg-cell-hover);

  border-color:
    var(--neon-cyan);

  box-shadow:
    0 0 14px
    rgba(0, 240, 255, 0.35);

  transform:
    translateY(-2px);
}

.cell:active:not(:disabled) {
  transform:
    scale(0.96);
}

.cell:focus-visible {
  outline:
    2px solid
    var(--neon-cyan);

  outline-offset:
    2px;
}

.cell.x {
  color:
    var(--neon-cyan);

  text-shadow:
    0 0 10px
      rgba(0, 240, 255, 0.8),
    0 0 20px
      rgba(0, 240, 255, 0.4);

  border-color:
    rgba(0, 240, 255, 0.3);

  cursor:
    not-allowed;
}

.cell.o {
  color:
    var(--neon-magenta);

  text-shadow:
    0 0 10px
      rgba(255, 0, 127, 0.8),
    0 0 20px
      rgba(255, 0, 127, 0.4);

  border-color:
    rgba(255, 0, 127, 0.3);

  cursor:
    not-allowed;
}

.cell.pop {
  animation:
    popIn
    0.2s
    cubic-bezier(
      0.175,
      0.885,
      0.32,
      1.275
    );
}

@keyframes popIn {
  0% {
    transform:
      scale(0.4);

    opacity: 0;
  }

  100% {
    transform:
      scale(1);

    opacity: 1;
  }
}

.cell.winner {
  background-color:
    rgba(0, 240, 255, 0.15) !important;

  border-color:
    var(--neon-cyan) !important;

  box-shadow:
    0 0 25px
      rgba(0, 240, 255, 0.6),
    inset 0 0 15px
      rgba(0, 240, 255, 0.3) !important;

  animation:
    winPulseCyan
    1.2s
    infinite
    alternate
    ease-in-out;
}

.cell.winner.winner-o {
  background-color:
    rgba(255, 0, 127, 0.15) !important;

  border-color:
    var(--neon-magenta) !important;

  box-shadow:
    0 0 25px
      rgba(255, 0, 127, 0.6),
    inset 0 0 15px
      rgba(255, 0, 127, 0.3) !important;

  animation:
    winPulseMagenta
    1.2s
    infinite
    alternate
    ease-in-out;
}

@keyframes winPulseCyan {
  0% {
    transform:
      scale(1);

    box-shadow:
      0 0 15px
      rgba(0, 240, 255, 0.4);
  }

  100% {
    transform:
      scale(1.04);

    box-shadow:
      0 0 30px
      rgba(0, 240, 255, 0.8);
  }
}

@keyframes winPulseMagenta {
  0% {
    transform:
      scale(1);

    box-shadow:
      0 0 15px
      rgba(255, 0, 127, 0.4);
  }

  100% {
    transform:
      scale(1.04);

    box-shadow:
      0 0 30px
      rgba(255, 0, 127, 0.8);
  }
}

.board.game-over .cell:not(.winner) {
  opacity:
    0.45;

  cursor:
    not-allowed;
}

.board.disabled {
  pointer-events:
    none;
}

.action-panel {
  width: 100%;
}

.restart-btn {
  width: 100%;

  padding:
    11px 16px;

  min-height:
    46px;

  font-size:
    0.95rem;

  font-weight:
    800;

  letter-spacing:
    0.5px;

  border:
    1px solid
    var(--neon-cyan);

  border-radius:
    var(--radius-md);

  background-color:
    var(--neon-cyan-dim);

  color:
    var(--neon-cyan);

  cursor:
    pointer;

  box-shadow:
    0 0 12px
    rgba(0, 240, 255, 0.2);

  transition:
    0.15s ease;
}

.restart-btn:hover {
  background-color:
    var(--neon-cyan);

  color:
    var(--bg-dark);

  box-shadow:
    0 0 20px
    rgba(0, 240, 255, 0.65);
}

.restart-btn:active {
  transform:
    scale(0.97);
}

.restart-btn:focus-visible {
  outline:
    2px solid
    var(--neon-cyan);

  outline-offset:
    2px;
}

.modal-overlay {
  position: fixed;

  inset: 0;

  background:
    rgba(3, 6, 15, 0.85);

  backdrop-filter:
    blur(8px);

  -webkit-backdrop-filter:
    blur(8px);

  display: flex;

  justify-content: center;
  align-items: center;

  padding: 20px;

  z-index: 100;

  opacity: 1;
  visibility: visible;

  transition:
    opacity var(--transition-normal),
    visibility var(--transition-normal);
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 360px;

  background:
    #0c111e;

  border:
    1px solid
    rgba(0, 240, 255, 0.3);

  border-radius:
    var(--radius-lg);

  padding:
    32px 24px;

  text-align:
    center;

  box-shadow:
    var(--shadow-modal);

  transform:
    scale(1)
    translateY(0);

  transition:
    transform
    var(--transition-normal);
}

.modal-overlay.hidden .modal-card {
  transform:
    scale(0.9)
    translateY(15px);
}

.modal-title {
  font-size:
    1.7rem;

  font-weight:
    900;

  margin-bottom:
    8px;

  color:
    var(--text-main);
}

.modal-title.win-x {
  color:
    var(--neon-cyan);

  text-shadow:
    0 0 14px
    var(--neon-cyan-glow);
}

.modal-title.win-o {
  color:
    var(--neon-magenta);

  text-shadow:
    0 0 14px
    var(--neon-magenta-glow);
}

.modal-message {
  font-size:
    0.95rem;

  font-weight:
    500;

  color:
    var(--text-muted);

  margin-bottom:
    24px;

  line-height:
    1.45;
}

.modal-actions {
  display:
    flex;

  flex-direction:
    column;

  gap:
    10px;
}

.modal-btn {
  width:
    100%;

  padding:
    12px 16px;

  font-size:
    0.92rem;

  font-weight:
    800;

  border-radius:
    var(--radius-md);

  cursor:
    pointer;
}

.play-again-btn {
  background:
    var(--neon-cyan);

  color:
    var(--bg-dark);

  border:
    1px solid
    var(--neon-cyan);
}

.change-mode-btn {
  background:
    var(--bg-panel-inner);

  border:
    1px solid
    rgba(255, 255, 255, 0.15);

  color:
    var(--text-main);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform:
      translateY(-4px);
  }

  to {
    opacity: 1;
    transform:
      translateY(0);
  }
}

@media (max-width: 700px) {
  body {
    align-items:
      flex-start;

    padding:
      8px;
  }

  .game-container {
    width:
      calc(100vw - 16px);

    max-width:
      440px;

    margin-top:
      8px;

    padding:
      18px 14px;

    gap:
      13px;
  }

  .game-title {
    font-size:
      clamp(
        1.8rem,
        9vw,
        2.3rem
      );
  }

  .board {
    width:
      min(
        390px,
        100%
      );

    gap:
      7px;
  }

  .cell {
    font-size:
      clamp(
        1.7rem,
        13vw,
        3rem
      );

    border-radius:
      10px;
  }

  .mode-btn {
    font-size:
      clamp(
        0.66rem,
        3vw,
        0.78rem
      );

    padding:
      8px 5px;
  }

  .difficulty-label {
    font-size:
      0.7rem;
  }

  .diff-btn {
    font-size:
      0.67rem;
  }

  .status-text {
    font-size:
      0.88rem;
  }
}

@media (max-width: 420px) {
  .game-container {
    width:
      calc(100vw - 14px);

    padding:
      15px 10px;
  }

  .board {
    width:
      100%;

    gap:
      6px;
  }

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

  .difficulty-selector {
    gap:
      5px;
  }

  .difficulty-label {
    font-size:
      0.68rem;
  }

  .diff-btn {
    font-size:
      0.64rem;

    padding:
      6px 2px;
  }
}

@media (max-width: 360px) {
  .game-container {
    width:
      calc(100vw - 10px);

    padding:
      12px 8px;

    gap:
      10px;

    border-radius:
      16px;
  }

  .game-title {
    font-size:
      1.7rem;
  }

  .mode-btn {
    font-size:
      0.63rem;
  }

  .difficulty-selector {
    flex-direction:
      column;

    align-items:
      stretch;
  }

  .difficulty-label {
    text-align:
      center;
  }

  .board {
    width:
      100%;

    gap:
      5px;
  }

  .cell {
    font-size:
      clamp(
        1.45rem,
        16vw,
        2.5rem
      );
  }

  .restart-btn {
    min-height:
      44px;
  }
}

@media (max-width: 300px) {
  .mode-selector {
    grid-template-columns:
      1fr;
  }

  .board {
    gap:
      4px;
  }

  .cell {
    font-size:
      1.35rem;
  }
}