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

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --cell: #334155;
  --cell-hover: #475569;
  --x: #38bdf8;
  --o: #fb7185;
  --text: #e2e8f0;
  --accent: #818cf8;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Intro splash --------------------------------------------------- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1e293b 0%, var(--bg) 70%);
  transition: opacity 0.5s ease;
}

.intro.hide {
  opacity: 0;
  pointer-events: none;
}

.intro-signs {
  display: flex;
  gap: clamp(10px, 4vw, 28px);
}

.intro-sign {
  font-size: clamp(3rem, 16vw, 6rem);
  font-weight: 800;
  line-height: 1;
  animation: sign-drop 0.8s cubic-bezier(0.18, 0.9, 0.3, 1.35) backwards;
}

.intro-sign.s1 { color: var(--x); animation-delay: 0.05s; }
.intro-sign.s2 { color: var(--o); animation-delay: 0.2s; }
.intro-sign.s3 { color: #fbbf24; animation-delay: 0.35s; }
.intro-sign.s4 { color: var(--accent); animation-delay: 0.5s; }

@keyframes sign-drop {
  0% {
    transform: translateY(-140%) rotate(-540deg) scale(0);
    opacity: 0;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translateY(0) rotate(0) scale(1);
    opacity: 1;
  }
}

.intro-title {
  margin-top: 20px;
  font-size: 2rem;
  letter-spacing: 2px;
  opacity: 0;
  animation: intro-rise 0.6s ease forwards 1.15s;
}

.intro-hint {
  margin-top: 10px;
  font-size: 0.85rem;
  opacity: 0;
  letter-spacing: 1px;
  animation: intro-blink 1.6s ease-in-out infinite 1.6s;
}

@keyframes intro-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes intro-blink {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.7; }
}

.app {
  text-align: center;
  padding: 24px;
  width: 100%;
  max-width: 380px;
}

h1 {
  font-size: 2rem;
  margin-bottom: 18px;
  letter-spacing: 1px;
}

.modes {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.mode-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--cell);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s;
}

.mode-btn:hover {
  background: var(--cell);
}

.mode-btn.active {
  border-color: var(--accent);
  background: var(--cell);
}

.sign-config {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 16px;
}

.sign-group {
  flex: 1;
  background: var(--panel);
  border-radius: 10px;
  padding: 8px;
}

.sign-label {
  display: block;
  font-size: 0.8rem;
  opacity: 0.75;
  margin-bottom: 6px;
}

.sign-options {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sign-opt {
  width: 38px;
  height: 38px;
  border: 1px solid var(--cell);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}

.sign-opt:hover:not(:disabled) {
  background: var(--cell);
}

.sign-opt.active {
  border-color: var(--accent);
  background: var(--cell);
}

.sign-opt:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.difficulty {
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.difficulty.hidden {
  display: none;
}

.difficulty label {
  display: block;
  font-size: 0.85rem;
  opacity: 0.85;
  margin-bottom: 8px;
}

.difficulty #diffLabel {
  font-weight: 700;
  opacity: 1;
  color: var(--accent);
}

.difficulty input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.status {
  font-size: 1.1rem;
  margin-bottom: 16px;
  min-height: 1.4em;
  font-weight: 600;
}

.status.result {
  animation: result-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: var(--accent);
}

@keyframes result-bounce {
  0% {
    transform: scale(0.7);
    opacity: 0.2;
  }
  60% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  aspect-ratio: 1 / 1;
  margin-bottom: 20px;
  animation: board-in 0.4s ease both;
}

@keyframes board-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cell {
  background: var(--cell);
  border: none;
  border-radius: 12px;
  font-size: clamp(2.5rem, 14vw, 4rem);
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.05s;
}

.cell:hover:not(.taken) {
  background: var(--cell-hover);
}

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

.mark {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Pop-in when a mark is placed */
.mark.pop {
  animation: pop-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  0% {
    transform: scale(0) rotate(-25deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.25) rotate(6deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

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

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

.cell.win {
  color: #fff;
  animation: win-pulse 0.9s ease-in-out infinite;
  animation-delay: var(--win-delay, 0s);
}

@keyframes win-pulse {
  0%,
  100% {
    background: var(--accent);
    box-shadow: 0 0 0 0 rgba(129, 140, 248, 0.6);
    transform: scale(1);
  }
  50% {
    background: #a5b4fc;
    box-shadow: 0 0 22px 5px rgba(129, 140, 248, 0.85);
    transform: scale(1.06);
  }
}

.scoreboard {
  display: flex;
  justify-content: space-around;
  margin-bottom: 18px;
  font-size: 0.95rem;
}

.scoreboard strong {
  display: block;
  font-size: 1.3rem;
  margin-top: 2px;
}

.reset-btn {
  padding: 12px 28px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: filter 0.15s;
}

.reset-btn:hover {
  filter: brightness(1.1);
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .mark.pop,
  .cell.win,
  .status.result,
  .board,
  .intro-sign,
  .intro-title,
  .intro-hint {
    animation: none !important;
  }

  .intro-title,
  .intro-hint {
    opacity: 1;
  }
}
