* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
}
:root {
  --primary: #4f46e5;
  --secondary: #06b6d4;
  --success: #22c55e;
  --danger: #ef4444;
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: rgba(255, 255, 255, 0.08);
  --text: #fff;
  --text-light: #cbd5e1;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 15px 35px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --speed: 0.18s;
}
/* Light Mode */
body.light {
  --bg: #d9e9ff;
  --bg2: #b8d6ff;
  --card: #f1fafd;
  --text: #0f172a;
  --text-light: #475569;
  --border: #c5d4e8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
body.light .wrapper {
  background: var(--card);
  border: 1px solid var(--border);
}
body.light .score-card,
body.light #turn,
body.light .box {
  background: #ffffff;
}
body.light .turn-x,
body.light .player-x {
  color: #2563eb;
}
body.light .turn-o,
body.light .player-o {
  color: #ea580c;
}
body.light .popup-content {
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
body.light #msg {
  color: #08e85a;
}
/* Body */
body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  font-family: "Poppins", sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg), var(--bg2));
  transition: 0.25s;
}
/* Wrapper */
.wrapper {
  width: 100%;
  max-width: 680px;
  padding: 35px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  transition: 0.25s;
}
/* Header */
header {
  position: relative;
  text-align: center;
  margin-bottom: 30px;
}
header h1 {
  font-size: 2.4rem;
  font-weight: 700;
  text-align: center;
}
.subtitle {
  margin-top: 10px;
  color: var(--text-light);
}
/* Theme Button */
#theme-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  transition: var(--speed);
}
#theme-btn:hover {
  transform: rotate(20deg) scale(1.06);
}
/* Hide */
.hide {
  display: none !important;
}
/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  margin-bottom: 25px;
}
.score-card {
  padding: 18px;
  text-align: center;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  transition: var(--speed);
}
.score-card:hover {
  transform: translateY(-4px);
}
.score-card h2 {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 10px;
}
.score-card span {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}
/* Current Turn */
.status {
  text-align: center;
  margin-bottom: 28px;
}
#turn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 50px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-light);
}
.turn-x {
  color: #38bdf8;
}
.turn-o {
  color: #fb923c;
}
#turn span {
  font-weight: 700;
  margin-left: 6px;
  font-size: 1.1rem;
}
/* Game */
.container {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}
.game {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: min(92vw, 420px);
}
/* Boxes */
.box {
  aspect-ratio: 1;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
  font-size: clamp(2.8rem, 8vw, 4rem);
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    background 0.25s ease,
    border-color 0.25s ease;
}
.box:hover:not(:disabled) {
  transform: translateY(-3px);
  border-color: #38bdf8;
  box-shadow: 0 6px 15px rgba(56, 189, 248, 0.18);
}
.box:active:not(:disabled) {
  transform: scale(0.96);
}
.box:disabled {
  cursor: default;
}
.player-x {
  color: #38bdf8;
}
.player-o {
  color: #fb923c;
}
/* Winner */
.winner {
  color: var(--success);
  border: 2px solid var(--success);
  animation: winnerGlow 0.6s infinite alternate;
}
@keyframes winnerGlow {
  from {
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.35);
  }
  to {
    box-shadow: 0 0 22px rgba(34, 197, 94, 0.9);
  }
}
/* Buttons */
.buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  flex-wrap: wrap;
}
.buttons button,
#play-again-btn {
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 10px 25px rgba(79, 70, 229, 0.35);
  transition: var(--speed);
}
.buttons button:hover,
#play-again-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 28px rgba(79, 70, 229, 0.45);
}
.buttons button:active,
#play-again-btn:active {
  transform: scale(0.96);
}
/* Popup */
.popup {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  z-index: 999;
}
.popup-content {
  width: min(90%, 380px);
  padding: 35px 30px;
  text-align: center;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: popup 0.22s ease;
}
#msg {
  margin-bottom: 25px;
  font-size: 2rem;
  color: var(--success);
}
@keyframes popup {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
/* Selection */
::selection {
  background: var(--secondary);
  color: #fff;
}
/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--secondary);
}
/* Tablet */
@media (max-width: 768px) {
  .wrapper {
    padding: 25px;
  }
  header h1 {
    font-size: 2rem;
  }
  .subtitle {
    font-size: 0.9rem;
  }
  .scoreboard {
    gap: 10px;
  }
  .score-card {
    padding: 15px;
  }
  .score-card span {
    font-size: 1.7rem;
  }
  .game {
    width: min(95vw, 370px);
    gap: 12px;
  }
  .buttons {
    flex-direction: column;
  }
  .buttons button {
    width: 100%;
  }
  #theme-btn {
    width: 44px;
    height: 44px;
  }
}
/* Mobile */
@media (max-width: 480px) {
  body {
    padding: 15px;
  }
  .wrapper {
    padding: 20px;
  }
  header h1 {
    font-size: 1.8rem;
    text-align: center;
  }
  .subtitle {
    text-align: center;
    font-size: 0.85rem;
  }
  #theme-btn {
    width: 42px;
    height: 42px;
    font-size: 1rem;
    top: 0;
    right: 0;
  }
  .scoreboard {
    grid-template-columns: 1fr;
  }
  #turn {
    width: 100%;
    justify-content: center;
  }
  .game {
    width: 100%;
    gap: 10px;
  }
  .box {
    border-radius: 14px;
  }
  .popup-content {
    padding: 28px 20px;
  }
  #msg {
    font-size: 1.5rem;
  }
}
/* Small Mobile */
@media (max-width: 400px) {
  .wrapper {
    padding: 18px;
  }
  header h1 {
    font-size: 1.5rem;
  }
  .subtitle {
    font-size: 0.8rem;
  }
  #theme-btn {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
    top: 0;
    right: 0;
  }
  .score-card span {
    font-size: 1.6rem;
  }
  #turn {
    padding: 10px 16px;
    font-size: 0.9rem;
  }
  #turn span {
    font-size: 1rem;
  }
  .game {
    gap: 8px;
  }
  .buttons button,
  #play-again-btn {
    padding: 12px 20px;
    font-size: 0.95rem;
  }
  #msg {
    font-size: 1.35rem;
  }
}
@media (max-width: 350px) {
  body {
    padding: 12px;
  }
  .wrapper {
    padding: 17px;
  }
  header h1 {
    font-size: 1.3rem;
  }
  .subtitle {
    font-size: 0.7rem;
  }
  #theme-btn {
    width: 34px;
    height: 34px;
    font-size: 0.8rem;
    top: 0;
    right: 0;
  }
  .score-card {
    padding: 12px;
  }
  .score-card h2 {
    font-size: 0.85rem;
  }
  .score-card span {
    font-size: 1.5rem;
  }
  #turn {
    padding: 9px 14px;
    font-size: 0.85rem;
  }
  #turn span {
    font-size: 0.95rem;
  }
  .game {
    gap: 8px;
  }
  .box {
    border-radius: 12px;
    font-size: clamp(2.2rem, 9vw, 3rem);
  }
  .buttons button,
  #play-again-btn {
    padding: 11px 16px;
    font-size: 0.9rem;
  }
  .popup-content {
    padding: 24px 18px;
  }
  #msg {
    font-size: 1.3rem;
  }
}
@media (max-width: 300px) {
  header {
    padding-top: 40px;
  }
  #theme-btn {
    top: 0;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
  #theme-btn:hover {
    transform: translateX(-50%) rotate(20deg) scale(1.06);
  }
  header h1 {
    font-size: 1.2rem;
    margin-bottom: 4px;
  }
  .subtitle {
    font-size: 0.65rem;
    margin-top: 4px;
  }
}
/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
