/* ============ XO Pro — Professional Tic Tac Toe ============ */
:root {
  --bg-1: #0d1024;
  --bg-2: #191e3c;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #eef1ff;
  --text-dim: #9aa3c7;
  --x-color: #4dd7fe;
  --o-color: #ff7ab8;
  --accent: #7c5cff;
  --accent-2: #5cc8ff;
  --win: #3ddc85;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg-1);
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg-1);
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 14px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  overflow-x: hidden;
}

/* Fixed background layer — always covers the full screen on every
   device, never leaves gaps or stretches while scrolling */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1100px 700px at 15% -10%, rgba(124, 92, 255, 0.28), transparent 60%),
    radial-gradient(1000px 700px at 110% 110%, rgba(255, 122, 184, 0.2), transparent 60%),
    radial-gradient(700px 500px at -10% 100%, rgba(92, 200, 255, 0.12), transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  pointer-events: none;
}

/* Slow drifting glow orb for depth */
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 46vmax;
  height: 46vmax;
  top: -18vmax;
  left: -14vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(92, 200, 255, 0.10), transparent 68%);
  animation: orbDrift 22s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes orbDrift {
  to { transform: translate(55vw, 50vh) scale(1.2); }
}

button, a { touch-action: manipulation; }

/* Celebration canvas */
#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 120;
  pointer-events: none;
}

/* ==================== GAME SHELL ==================== */
.game-shell {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.8vh, 18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  font-size: clamp(26px, 3.4vmin, 36px);
  font-weight: 800;
  letter-spacing: 1px;
  user-select: none;
  -webkit-user-select: none;
}
.logo-x { color: var(--x-color); text-shadow: 0 0 18px rgba(77, 215, 254, 0.6); }
.logo-o { color: var(--o-color); text-shadow: 0 0 18px rgba(255, 122, 184, 0.6); }
.logo-text {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 20px;
  vertical-align: middle;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--accent-2); }
.icon-btn:active { transform: scale(0.94); }

.mode-switch, .diff-switch {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.mode-btn, .diff-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: inherit;
}
.mode-btn.active, .diff-btn.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(124, 92, 255, 0.45);
}
.mode-btn:not(.active):hover, .diff-btn:not(.active):hover { color: var(--text); }

.difficulty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.difficulty-row.hidden { display: none; }
.diff-label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.diff-btn { padding: 6px 12px; font-size: 12px; }

/* ==================== SCOREBOARD ==================== */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.score-card--x .score-value { color: var(--x-color); }
.score-card--o .score-value { color: var(--o-color); }
.score-card--draw .score-value { color: var(--text-dim); }

.score-card.turn {
  border-color: currentColor;
  transform: translateY(-3px);
}
.score-card--x.turn { box-shadow: 0 8px 24px rgba(77, 215, 254, 0.25); border-color: var(--x-color); }
.score-card--o.turn { box-shadow: 0 8px 24px rgba(255, 122, 184, 0.25); border-color: var(--o-color); }

.score-name {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.score-value { font-size: clamp(20px, 2.8vmin, 30px); font-weight: 800; }

/* Status pill */
.status {
  margin: 0 auto;
  width: fit-content;
  max-width: 100%;
  padding: 8px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.status b { color: var(--text); }

/* ==================== BOARD ==================== */
.board-wrap { display: flex; justify-content: center; }

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(560px, 92vw);
  width: clamp(260px, calc(100svh - 430px), min(560px, 92vw));
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  padding: 12px;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: clamp(30px, 10vmin, 84px);
  font-weight: 800;
  font-family: inherit;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}
.cell:hover:not(.filled):not(:disabled) { background: rgba(255, 255, 255, 0.17); transform: scale(1.03); }
.cell:active:not(.filled):not(:disabled) { transform: scale(0.97); }
.cell:disabled { cursor: default; }

/* Ghost preview of the next mark on hover */
.board[data-turn="x"] .cell:not(.filled):not(:disabled):hover::after,
.board[data-turn="o"] .cell:not(.filled):not(:disabled):hover::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.25;
}
.board[data-turn="x"] .cell:not(.filled):not(:disabled):hover::after { content: "X"; color: var(--x-color); }
.board[data-turn="o"] .cell:not(.filled):not(:disabled):hover::after { content: "O"; color: var(--o-color); }

.cell.x { color: var(--x-color); text-shadow: 0 0 22px rgba(77, 215, 254, 0.55); }
.cell.o { color: var(--o-color); text-shadow: 0 0 22px rgba(255, 122, 184, 0.55); }

.cell.filled span {
  display: inline-block;
  animation: pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop {
  0% { transform: scale(0.2) rotate(-12deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.cell.win-cell { background: rgba(61, 220, 133, 0.18); animation: winPulse 0.7s ease infinite alternate; }
@keyframes winPulse {
  from { box-shadow: 0 0 0 rgba(61, 220, 133, 0.0) inset; }
  to   { box-shadow: 0 0 26px rgba(61, 220, 133, 0.35) inset; }
}

.win-line {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  pointer-events: none;
}
.win-line line {
  stroke: var(--win);
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(61, 220, 133, 0.8));
  stroke-dasharray: 500;
  stroke-dashoffset: 500;
}
.win-line.draw line { animation: drawLine 0.45s ease forwards; }
@keyframes drawLine { to { stroke-dashoffset: 0; } }

/* ==================== BUTTONS ==================== */
.actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.btn {
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.96); }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 9px 16px;
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.45);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 10px 30px rgba(124, 92, 255, 0.6); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.btn-big { font-size: 16px; padding: 14px 34px; }

/* ==================== FOOTER ==================== */
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 0;
}

/* ==================== MODAL ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 25, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 100;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }

.modal {
  position: relative;
  background: linear-gradient(160deg, #1c2144, #141833);
  border: 1px solid rgba(124, 92, 255, 0.4);
  border-radius: 24px;
  box-shadow: var(--shadow), 0 0 60px rgba(124, 92, 255, 0.2);
  padding: 28px 24px;
  width: min(420px, 100%);
  max-height: 90vh;
  max-height: 90svh;
  overflow-y: auto;
  text-align: center;
  transform: translateY(16px) scale(0.96);
  transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.modal-overlay.show .modal { transform: translateY(0) scale(1); }

.modal-step { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.modal-step.hidden { display: none; }

.result-emoji { font-size: 52px; animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.result-title { font-size: 30px; font-weight: 800; }
.result-title.x-win { color: var(--x-color); }
.result-title.o-win { color: var(--o-color); }
.result-sub { color: var(--text-dim); font-size: 14px; }

/* ==================== RESPONSIVE ==================== */

/* Small phones */
@media (max-width: 420px) {
  .topbar { justify-content: center; }
  .topbar-right { flex-wrap: wrap; justify-content: center; }
  .logo { font-size: 26px; }
  .mode-btn { font-size: 12px; padding: 7px 11px; }
  .score-value { font-size: 20px; }
  .status { font-size: 13px; }
  .btn-big { width: 100%; }
}

/* Landscape phones — keep the board fully visible */
@media (max-height: 560px) and (orientation: landscape) {
  .stage-screen { padding: 10px 12px; gap: 8px; }
  .game-shell { gap: 8px; }
  .board { width: clamp(200px, calc(100svh - 230px), min(340px, 88vw)); }
  .scoreboard { gap: 6px; }
  .score-card { padding: 6px 6px; border-radius: 12px; }
  .score-value { font-size: 18px; }
  .modal { padding: 18px 20px; }
  .result-emoji { font-size: 36px; }
  .result-title { font-size: 22px; }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* =========================================================================
   KRITRIM: scrollable content + real ad units below the fullscreen game
   ========================================================================= */

/* The game fills the first screen; the About content + ad units scroll in
   below it. Override the flex-centred body so the whole page can scroll. */
html { overflow-x: hidden; overflow-y: auto; touch-action: pan-y; overscroll-behavior: none; }
body {
  display: block;
  min-height: 100%;
  padding: 0;
  gap: 0;
  overflow-x: hidden;
  touch-action: pan-y;
}

/* First screen: holds and centres the game board */
.stage-screen {
  min-height: 100svh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8vh, 18px);
  padding: 14px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-top: max(14px, env(safe-area-inset-top));
}

/* Board keeps touch-action:none so taps/drags never scroll the page;
   the header, the space around the board, and the content below scroll. */
.board { touch-action: none; }
.about { touch-action: pan-y; }

/* ---- About / how-to-play content ---- */
.about {
  max-width: 750px;
  margin: 0 auto;
  padding: 26px 20px 56px;
  line-height: 1.65;
  font-size: 16px;
}
.about h2 { font-size: 1.5rem; margin: 0.2em 0 0.5em; color: var(--text); }
.about h3 { font-size: 1.15rem; margin: 1.4em 0 0.45em; color: var(--accent-2); }
.about p  { margin: 0.4em 0 1.1em; color: var(--text-dim); }

/* ---- Content ad slots: size to their ad (no grey box, no clipping) ---- */
.about .ad-slot {
  width: auto;
  height: auto;
  max-width: 100%;
  margin: 26px auto;
  padding: 0;
  background: transparent;
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: center;
}
.about .ad-slot iframe { max-width: 100%; display: block; }

/* The fixed side rails are gone. They held a 160x600 and a 160x300
   skyscraper, a format retired across every site: squares and long bars
   only. The ad-box2-wrap rule went with them - that slot no longer exists. */

/* ---- Inline SVG icons (replace all emoji in the UI) ---- */
.ic {
  width: 1.05em;
  height: 1.05em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.18em;
  flex: none;
}
.mode-btn, .diff-btn, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.icon-btn .ic { width: 20px; height: 20px; vertical-align: middle; }
.status .ic { margin-right: 5px; }
.result-emoji { display: flex; align-items: center; justify-content: center; }
.result-emoji .ic { width: 1em; height: 1em; stroke-width: 1.6; vertical-align: middle; }

/* ---- Win-modal display ad (7th unit) ---- */
.modal .ad-slot { display: flex; justify-content: center; align-items: center; width: 100%; margin: 2px 0; }
.modal .ad-slot iframe { max-width: 100%; display: block; }
