/* ==========================================================================
   إكس أو — تيك تاك تو
   واجهة داكنة بلمسات نيون، بدون أي مكتبات خارجية.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --x: #45e6ff;
  --x-glow: rgba(69, 230, 255, 0.55);
  --o: #ff6fae;
  --o-glow: rgba(255, 111, 174, 0.55);
  --ink: #eef4ff;
  --muted: #93a4c7;
  --line: rgba(255, 255, 255, 0.1);
  --ease: cubic-bezier(0.22, 0.9, 0.32, 1);
  --radius-lg: 30px;
  --radius-md: 18px;
  --font: "Cairo", "Segoe UI", Tahoma, "Noto Kufi Arabic", system-ui, -apple-system, sans-serif;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(14px, 4vw, 40px);
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--font);
  background-color: #070b18;
  background-image:
    radial-gradient(1200px 700px at 15% -10%, rgba(31, 48, 96, 0.65), transparent 60%),
    radial-gradient(1000px 600px at 90% 110%, rgba(64, 27, 66, 0.5), transparent 60%);
}

/* ---------- خلفية متحركة ---------- */

.aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.aurora__blob {
  position: absolute;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(72px);
  opacity: 0.42;
  will-change: transform;
}

.aurora__blob--cyan {
  top: -26vmax;
  right: -18vmax;
  background: radial-gradient(circle at center, rgba(69, 230, 255, 0.55), transparent 62%);
  animation: drift-a 19s var(--ease) infinite alternate;
}

.aurora__blob--pink {
  bottom: -30vmax;
  left: -20vmax;
  background: radial-gradient(circle at center, rgba(255, 111, 174, 0.45), transparent 62%);
  animation: drift-b 23s var(--ease) infinite alternate;
}

.aurora__blob--violet {
  top: 24vh;
  left: 34vw;
  width: 44vmax;
  height: 44vmax;
  background: radial-gradient(circle at center, rgba(150, 120, 255, 0.4), transparent 62%);
  animation: drift-c 27s var(--ease) infinite alternate;
}

@keyframes drift-a {
  to {
    transform: translate3d(-6vmax, 8vmax, 0) scale(1.12);
  }
}

@keyframes drift-b {
  to {
    transform: translate3d(7vmax, -6vmax, 0) scale(1.16);
  }
}

@keyframes drift-c {
  to {
    transform: translate3d(-8vmax, -4vmax, 0) scale(0.92);
  }
}

/* ---------- الحاوية والبطاقة ---------- */

.stage {
  width: 100%;
  max-width: 470px;
}

.app {
  position: relative;
  width: 100%;
  padding: clamp(18px, 4.6vw, 28px);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(24, 32, 60, 0.86), rgba(11, 16, 32, 0.94));
  box-shadow:
    0 44px 90px -46px rgba(0, 0, 0, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.app__head {
  text-align: center;
}

.app__badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.app__title {
  margin: 0;
  font-size: clamp(2rem, 7.4vw, 2.7rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.5px;
  background: linear-gradient(100deg, var(--x), #b9acff 52%, var(--o));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.app__sub {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- تبويبات الوضع ---------- */

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 20px 0 12px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(6, 10, 22, 0.66);
}

.tab {
  appearance: none;
  border: 0;
  border-radius: 13px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition:
    color 0.2s var(--ease),
    background 0.25s var(--ease),
    box-shadow 0.25s var(--ease),
    transform 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.tab:hover {
  color: var(--ink);
}

.tab:active {
  transform: scale(0.98);
}

.tab.is-active {
  color: #05121f;
  background: linear-gradient(135deg, var(--x), #8ef0ff 46%, #bdaaff);
  box-shadow: 0 10px 24px -14px var(--x-glow);
}

/* ---------- مستويات الصعوبة ---------- */

.levels {
  display: flex;
  gap: 8px;
  margin: 0 0 6px;
}

.chip {
  flex: 1;
  appearance: none;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition:
    color 0.2s var(--ease),
    border-color 0.2s var(--ease),
    background 0.2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.22);
}

.chip.is-active {
  color: var(--ink);
  border-color: rgba(69, 230, 255, 0.45);
  background: rgba(69, 230, 255, 0.12);
}

.levels__hint {
  min-height: 1.2em;
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 0.73rem;
}

/* ---------- لوحة النقاط ---------- */

.scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0 14px;
}

.score {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "mark name"
    "value value";
  align-items: center;
  gap: 2px 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.035);
  transition:
    border-color 0.25s var(--ease),
    background 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
}

.score__mark {
  grid-area: mark;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
}

.score__name {
  grid-area: name;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.score__value {
  grid-area: value;
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.score--x .score__mark {
  color: var(--x);
}

.score--o .score__mark {
  color: var(--o);
}

.score--draw .score__mark {
  color: var(--muted);
}

.score--x.is-turn {
  border-color: rgba(69, 230, 255, 0.4);
  background: rgba(69, 230, 255, 0.09);
}

.score--o.is-turn {
  border-color: rgba(255, 111, 174, 0.4);
  background: rgba(255, 111, 174, 0.09);
}

/* ---------- شريط الحالة ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(7, 12, 26, 0.62);
  font-size: 0.92rem;
  font-weight: 700;
  transition: border-color 0.25s var(--ease);
}

.status__text {
  overflow: hidden;
}

.status__dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--x);
  box-shadow: 0 0 12px var(--x-glow);
  animation: dot-pulse 1.9s ease-in-out infinite;
}

.status--x .status__dot {
  background: var(--x);
  box-shadow: 0 0 12px var(--x-glow);
}

.status--o .status__dot {
  background: var(--o);
  box-shadow: 0 0 12px var(--o-glow);
}

.status--draw .status__dot {
  background: var(--muted);
  box-shadow: none;
  animation: none;
}

@keyframes dot-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(0.82);
  }
}

.mk {
  font-weight: 800;
}

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

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

/* ---------- اللوحة ---------- */

.board-wrap {
  position: relative;
  width: min(100%, 400px);
  margin: 14px auto 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.4vw, 14px);
  aspect-ratio: 1 / 1;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: clamp(13px, 3.4vw, 20px);
  background:
    radial-gradient(120% 120% at 20% 0%, rgba(255, 255, 255, 0.075), transparent 60%),
    rgba(255, 255, 255, 0.025);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 14px 26px -20px #000;
  cursor: pointer;
  transition:
    transform 0.16s var(--ease),
    border-color 0.2s var(--ease),
    background 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.is-filled) {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.2);
}

.cell:active:not(.is-filled) {
  transform: scale(0.97);
}

.cell:focus-visible {
  outline: 2px solid var(--x);
  outline-offset: 2px;
}

/* المعاينة الشبحية لعلامة الدور الحالي */

.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(2rem, 8.4vw, 3.2rem);
  font-weight: 600;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s var(--ease);
}

.board[data-turn="X"] .cell:not(.is-filled):hover::after,
.board[data-turn="X"] .cell:not(.is-filled):focus-visible::after {
  content: "✕";
  color: var(--x);
  opacity: 0.16;
}

.board[data-turn="O"] .cell:not(.is-filled):hover::after,
.board[data-turn="O"] .cell:not(.is-filled):focus-visible::after {
  content: "◯";
  color: var(--o);
  opacity: 0.18;
}

.board.is-over .cell::after {
  opacity: 0 !important;
}

.board.is-locked .cell {
  pointer-events: none;
}

/* العلامات */

.mark {
  width: 62%;
  height: 62%;
  overflow: visible;
}

.mark line,
.mark path {
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: stroke-draw 0.3s var(--ease) forwards;
}

.mark--x line {
  stroke: var(--x);
  filter: drop-shadow(0 0 10px var(--x-glow));
}

.mark--x line:nth-child(2) {
  animation-delay: 0.11s;
}

.mark--o path {
  stroke: var(--o);
  stroke-width: 8.5;
  filter: drop-shadow(0 0 12px var(--o-glow));
}

@keyframes stroke-draw {
  to {
    stroke-dashoffset: 0;
  }
}

.cell.is-win {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.1);
  animation: win-bounce 0.5s var(--ease);
  box-shadow:
    inset 0 0 24px rgba(255, 255, 255, 0.12),
    0 0 30px -6px rgba(255, 255, 255, 0.2);
}

@keyframes win-bounce {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.055);
  }
  100% {
    transform: scale(1);
  }
}

/* خط الفوز فوق اللوحة */

.win-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.win-line path {
  fill: none;
  stroke: #fff;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  vector-effect: non-scaling-stroke;
}

.win-line path.is-on {
  opacity: 1;
  animation: stroke-draw 0.42s 0.1s var(--ease) forwards;
}

.win-line path.is-x {
  stroke: var(--x);
  filter: drop-shadow(0 0 9px var(--x-glow));
}

.win-line path.is-o {
  stroke: var(--o);
  filter: drop-shadow(0 0 9px var(--o-glow));
}

/* ---------- الأزرار ---------- */

.actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 0.15s var(--ease),
    box-shadow 0.2s var(--ease),
    background 0.2s var(--ease),
    border-color 0.2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

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

.btn--primary {
  flex: 1.4;
  padding: 12px 16px;
  color: #05121f;
  background: linear-gradient(135deg, var(--x), #8ef0ff 46%, #c2b1ff);
  box-shadow: 0 16px 30px -18px var(--x-glow);
}

.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px -16px var(--x-glow);
}

.btn--ghost {
  flex: 1;
  padding: 12px 14px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.btn--ghost:hover {
  background: rgba(255, 255, 255, 0.09);
}

.btn--icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  padding: 0;
  font-size: 1.05rem;
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.btn--icon:hover {
  background: rgba(255, 255, 255, 0.09);
}

.btn--icon[aria-pressed="false"] {
  opacity: 0.55;
}

.btn--primary.is-pulse {
  animation: attention 1.1s var(--ease);
}

@keyframes attention {
  0%,
  100% {
    transform: none;
  }
  35% {
    transform: translateY(-2px) scale(1.02);
  }
  70% {
    transform: translateY(0) scale(0.995);
  }
}

/* ---------- التذييل والرقائق ---------- */

.footnote {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 0.71rem;
  text-align: center;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.68rem;
  line-height: 1.4;
}

/* ---------- القصاصات (Confetti) ---------- */

.confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- الشاشات الصغيرة ---------- */

[hidden] {
  display: none !important;
}

@media (max-width: 380px) {
  .score {
    padding: 8px 9px;
  }

  .score__name {
    font-size: 0.6rem;
  }

  .actions {
    flex-wrap: wrap;
  }

  .btn--primary {
    flex: 1 1 100%;
    order: -1;
  }
}

@media (max-height: 760px) {
  body {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .app {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .board-wrap {
    width: min(100%, 330px);
  }

  .scores {
    margin: 12px 0 10px;
  }
}

/* ---------- احترام تقليل الحركة ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
