:root {
  --bg1: #0f172a;
  --bg2: #1d4ed8;
  --panel: rgba(15, 23, 42, 0.82);
  --soft: rgba(255, 255, 255, 0.09);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --x: #fb7185;
  --o: #38bdf8;
  --accent: #8b5cf6;
  --cell: #ffffff;
  --ink: #0f172a;
}

body.light {
  --bg1: #dbeafe;
  --bg2: #e9d5ff;
  --panel: rgba(255, 255, 255, 0.86);
  --soft: rgba(15, 23, 42, 0.07);
  --text: #0f172a;
  --muted: #475569;
}

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

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;

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

  padding: 35px 20px 60px;

  overflow-x: hidden;

  font-family: Arial, sans-serif;

  color: var(--text);

  background:
    radial-gradient(
      circle at top left,
      rgba(139, 92, 246, 0.5),
      transparent 35%
    ),
    linear-gradient(
      135deg,
      var(--bg1),
      var(--bg2)
    );

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
}

.hidden {
  display: none !important;
}


/* =========================
   CONFETTI
========================= */

#confetti {
  position: fixed;
  inset: 0;

  width: 100%;
  height: 100%;

  pointer-events: none;

  z-index: 10;
}


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

.game {
  width: min(100%, 560px);

  margin: 0 auto;

  padding: 28px;

  border-radius: 28px;

  background: var(--panel);

  box-shadow:
    0 25px 60px
    rgba(0, 0, 0, 0.35);

  backdrop-filter: blur(18px);
}


/* =========================
   HEADER
========================= */

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;

  gap: 16px;

  margin-bottom: 20px;
}

header small {
  color: var(--muted);

  font-weight: 800;

  letter-spacing: 0.18em;
}

h1 {
  margin-top: 4px;

  font-size: clamp(
    2rem,
    7vw,
    3rem
  );
}

h1 span {
  color: #c4b5fd;
}

.tools {
  display: flex;
  gap: 8px;
}

.tools button {
  width: 44px;
  height: 44px;

  border-radius: 13px;

  color: var(--text);

  background: var(--soft);

  font-size: 1.2rem;
}


/* =========================
   GAME MODE
========================= */

.game-mode-section {
  margin-bottom: 20px;

  padding: 15px;

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

  border-radius: 18px;

  background:
    rgba(255, 255, 255, 0.04);
}

.mode-label {
  margin-bottom: 10px;

  color: var(--muted);

  font-size: 0.78rem;

  font-weight: 800;

  text-transform: uppercase;

  letter-spacing: 0.12em;
}

.game-mode-selector {
  display: grid;

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

  gap: 10px;
}

.mode-button {
  padding: 12px 14px;

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

  border-radius: 13px;

  color: var(--muted);

  background:
    rgba(255, 255, 255, 0.06);

  font-weight: 800;

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

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

  color: var(--text);
}

.mode-button.active {
  color: #ffffff;

  border-color:
    rgba(139, 92, 246, 0.65);

  background:
    linear-gradient(
      135deg,
      #8b5cf6,
      #38bdf8
    );

  box-shadow:
    0 8px 20px
    rgba(139, 92, 246, 0.22);
}


/* =========================
   JARVIS DIFFICULTY
========================= */

.jarvis-difficulty {
  margin-top: 14px;

  padding-top: 14px;

  border-top:
    1px solid
    rgba(255, 255, 255, 0.1);
}

.jarvis-difficulty > span {
  display: block;

  margin-bottom: 10px;

  color: var(--muted);

  font-size: 0.78rem;

  font-weight: 800;

  text-transform: uppercase;

  letter-spacing: 0.12em;
}

.difficulty-buttons {
  display: grid;

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

  gap: 8px;

  margin-bottom: 12px;
}

.ttt-difficulty {
  padding: 10px 8px;

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

  border-radius: 11px;

  color: var(--muted);

  background:
    rgba(255, 255, 255, 0.06);

  font-size: 0.85rem;

  font-weight: 800;

  transition:
    transform 0.18s ease,
    background 0.18s ease,
    color 0.18s ease;
}

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

  color: var(--text);
}

.ttt-difficulty.active {
  color: #0f172a;

  background:
    linear-gradient(
      135deg,
      #c4b5fd,
      #67e8f9
    );

  box-shadow:
    0 8px 18px
    rgba(56, 189, 248, 0.15);
}


/* =========================
   JARVIS MESSAGE
========================= */

.jarvis-message {
  min-height: 44px;

  padding: 11px 13px;

  display: flex;
  align-items: center;

  border:
    1px solid
    rgba(56, 189, 248, 0.2);

  border-radius: 13px;

  color: #dbeafe;

  background:
    linear-gradient(
      135deg,
      rgba(56, 189, 248, 0.08),
      rgba(139, 92, 246, 0.08)
    );

  font-size: 0.84rem;

  line-height: 1.45;
}


/* =========================
   PLAYER NAMES
========================= */

.names {
  display: grid;

  grid-template-columns:
    1fr 1fr auto;

  gap: 10px;

  align-items: end;

  margin-bottom: 18px;
}

.names label {
  color: var(--muted);

  font-size: 0.8rem;

  font-weight: 700;
}

.names input {
  width: 100%;

  margin-top: 6px;

  padding: 11px;

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

  border-radius: 12px;

  outline: none;

  color: var(--text);

  background: var(--soft);
}

.names input:focus {
  border-color:
    rgba(139, 92, 246, 0.65);
}

.names button {
  padding: 12px 15px;

  border-radius: 12px;

  color: #ffffff;

  background:
    linear-gradient(
      135deg,
      #8b5cf6,
      #a855f7
    );

  font-weight: 800;
}


/* =========================
   SCOREBOARD
========================= */

.scores {
  display: grid;

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

  gap: 10px;

  margin-bottom: 18px;
}

.scores article {
  padding: 14px 8px;

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

  border-radius: 16px;

  text-align: center;

  background: var(--soft);

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

.scores span,
.scores small {
  display: block;

  color: var(--muted);
}

.scores span {
  overflow: hidden;

  font-weight: 700;

  white-space: nowrap;

  text-overflow: ellipsis;
}

.scores strong {
  display: block;

  margin: 5px 0;

  font-size: 1.8rem;
}

.scores small {
  font-size: 0.7rem;
}

body.jarvis-mode
.scores article:last-child {
  border-color:
    rgba(56, 189, 248, 0.35);

  box-shadow:
    0 0 20px
    rgba(56, 189, 248, 0.08);
}


/* =========================
   INFO
========================= */

.info {
  display: flex;

  justify-content: space-between;

  align-items: center;

  gap: 15px;

  margin-bottom: 14px;

  font-weight: 800;
}

.info p {
  min-width: 0;
}

.info div {
  flex: 0 0 auto;

  padding: 7px 11px;

  border-radius: 999px;

  background: var(--soft);
}

.warning {
  animation:
    pulse
    0.7s
    infinite;
}


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

.board {
  display: grid;

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

  gap: 10px;

  margin-bottom: 22px;
}

.cell {
  aspect-ratio: 1;

  border-radius: 18px;

  color: var(--ink);

  background: var(--cell);

  font-size:
    clamp(
      2.8rem,
      13vw,
      5rem
    );

  font-weight: 900;

  box-shadow:
    inset
    0 -5px 0
    rgba(15, 23, 42, 0.08);

  transition:
    transform 0.16s ease,
    opacity 0.16s ease;
}

.cell:hover:not(:disabled) {
  transform:
    translateY(-3px)
    scale(1.02);
}

.cell.x {
  color: var(--x);
}

.cell.o {
  color: var(--o);
}

.cell.pop {
  animation:
    pop
    0.22s;
}

.cell.winner {
  background: #fde68a;

  animation:
    glow
    0.8s
    infinite
    alternate;
}

body.jarvis-thinking
.board {
  opacity: 0.82;
}

body.jarvis-thinking
.cell:not(:disabled) {
  cursor: wait;
}


/* =========================
   ACTION BUTTONS
========================= */

.actions {
  display: flex;

  gap: 12px;
}

.actions button {
  flex: 1;

  padding: 12px 15px;

  border-radius: 12px;

  color: #ffffff;

  background: var(--accent);

  font-weight: 800;
}

.actions #reset {
  background: #ef4444;
}


/* =========================
   NOTE
========================= */

.note {
  margin-top: 14px;

  color: var(--muted);

  text-align: center;

  font-size: 0.76rem;
}


/* =========================
   BACK BUTTON
========================= */

.back-button {
  position: fixed;

  top: 20px;
  left: 20px;

  z-index: 1000;

  display: inline-block;

  padding: 12px 18px;

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

  border-radius: 12px;

  color: #06101d;

  background:
    linear-gradient(
      135deg,
      #5cf2ff,
      #82ffb4
    );

  font-weight: bold;

  text-decoration: none;

  box-shadow:
    0 10px 25px
    rgba(0, 0, 0, 0.22);

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.back-button:hover {
  transform:
    translateY(-3px);

  box-shadow:
    0 14px 30px
    rgba(0, 0, 0, 0.3);
}


/* =========================
   LIGHT MODE
========================= */

body.light
.game-mode-section {
  border-color:
    rgba(15, 23, 42, 0.1);
}

body.light
.mode-button,
body.light
.ttt-difficulty {
  color: #475569;

  border-color:
    rgba(15, 23, 42, 0.08);

  background:
    rgba(15, 23, 42, 0.05);
}

body.light
.jarvis-message {
  color: #334155;

  border-color:
    rgba(56, 189, 248, 0.22);
}


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

@keyframes pop {
  0% {
    transform:
      scale(0.5);

    opacity: 0;
  }

  80% {
    transform:
      scale(1.08);
  }

  100% {
    transform:
      scale(1);

    opacity: 1;
  }
}

@keyframes pulse {
  50% {
    transform:
      scale(1.08);
  }
}

@keyframes glow {
  to {
    box-shadow:
      0 0 28px
      rgba(253, 230, 138, 0.95);
  }
}


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

@media (max-width: 700px) {
  .back-button {
    position: static;

    align-self: flex-start;

    margin-bottom: 15px;
  }

  body {
    flex-direction: column;

    align-items: center;

    padding-top: 20px;
  }
}

@media (max-width: 560px) {
  body {
    padding:
      20px
      12px
      50px;
  }

  .game {
    padding:
      21px
      16px;
  }

  .game-mode-selector {
    grid-template-columns:
      1fr;
  }

  .difficulty-buttons {
    grid-template-columns:
      1fr;
  }

  .names {
    grid-template-columns:
      1fr 1fr;
  }

  .names button {
    grid-column:
      1 / -1;
  }

  .jarvis-message {
    font-size: 0.8rem;
  }
}

@media (max-width: 400px) {
  .scores small {
    display: none;
  }

  .actions {
    flex-direction: column;
  }

  .info {
    align-items: flex-start;

    flex-direction: column;
  }
}