/*
  Tic-tac-toe in neon: a night page like Blockfall's, one glass stage that
  holds the start screen and the game, a board drawn in glowing lines, X in
  pink and O in aqua - the site's own colours - and gold for the winning row.
*/

.xo-page {
  --glass: rgba(255, 255, 255, .07);
  --glass-edge: rgba(255, 255, 255, .14);
  --text: #EDEBFF;
  --muted: #A6A2C8;
  --nx: #FF5EA8;           /* X */
  --no: #4EE6F0;           /* O */
  --line: #8C7CFF;         /* the board's lines */
  --win: #FFD54A;
  color: var(--text);
  background:
    radial-gradient(1100px 560px at 50% -12%, #3B2A7A 0, rgba(59, 42, 122, 0) 70%),
    radial-gradient(800px 480px at 100% 100%, #5A1E52 0, rgba(90, 30, 82, 0) 70%),
    #0D0B1E;
}
.xo-page::before, .xo-page::after { display: none; }
.xo-page .game-bar { background: rgba(13, 11, 30, .75); backdrop-filter: blur(8px); border-bottom: 1px solid rgba(140, 124, 255, .2); }
.xo-page .small { color: var(--muted); }
.xo-page .more-games h2 { color: var(--text); }

.xo { gap: 10px; padding-top: 10px; max-width: 600px; }

/* ------------------------------------------------------------------ stage */

.stage {
  position: relative;
  /* As tall as a phone's screen allows, so the whole game fits without scrolling. */
  min-height: min(calc(100dvh - 76px), 760px);
  display: flex; flex-direction: column;
  padding: 14px;
  background: linear-gradient(180deg, rgba(30, 24, 66, .92), rgba(18, 14, 40, .96));
  border: 1px solid rgba(140, 124, 255, .3); border-radius: 18px;
  box-shadow: 0 0 0 4px rgba(140, 124, 255, .07), 0 0 40px rgba(140, 124, 255, .18), 0 18px 40px rgba(0, 0, 0, .5);
}
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.screen.in { animation: screen-in .35s ease-out both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } }

/* ------------------------------------------------------------------ the start */

.home { justify-content: center; text-align: center; }
.logo { margin: 4px 0 0; display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.logo .lx, .logo .lo { font: 900 clamp(3rem, 15vw, 4.4rem)/1 system-ui, sans-serif; animation: logo-in .6s cubic-bezier(.2, 1.6, .4, 1) both; }
.logo .lx { color: var(--nx); text-shadow: 0 0 12px rgba(255, 94, 168, .8), 0 0 32px rgba(255, 94, 168, .45); }
.logo .lo { color: var(--no); text-shadow: 0 0 12px rgba(78, 230, 240, .8), 0 0 32px rgba(78, 230, 240, .45); animation-delay: .12s; }
.logo .name { flex-basis: 100%; font: 900 clamp(1.4rem, 6vw, 1.9rem)/1.1 system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--text); }
@keyframes logo-in { from { opacity: 0; transform: scale(.3) rotate(-12deg); } }
.tag { margin: 0; color: var(--muted); font-weight: 700; }

.pick { display: flex; gap: 4px; padding: 4px; background: rgba(0, 0, 0, .28); border: 1px solid var(--glass-edge); border-radius: 999px; }
.seg {
  min-height: 40px; padding: 6px 14px; border: 0; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--text); font: 800 .92rem/1 system-ui, sans-serif;
}
.seg:hover { background: rgba(255, 255, 255, .08); }
.seg[aria-pressed="true"] { background: linear-gradient(180deg, #A99CFF, #7462F0); color: #0D0B1E; box-shadow: 0 0 16px rgba(140, 124, 255, .55); }
.levels[hidden] { display: none; }

.modes { display: grid; gap: 10px; width: min(100%, 380px); margin-top: 4px; }
.mode {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; text-align: left; cursor: pointer;
  background: var(--glass); color: var(--text); border: 1px solid var(--glass-edge); border-radius: 14px;
  font: inherit; transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
.mode:hover { background: rgba(255, 255, 255, .12); box-shadow: 0 0 18px rgba(140, 124, 255, .3); }
.mode:active { transform: scale(.98); }
.mode .words { display: flex; flex-direction: column; gap: 2px; }
.mode b { font: 900 1.12rem/1.15 system-ui, sans-serif; }
.mode small { color: var(--muted); font-weight: 700; font-size: .85rem; }
.mini {
  flex: none; width: 52px; height: 52px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 4px;
  background: rgba(0, 0, 0, .3); border: 1px solid rgba(140, 124, 255, .35); border-radius: 10px;
}
.mini.big { grid-template-columns: repeat(5, 1fr); gap: 2px; }
.mini i { border-radius: 3px; background: rgba(255, 255, 255, .06); }
.mini i.x { background: var(--nx); box-shadow: 0 0 6px rgba(255, 94, 168, .7); }
.mini i.o { background: var(--no); box-shadow: 0 0 6px rgba(78, 230, 240, .7); }
.mini.star { display: grid; place-items: center; grid-template-columns: 1fr; font-size: 1.9rem; color: var(--win); text-shadow: 0 0 12px rgba(255, 213, 74, .7); }
.link { margin-top: 2px; padding: 8px 12px; border: 0; background: none; color: var(--muted); font: 800 .9rem/1 system-ui, sans-serif; cursor: pointer; }
.link:hover { color: var(--text); }

/* ------------------------------------------------------------------ the game */

.game { gap: 10px; }
.scoreboard { display: grid; grid-template-columns: 1fr .8fr 1fr; gap: 8px; width: min(100%, 420px); }
.side {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 8px;
  padding: 7px 10px; background: var(--glass); border: 1px solid var(--glass-edge); border-radius: 12px;
  transition: box-shadow .2s ease, border-color .2s ease, background .2s ease;
}
.side .mark { grid-row: 1 / 3; font: 900 1.6rem/1 system-ui, sans-serif; }
.side .who { font-weight: 800; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side strong { font: 900 1.45rem/1 system-ui, sans-serif; }
.side.draws { grid-template-columns: 1fr; text-align: center; }
.side.draws .mark { display: none; }
.mx { color: var(--nx); text-shadow: 0 0 10px rgba(255, 94, 168, .7); }
.mo { color: var(--no); text-shadow: 0 0 10px rgba(78, 230, 240, .7); }
#side-x.turn { border-color: rgba(255, 94, 168, .8); box-shadow: 0 0 18px rgba(255, 94, 168, .45); background: rgba(255, 94, 168, .1); }
#side-o.turn { border-color: rgba(78, 230, 240, .8); box-shadow: 0 0 18px rgba(78, 230, 240, .45); background: rgba(78, 230, 240, .1); }
.side.turn .mark { animation: nudge .9s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.18); } }

.xo .status { margin: 0; color: var(--text); font-size: 1.05rem; min-height: 1.4em; }
.status .dots span { animation: blink 1s infinite; }
.status .dots span:nth-child(2) { animation-delay: .2s; }
.status .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

/* The board: as big as fits under the score and over the buttons. */
.board-wrap {
  --size: min(100%, calc(100dvh - 360px), 460px);
  position: relative; width: var(--size); aspect-ratio: 1; margin: auto;
  /* Marks sized by the board's own width (cqw), whatever the screen. */
  container-type: inline-size;
}
.grid, .strike { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.grid line { stroke: var(--line); stroke-width: 6; stroke-linecap: round; filter: drop-shadow(0 0 5px rgba(140, 124, 255, .9)); }
.board-wrap.n5 .grid line { stroke-width: 4; }
.board {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); grid-template-rows: repeat(var(--n, 3), 1fr);
}
.cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
  padding: 16%; margin: 6%; border: 0; border-radius: 12px; cursor: pointer;
  background: transparent; color: inherit;
  transition: background .12s ease, transform .1s ease;
}
.board-wrap.n5 .cell { padding: 9%; margin: 5%; border-radius: 8px; }
.cell:hover:not(:disabled) { background: rgba(255, 255, 255, .06); }
.cell:active:not(:disabled) { transform: scale(.94); }
.cell:focus-visible { outline: 2px solid var(--win); outline-offset: 2px; }
.cell:disabled { cursor: default; }
.cell svg { width: 100%; height: 100%; overflow: visible; }
.cell path, .cell circle {
  fill: none; stroke-width: 13; stroke-linecap: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: draw .26s ease-out forwards;
}
.cell .x path { stroke: var(--nx); filter: drop-shadow(0 0 6px rgba(255, 94, 168, .95)); }
.cell .x path + path { animation-delay: .1s; }
.cell .o circle { stroke: var(--no); filter: drop-shadow(0 0 6px rgba(78, 230, 240, .95)); }
@keyframes draw { to { stroke-dashoffset: 0; } }
.cell .emo { font-size: calc(100cqw / var(--n, 3) * .5); line-height: 1; animation: emo .3s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes emo { from { transform: scale(0) rotate(-30deg); } }

/* Where the next mark would go, faintly, under a mouse. */
@media (hover: hover) {
  .board[data-turn="X"] .cell:hover:not(:disabled)::after,
  .board[data-turn="O"] .cell:hover:not(:disabled)::after { position: absolute; font: 900 calc(100cqw / var(--n, 3) * .62)/1 system-ui, sans-serif; opacity: .22; }
  .board[data-turn="X"] .cell:hover:not(:disabled)::after { content: "×"; color: var(--nx); }
  .board[data-turn="O"] .cell:hover:not(:disabled)::after { content: "○"; color: var(--no); }
}

.cell.in { animation: cellpop .32s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes cellpop { from { transform: scale(.4); opacity: 0; } }
.cell.win { background: rgba(255, 213, 74, .16); box-shadow: 0 0 22px rgba(255, 213, 74, .45) inset; animation: winpulse .9s ease-in-out infinite alternate; }
@keyframes winpulse { to { background: rgba(255, 213, 74, .3); } }
.board.over .cell:not(.win) { opacity: .45; }
/* The last move, softly lit from under its mark. */
.cell.last { background: radial-gradient(circle, rgba(255, 255, 255, .09), rgba(255, 255, 255, 0) 70%); }

.strike line { stroke: var(--win); stroke-width: 9; stroke-linecap: round; opacity: 0; stroke-dasharray: 1; stroke-dashoffset: 1; filter: drop-shadow(0 0 8px rgba(255, 213, 74, .95)); }
.strike.show line { opacity: 1; animation: draw .35s .12s ease-out forwards; }

/* The result under the board, in place of the buttons, once the round is over. */
.result {
  width: min(100%, 360px); padding: 10px 14px 12px; text-align: center;
  background: rgba(13, 11, 30, .7); border: 1px solid rgba(255, 255, 255, .16); border-radius: 16px;
  animation: result-in .35s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes result-in { from { opacity: 0; transform: translateY(14px) scale(.92); } }
.game.done .actions { display: none; }
.r-title { margin: 0; font: 900 1.5rem/1.1 system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase; }
.r-title.good { color: var(--win); text-shadow: 0 0 16px rgba(255, 213, 74, .6); }
.r-title.bad { color: #FF8FA3; }
.r-title.even { color: var(--text); }
.r-text { margin: 4px 0 10px; color: var(--muted); font-weight: 700; font-size: .92rem; }
.r-text:empty { display: none; }
.r-buttons { display: flex; gap: 8px; justify-content: center; }

.actions { display: flex; gap: 8px; justify-content: center; }
.xo .btn {
  min-height: 46px; padding: 8px 16px; font-size: .95rem;
  border: 0; border-radius: 999px; box-shadow: 0 4px 0 #B86E00, 0 0 20px rgba(255, 182, 39, .35);
  background: linear-gradient(180deg, #FFE27A, #FFB627); color: #2A1A00;
}
.xo .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #B86E00; }
.xo .btn-quiet { background: var(--glass); color: var(--text); border: 1px solid var(--glass-edge); box-shadow: none; }
.xo .btn-quiet:hover { background: rgba(255, 255, 255, .14); }

/* A narrow phone: the names a little smaller, so "Player O" fits. */
@media (max-width: 380px) {
  .scoreboard { gap: 6px; }
  .side { padding: 6px 8px; column-gap: 6px; }
  .side .mark { font-size: 1.35rem; }
  .side .who { font-size: .72rem; }
  .side strong { font-size: 1.3rem; }
}

/* In a puzzle the score and the match do not apply. */
body.puzzling .scoreboard { visibility: hidden; }

/* A phone on its side: the board on the left, everything else beside it. */
@media (orientation: landscape) and (max-height: 520px) {
  .xo { max-width: 980px; }
  .stage { min-height: calc(100dvh - 70px); padding: 10px; }
  .game { display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr auto auto auto 1fr; align-items: center; column-gap: 20px; row-gap: 10px; }
  .board-wrap { --size: calc(100dvh - 104px); grid-column: 1; grid-row: 1 / 6; margin: 0; }
  .scoreboard { grid-column: 2; grid-row: 2; justify-self: center; }
  .xo .status { grid-column: 2; grid-row: 3; justify-self: center; }
  .actions, .result { grid-column: 2; grid-row: 4; justify-self: center; }
  .home { flex-direction: row; flex-wrap: wrap; justify-content: center; align-content: center; }
  .home { gap: 8px; }
  .home .logo { flex-basis: 100%; margin: 0; }
  .home .tag { display: none; }
  .logo .lx, .logo .lo { font-size: 2.1rem; }
  .logo .name { font-size: 1.2rem; }
  .modes { grid-template-columns: repeat(3, 1fr); width: 100%; }
  .mode { flex-direction: column; text-align: center; gap: 6px; padding: 8px; }
}

/* ------------------------------------------------------------------ settings */

.sheet {
  width: min(92vw, 400px); padding: 18px;
  background: #1B1638; color: var(--text);
  border: 1px solid rgba(140, 124, 255, .35); border-radius: 16px; box-shadow: 0 18px 40px rgba(0, 0, 0, .6);
}
.sheet::backdrop, .xo-page .rc::backdrop { background: rgba(8, 6, 20, .6); }
.sheet h2 { margin: 0 0 12px; text-align: center; text-transform: uppercase; letter-spacing: .08em; }
.sheet .label { margin: 14px 0 6px; font-weight: 800; font-size: .9rem; }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; margin-bottom: 10px; }
.switch input { width: 22px; height: 22px; margin-top: 2px; accent-color: #7462F0; flex: none; }
.switch small { display: block; color: var(--muted); font-size: .82rem; }
.sheet .btn { display: flex; margin: 10px auto 0; min-height: 42px; padding: 6px 16px; border-radius: 999px; border: 1px solid var(--glass-edge); background: var(--glass); color: var(--text); box-shadow: none; }
.sheet .close { background: linear-gradient(180deg, #FFE27A, #FFB627); color: #2A1A00; border: 0; }
.skins { display: flex; gap: 6px; flex-wrap: wrap; }
.skin {
  padding: 8px 12px; cursor: pointer; border-radius: 999px;
  background: var(--glass); color: var(--text); border: 1px solid var(--glass-edge);
  font: 900 1rem/1 system-ui, sans-serif;
}
.skin[aria-pressed="true"] { background: linear-gradient(180deg, #A99CFF, #7462F0); color: #0D0B1E; border-color: transparent; }

.xo-page .rc { background: #1B1638; color: var(--text); border: 1px solid rgba(140, 124, 255, .35); }
.xo-page .rc .small { color: var(--muted); }
.xo-page .rc .btn { background: var(--glass); color: var(--text); border: 1px solid var(--glass-edge); box-shadow: none; border-radius: 999px; }

/* The help line: keys on a computer only. */
@media (pointer: coarse) { .for-keys { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .cell.win, .side.turn .mark, .logo .lx, .logo .lo { animation: none; }
}
