﻿/* Tic-Tac-Toe — game.bangtech.com/tic-tac-toe/ */
:root {
  --bg: #0d131c;
  --panel: rgba(18, 26, 38, 0.94);
  --panel-2: #1b2636;
  --cell: #152131;
  --cell-hover: #1c2b40;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8eef7;
  --muted: #8fa0b8;
  --x: #5ec2ff;
  --o: #ffd166;
  --win: #69f0ae;
  font-family: Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; min-height: 100dvh; color: var(--text); display: flex; flex-direction: column; background:
  radial-gradient(1000px 520px at 15% -10%, rgba(94,194,255,.16), transparent 60%),
  radial-gradient(800px 480px at 110% 110%, rgba(255,209,102,.13), transparent 60%), var(--bg) fixed; }
h1, h2, h3 { font-family: 'Space Grotesk', Inter, sans-serif; margin: 0; }
a { color: var(--x); }
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- nav / footer ---------- */
.site-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; width: 100%; max-width: 1080px; margin: 0 auto; }
.nav-brand { font-family: 'Space Grotesk', sans-serif; font-weight: 700; color: var(--text); text-decoration: none; font-size: 17px; white-space: nowrap; }
.brand-x { color: var(--x); } .brand-o { color: var(--o); margin-right: 4px; }
.nav-links { display: flex; gap: 4px; }
.nav-links a { color: var(--muted); text-decoration: none; padding: 8px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.nav-links a:hover { color: var(--text); background: var(--panel-2); }
.site-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 16px 24px; margin-top: auto; }

/* ---------- layout: portrait / narrow = one column ---------- */
.ttt { width: 100%; max-width: 1080px; margin: 0 auto; padding: 4px 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.play-area { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.side { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 14px; }

/* board size: as large as fits, leaving room for the status line and nav */
.board-wrap { --size: min(92vw, calc(100dvh - 190px), 520px); position: relative; width: var(--size); height: var(--size); min-width: 240px; min-height: 240px; }

/* ---------- landscape / wide = board left, controls right ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 560px) {
  .ttt { flex-direction: row; align-items: flex-start; justify-content: center; gap: 28px; }
  .play-area { width: auto; }
  .side { width: 340px; flex-shrink: 0; }
  .board-wrap { --size: min(56vw, calc(100dvh - 130px), 560px); }
}
/* short landscape phones: tighter chrome */
@media (orientation: landscape) and (max-height: 500px) {
  .site-nav { padding: 4px 16px; }
  .status { font-size: 18px; min-height: 0; }
  .board-wrap { --size: min(56vw, calc(100dvh - 104px), 560px); }
}

/* ---------- status ---------- */
.status { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: clamp(18px, 4.5vw, 24px); min-height: 32px; text-align: center; }
.status .x { color: var(--x); } .status .o { color: var(--o); }
.status.thinking::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- board ---------- */
.board { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: clamp(6px, 2.2%, 12px); }
.cell { position: relative; border: 1px solid var(--line); border-radius: clamp(10px, 4%, 18px); background: var(--cell); cursor: pointer; padding: 0;
  display: grid; place-items: center; transition: background .15s, transform .08s, box-shadow .2s; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.cell:hover:not(:disabled) { background: var(--cell-hover); }
.cell:active:not(:disabled) { transform: scale(.97); }
.cell:focus-visible { outline: 3px solid var(--x); outline-offset: 2px; }
.cell:disabled { cursor: default; }
.board.locked .cell { cursor: default; }
/* "ghost" preview of the current player's mark on hover (mouse only) */
@media (hover: hover) {
  .board[data-turn="X"]:not(.locked) .cell:empty:hover::after { content: '✕'; color: var(--x); opacity: .18; font-size: calc(var(--size, 300px) * .2); font-weight: 800; }
  .board[data-turn="O"]:not(.locked) .cell:empty:hover::after { content: '◯'; color: var(--o); opacity: .18; font-size: calc(var(--size, 300px) * .18); font-weight: 800; }
}
.cell svg { width: 66%; height: 66%; overflow: visible; }
.cell svg * { fill: none; stroke-width: 13; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .28s ease-out forwards; }
.cell svg.x * { stroke: var(--x); filter: drop-shadow(0 0 6px rgba(94,194,255,.45)); }
.cell svg.x path + path { animation-delay: .12s; }
.cell svg.o * { stroke: var(--o); filter: drop-shadow(0 0 6px rgba(255,209,102,.45)); }
@keyframes draw { to { stroke-dashoffset: 0; } }
.cell.win { background: rgba(105, 240, 174, .12); border-color: rgba(105, 240, 174, .5); }
.board.done .cell:not(.win) svg { opacity: .35; transition: opacity .4s; }

/* winning line drawn over the board */
.win-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.win-line line { stroke: var(--win); stroke-width: clamp(6px, 2.4%, 12px); stroke-linecap: round; opacity: 0; filter: drop-shadow(0 0 8px rgba(105,240,174,.7)); }
.win-line.show line { opacity: 1; animation: strike .45s ease-out; }
@keyframes strike { from { stroke-dasharray: 0 2000; } to { stroke-dasharray: 2000 0; } }

/* ---------- side panel ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.field-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.seg { display: flex; gap: 4px; background: #0f1824; border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; min-height: 46px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 700; font-size: 15px; cursor: pointer; transition: background .15s, color .15s; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 2px 6px rgba(0,0,0,.3); }
.seg button:focus-visible { outline: 2px solid var(--x); outline-offset: 1px; }
.actions { display: flex; gap: 8px; margin-top: 6px; }
.actions .btn { flex: 1; }

.btn { min-height: 48px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; cursor: pointer; font-weight: 700; font-size: 15px; transition: background .15s, transform .05s; }
.btn:hover { background: #24324a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, #ffb703, #ffd166); color: #1a1300; border: 0; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.big { min-height: 54px; font-size: 17px; width: 100%; }
.btn:focus-visible { outline: 2px solid var(--x); outline-offset: 2px; }

.scores { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; }
.score { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; text-align: center; border-top: 3px solid var(--line); transition: border-color .2s, background .2s; }
.score.x { border-top-color: var(--x); } .score.o { border-top-color: var(--o); }
.score.d { min-width: 74px; }
.score.active { background: var(--panel-2); }
.score-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score b { font-family: 'Space Grotesk', sans-serif; font-size: 28px; line-height: 1.2; }
.score.bump b { animation: bump .5s ease-out; }
@keyframes bump { 40% { transform: scale(1.35); } }
.score b { display: inline-block; }

.result { background: var(--panel); border: 1px solid rgba(255,209,102,.35); border-radius: 16px; padding: 18px 16px 16px; text-align: center; animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
.result.win { border-color: rgba(105,240,174,.5); }
.result.lose { border-color: rgba(255,107,107,.45); }
.result-emoji { font-size: 40px; line-height: 1; }
.result h2 { font-size: 26px; margin: 6px 0 14px; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

/* ---------- ad slot (only visible after a game ends) ---------- */
.ad-wrap { width: 100%; text-align: center; }
.ad-wrap.ad-on { min-height: 120px; }
.ad-wrap:has(ins[data-ad-status="unfilled"]) { display: none; }
.ad-label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition: none !important; }
}
