:root,
[data-theme="dark"] {
  --bg-1: #060a14;
  --bg-2: #0c1424;

  --glow-blue: rgba(70, 130, 255, 0.22);
  --glow-red: rgba(255, 90, 90, 0.16);

  --glass: rgba(255, 255, 255, 0.045);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --cell-bg: rgba(255, 255, 255, 0.07);

  --border: rgba(255, 255, 255, 0.14);

  --text: #f1f4fb;
  --text-dim: #93a0b8;

  --x-color: #4d9dff;
  --o-color: #ff5c5c;

  --shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
  --bg-1: #eef1f8;
  --bg-2: #dfe5f2;

  --glow-blue: rgba(70, 130, 255, 0.16);
  --glow-red: rgba(255, 90, 90, 0.12);

  --glass: rgba(255, 255, 255, 0.58);
  --glass-strong: rgba(255, 255, 255, 0.8);
  --cell-bg: rgba(255, 255, 255, 0.72);

  --border: rgba(20, 30, 60, 0.12);

  --text: #131a2b;
  --text-dim: #57607a;

  --x-color: #2266dd;
  --o-color: #dd3333;

  --shadow: 0 24px 60px rgba(30, 40, 80, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;

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

  padding: 24px;

  font-family:
    "Inter",
    "Segoe UI",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;

  color: var(--text);

  background:
    radial-gradient(circle at 12% 10%, var(--glow-blue), transparent 45%),
    radial-gradient(circle at 92% 90%, var(--glow-red), transparent 45%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));

  background-attachment: fixed;

  transition:
    background 0.4s ease,
    color 0.4s ease;
}

/* =========================
   THEME TOGGLE
========================= */

.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;

  width: 64px;
  height: 32px;

  padding: 0 7px;

  border: 1px solid var(--border);
  border-radius: 999px;

  background: var(--glass-strong);

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

  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);

  cursor: pointer;

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

  z-index: 100;

  isolation: isolate;

  transition:
    background 0.3s ease,
    border-color 0.3s ease,
    transform 0.2s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
}

.theme-toggle:active {
  transform: scale(0.96);
}

.theme-toggle__icon {
  position: relative;

  font-size: 13px;
  line-height: 1;

  color: var(--text-dim);

  z-index: 2;

  pointer-events: none;
}

.theme-toggle__knob {
  position: absolute;

  top: 3px;
  left: 3px;

  width: 26px;
  height: 26px;

  border-radius: 50%;

  background: linear-gradient(160deg, #4d9dff, #1c3f80);

  box-shadow: 0 0 14px rgba(77, 157, 255, 0.45);

  transition:
    transform 0.3s ease,
    background 0.3s ease,
    box-shadow 0.3s ease;

  pointer-events: none;
}

[data-theme="light"] .theme-toggle__knob {
  transform: translateX(32px);

  background: linear-gradient(160deg, #ffd166, #ff9f43);

  box-shadow: 0 0 12px rgba(255, 180, 60, 0.4);
}

/* =========================
   GAME CARD
========================= */

.game {
  position: relative;
  z-index: 10;

  width: 100%;
  max-width: 440px;

  padding: 46px 38px 38px;

  border-radius: 32px;

  background: var(--glass);

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

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

  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);

  text-align: center;

  transition:
    background 0.4s ease,
    border-color 0.4s ease,
    box-shadow 0.4s ease;
}

/* subtle glass highlight */
.game::before {
  content: "";

  position: absolute;

  inset: 0;

  border-radius: inherit;

  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08),
    transparent 35%
  );

  pointer-events: none;
}

/* =========================
   TITLE
========================= */

h1 {
  position: relative;

  margin: 0 0 7px;

  font-size: clamp(34px, 5vw, 42px);

  font-weight: 850;

  letter-spacing: -1.2px;

  line-height: 1.05;

  color: var(--text);
}

.subtitle {
  margin: 0 0 27px;

  font-size: 11px;

  font-weight: 700;

  letter-spacing: 4px;

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

/* =========================
   STATUS
========================= */

.status {
  position: relative;

  margin: 0 auto 28px;

  padding: 11px 20px;

  width: fit-content;

  border-radius: 999px;

  display: inline-flex;
  align-items: center;
  gap: 10px;

  font-size: 14px;
  font-weight: 600;

  color: var(--text);

  background: var(--glass-strong);

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

  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);

  transition:
    color 0.25s ease,
    background 0.25s ease,
    box-shadow 0.25s ease;
}

.status::before {
  content: "";

  width: 9px;
  height: 9px;

  flex-shrink: 0;

  border-radius: 50%;

  background: var(--x-color);

  box-shadow: 0 0 9px var(--x-color);

  transition:
    background 0.25s ease,
    box-shadow 0.25s ease;
}

.status[data-mark="O"]::before {
  background: var(--o-color);

  box-shadow: 0 0 9px var(--o-color);
}

.status[data-mark=""]::before {
  background: var(--text-dim);

  box-shadow: none;
}

/* =========================
   BOARD
========================= */

.board {
  position: relative;

  z-index: 30;

  display: grid;

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

  gap: 12px;

  margin-bottom: 30px;
}

/* =========================
   CELLS
========================= */

.cell {
  position: relative;

  z-index: 31;

  width: 100%;

  aspect-ratio: 1 / 1;

  padding: 0;

  border-radius: 18px;

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

  background: var(--cell-bg);

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

  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);

  font-family: inherit;

  font-size: clamp(34px, 8vw, 48px);

  font-weight: 750;

  color: var(--text);

  cursor: pointer;

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

  pointer-events: auto;

  overflow: hidden;

  transition:
    transform 0.16s ease,
    background 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

/* Cell highlight */
.cell::before {
  content: "";

  position: absolute;

  inset: 0;

  border-radius: inherit;

  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08),
    transparent 45%
  );

  pointer-events: none;

  z-index: -1;
}

/* Hover */
.cell:hover {
  background: var(--glass-strong);

  border-color: rgba(120, 150, 255, 0.38);

  transform: translateY(-3px);

  box-shadow:
    0 14px 30px rgba(0, 0, 0, 0.28),
    0 0 18px rgba(80, 130, 255, 0.08);
}

/* Press */
.cell:active {
  transform: translateY(0) scale(0.95);
}

/* Keep occupied cells visually stable */
.cell[data-mark="X"],
.cell[data-mark="O"] {
  cursor: default;
}

/* =========================
   X
========================= */

.cell[data-mark="X"] {
  color: var(--x-color);

  text-shadow:
    0 0 18px rgba(77, 157, 255, 0.5),
    0 0 34px rgba(77, 157, 255, 0.2);

  animation: pop 0.22s ease;
}

/* =========================
   O
========================= */

.cell[data-mark="O"] {
  color: var(--o-color);

  text-shadow:
    0 0 18px rgba(255, 92, 92, 0.5),
    0 0 34px rgba(255, 92, 92, 0.2);

  animation: pop 0.22s ease;
}

/* =========================
   WINNING CELLS
========================= */

.cell.win {
  border-color: currentColor;

  box-shadow:
    0 0 24px currentColor,
    inset 0 1px 0 rgba(255, 255, 255, 0.1);

  animation:
    pop 0.22s ease,
    glow 1.6s ease-in-out infinite;
}

/* =========================
   RESTART
========================= */

.restart {
  position: relative;

  z-index: 40;

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

  background: var(--glass-strong);

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

  color: var(--text);

  font-family: inherit;

  font-size: 14px;

  font-weight: 700;

  letter-spacing: 0.2px;

  padding: 13px 30px;

  border-radius: 999px;

  cursor: pointer;

  box-shadow:
    0 9px 25px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);

  transition:
    transform 0.15s ease,
    background 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.restart:hover {
  transform: translateY(-2px);

  border-color: rgba(120, 150, 255, 0.35);

  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.32),
    0 0 18px rgba(80, 130, 255, 0.08);
}

.restart:active {
  transform: translateY(0) scale(0.97);
}

/* =========================
   ANIMATIONS
========================= */

@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes glow {
  0%,
  100% {
    box-shadow:
      0 0 14px currentColor,
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }

  50% {
    box-shadow:
      0 0 30px currentColor,
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }
}

/* =========================
   MOBILE
========================= */

@media (max-width: 460px) {
  body {
    padding: 18px;
  }

  .game {
    max-width: 100%;

    padding: 34px 22px 28px;

    border-radius: 26px;
  }

  h1 {
    font-size: 32px;
  }

  .subtitle {
    font-size: 9px;

    letter-spacing: 3px;

    margin-bottom: 24px;
  }

  .status {
    margin-bottom: 24px;

    font-size: 13px;

    padding: 10px 17px;
  }

  .board {
    gap: 9px;

    margin-bottom: 26px;
  }

  .cell {
    border-radius: 15px;

    font-size: 36px;
  }

  .theme-toggle {
    top: 16px;
    right: 16px;
  }
}
