/* ═══════════════════════════════════════════
   game.css — Shared stylesheet for all game pages
   CSS variables default to the Cosmic theme.
   Each game page overrides variables via :root or inline style.
═══════════════════════════════════════════ */

:root {
  /* Piece colors */
  --xc: #ff6b6b;
  --oc: #4dd9ac;
  --gold: #f9ca24;

  /* Text */
  --text-main: #f0e6ff;
  --text-muted: rgba(240,230,255,.45);
  --text-body: rgba(240,230,255,.6);

  /* Surfaces */
  --surface: rgba(255,255,255,.055);
  --border: rgba(255,255,255,.1);
  --hover-surface: rgba(255,255,255,.1);
  --hover-border: rgba(255,255,255,.26);

  /* h1 gradient */
  --h1-from: #a78bfa;
  --h1-mid: #f472b6;
  --h1-to: #fb923c;
  --h1-glow: rgba(167,139,250,.38);
  --h1-size: clamp(2rem, 8vw, 3.2rem);
  --h1-compact: 1.8rem;

  /* Big button */
  --btn-from: #7c3aed;
  --btn-mid: #a855f7;
  --btn-to: #ec4899;
  --btn-p1: rgba(168,85,247,.4);
  --btn-p2: rgba(168,85,247,.55);
  --btn-p3: rgba(168,85,247,.28);

  /* Option buttons — selected states */
  --opt-sx-bg: rgba(255,107,107,.13);
  --opt-sx-sh: rgba(255,107,107,.25);
  --opt-so-bg: rgba(77,217,172,.13);
  --opt-so-sh: rgba(77,217,172,.25);
  --opt-s1-b: var(--gold);
  --opt-s1-bg: rgba(249,202,36,.12);
  --opt-s1-sh: rgba(249,202,36,.22);
  --opt-s2-b: #60a5fa;
  --opt-s2-bg: rgba(96,165,250,.12);
  --opt-s2-sh: rgba(96,165,250,.22);

  /* Cell */
  --cell-glow: rgba(255,255,255,.13);
  --ai-flash: rgba(77,217,172,.22);
  --ai-flash-sh: rgba(77,217,172,.3);

  /* Result card */
  --rcard-bg: linear-gradient(140deg, rgba(26,20,65,.97), rgba(16,10,40,.97));
  --rtitle-d: #a78bfa;

  /* Play Again button */
  --pa-from: #7c3aed;
  --pa-to: #ec4899;
  --pa-sh: rgba(168,85,247,.4);

  /* Bubble */
  --bubble-bg: rgba(22,14,52,.94);

  /* Gold icon filter (for themed uses) */
  --gold-filter: drop-shadow(0 0 12px rgba(249,202,36,.5));
}

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

/* ── Body (structure only; background set inline per theme) ── */
body {
  min-height: 100vh; min-height: 100dvh;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--text-main);
  display: flex; align-items: center; justify-content: center;
  overflow-x: hidden; overflow-y: auto;
}

/* ── Canvas ── */
canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#bg-canvas { z-index: 0; }
#fx        { z-index: 100; }

/* ── Back link ── */
.back-link {
  position: fixed; top: 14px; left: 16px; z-index: 200;
  font-family: 'Nunito', sans-serif; font-size: .8rem; font-weight: 800;
  color: var(--text-muted); text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 12px;
  transition: all .2s ease;
  backdrop-filter: blur(12px);
}
.back-link:hover { color: var(--text-main); background: var(--hover-surface); border-color: var(--hover-border); }

/* ── App wrapper ── */
#app {
  position: relative; z-index: 1;
  width: 100%; max-width: 460px;
  padding: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}

/* ── Setup screen ── */
#setup {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 24px;
  animation: enter .55s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes enter {
  from { opacity: 0; transform: translateY(28px) scale(.94); }
  to   { opacity: 1; transform: none; }
}

/* ── h1 ── */
h1 {
  font-family: 'Fredoka One', cursive;
  font-size: var(--h1-size);
  background: linear-gradient(135deg, var(--h1-from), var(--h1-mid), var(--h1-to));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 22px var(--h1-glow));
  cursor: pointer; user-select: none;
  text-align: center; line-height: 1.1;
  transition: transform .15s;
}
h1:active { transform: scale(.97); }

/* ── Subtitle ── */
.sub {
  text-align: center; font-size: .85rem;
  color: var(--text-muted);
  letter-spacing: .1em; text-transform: uppercase; margin-top: 4px;
}

/* ── Card ── */
.card {
  width: 100%;
  background: var(--surface);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px;
  display: flex; flex-direction: column; gap: 18px;
}

/* ── Label ── */
.lbl { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; color: var(--text-muted); }

/* ── Row ── */
.row { display: flex; gap: 10px; margin-top: 10px; }

/* ── Option buttons ── */
.opt {
  flex: 1; padding: 14px 10px;
  border-radius: 14px; border: 2px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text-main); cursor: pointer;
  font-family: 'Nunito', sans-serif; font-size: .93rem; font-weight: 700;
  transition: all .22s cubic-bezier(.34,1.56,.64,1);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.opt:hover { transform: translateY(-2px); border-color: var(--hover-border); background: var(--hover-surface); }
.opt.sx { border-color: var(--xc);     background: var(--opt-sx-bg); box-shadow: 0 0 18px var(--opt-sx-sh); }
.opt.so { border-color: var(--oc);     background: var(--opt-so-bg); box-shadow: 0 0 18px var(--opt-so-sh); }
.opt.s1 { border-color: var(--opt-s1-b); background: var(--opt-s1-bg); box-shadow: 0 0 18px var(--opt-s1-sh); }
.opt.s2 { border-color: var(--opt-s2-b); background: var(--opt-s2-bg); box-shadow: 0 0 18px var(--opt-s2-sh); }
.opt.sk { border-color: var(--opt-s1-b); background: var(--opt-s1-bg); box-shadow: 0 0 18px var(--opt-s1-sh); }
.opt.sn { border-color: var(--opt-s2-b); background: var(--opt-s2-bg); box-shadow: 0 0 18px var(--opt-s2-sh); }

/* ── Symbol color helpers ── */
.xs { color: var(--xc); font-size: 1.35rem; filter: drop-shadow(0 0 5px var(--xc)); }
.os { color: var(--oc); font-size: 1.35rem; filter: drop-shadow(0 0 5px var(--oc)); }

/* ── Big start button ── */
.big-btn {
  width: 100%; padding: 17px;
  border-radius: 18px; border: none;
  background: linear-gradient(135deg, var(--btn-from), var(--btn-mid), var(--btn-to));
  color: #fff; font-family: 'Fredoka One', cursive;
  font-size: 1.35rem; letter-spacing: .04em;
  cursor: pointer;
  transition: all .22s cubic-bezier(.34,1.56,.64,1);
  animation: btnPulse 2.2s ease-in-out infinite;
}
@keyframes btnPulse {
  0%,100% { box-shadow: 0 4px 28px var(--btn-p1), 0 0 0 0 var(--btn-p3); }
  50%      { box-shadow: 0 4px 36px var(--btn-p2), 0 0 0 9px transparent; }
}
.big-btn:hover  { transform: translateY(-3px) scale(1.02); }
.big-btn:active { transform: scale(.97); }

/* ═══════════════════════════════════════════
   GAME SCREEN
═══════════════════════════════════════════ */
#game { display: none; flex-direction: column; align-items: center; gap: 14px; width: 100%; }

/* ── Scoreboard ── */
.scores {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 18px; padding: 12px 18px;
}

.sp { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; }
.sp .nm  { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); }
.sp .num { font-family: 'Fredoka One', cursive; font-size: 2rem; line-height: 1; color: currentColor; }
.sp .ico { font-size: 1.1rem; cursor: pointer; user-select: none; }

.sp[data-sym="X"] { color: var(--xc); }
.sp[data-sym="O"] { color: var(--oc); }

.sp.active .num { filter: brightness(1.3); }
.sp.active::after {
  content: '';
  position: absolute; bottom: -5px; left: 15%; right: 15%;
  height: 3px; border-radius: 3px; background: currentColor;
  animation: barIn .3s ease;
}
@keyframes barIn { from { transform: scaleX(0); } }

.mid { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mid .vs  { font-family: 'Fredoka One', cursive; font-size: 1.3rem; color: var(--text-muted); }
.mid .dw  { font-size: .68rem; font-weight: 700; color: var(--text-muted); background: rgba(255,255,255,.07); padding: 2px 8px; border-radius: 20px; }

.num.pop { animation: scPop .45s cubic-bezier(.34,1.56,.64,1); }
@keyframes scPop { 0%,100% { transform: scale(1); } 45% { transform: scale(1.65); } }

/* ── Board wrapper ── */
.bwrap { position: relative; width: 100%; aspect-ratio: 1; max-width: 390px; }

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 9px; width: 100%; height: 100%;
}

/* ── Cells ── */
.cell {
  background: var(--surface);
  border-radius: 16px; border: 1.5px solid var(--border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s, transform .18s, border-color .18s;
  position: relative; overflow: hidden;
}
.cell::after {
  content: '';
  position: absolute; inset: 0; border-radius: 16px;
  background: radial-gradient(circle at var(--mx,50%) var(--my,50%), var(--cell-glow), transparent 65%);
  opacity: 0; transition: opacity .2s;
}
.cell:hover:not(.taken):not(.go)::after { opacity: 1; }
.cell:hover:not(.taken):not(.go) {
  background: var(--hover-surface);
  transform: scale(1.05); border-color: var(--hover-border);
}
.cell.taken { cursor: default; }
.cell.win { animation: winCell .55s ease both; }
@keyframes winCell {
  to { background: rgba(249,202,36,.18); border-color: rgba(249,202,36,.55); box-shadow: 0 0 22px rgba(249,202,36,.3); }
}
.cell.aifl { animation: aiFlash .38s ease; }
@keyframes aiFlash {
  0%   { background: var(--surface); }
  35%  { background: var(--ai-flash); box-shadow: 0 0 16px var(--ai-flash-sh); }
  100% { background: var(--surface); }
}
.cell.shake { animation: shk .38s ease; }
@keyframes shk {
  0%,100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-2deg); }
  40% { transform: translateX(6px)  rotate(2deg); }
  60% { transform: translateX(-4px) rotate(-1deg); }
  80% { transform: translateX(4px)  rotate(1deg); }
}

/* ── SVG pieces ── */
.cell svg { width: 56%; height: 56%; overflow: visible; }

.xl {
  fill: none; stroke: var(--xc); stroke-width: 10; stroke-linecap: round;
  filter: drop-shadow(0 0 7px var(--xc));
  stroke-dasharray: 90; stroke-dashoffset: 90;
}
.xl1 { animation: dxl .22s ease forwards; }
.xl2 { animation: dxl .22s ease .11s forwards; }
@keyframes dxl { to { stroke-dashoffset: 0; } }

.ol {
  fill: none; stroke: var(--oc); stroke-width: 10; stroke-linecap: round;
  filter: drop-shadow(0 0 7px var(--oc));
  stroke-dasharray: 226; stroke-dashoffset: 226;
  animation: dol .32s ease forwards;
}
@keyframes dol { to { stroke-dashoffset: 0; } }

/* ── Win line ── */
#wl { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.wlp {
  fill: none; stroke: var(--gold); stroke-width: 5; stroke-linecap: round;
  filter: drop-shadow(0 0 8px var(--gold));
  transition: stroke-dashoffset .42s ease .08s;
}

/* ── Ghost hover preview ── */
.ghost {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: .22; pointer-events: none;
}
.ghost svg { width: 56%; height: 56%; overflow: visible; }
.ghost .xl { filter: none; animation: none; stroke-dashoffset: 0; }
.ghost .ol { filter: none; animation: none; stroke-dashoffset: 0; }

/* ── Status bar ── */
.status {
  width: 100%; padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: .93rem; font-weight: 700; text-align: center;
  min-height: 50px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.dots { display: inline-flex; gap: 4px; }
.dots i { display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--oc); animation: dot 1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .30s; }
@keyframes dot { 0%,100% { opacity:.3; transform:translateY(0); } 50% { opacity:1; transform:translateY(-5px); } }

/* ═══════════════════════════════════════════
   RESULT OVERLAY
═══════════════════════════════════════════ */
#res {
  display: none; position: fixed; inset: 0; z-index: 90;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.72); backdrop-filter: blur(10px); padding: 20px;
}
#res.on { display: flex; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; } }

.rcard {
  background: var(--rcard-bg);
  border: 1px solid var(--border);
  border-radius: 26px; padding: 34px 28px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  max-width: 330px; width: 100%;
  animation: cardIn .45s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes cardIn { from { transform: scale(.6) translateY(36px); opacity: 0; } }

.remoji { font-size: 3.8rem; animation: eIn .5s cubic-bezier(.34,1.56,.64,1) .15s both; }
@keyframes eIn { from { transform: scale(0) rotate(-20deg); opacity: 0; } }

.rtitle { font-family: 'Fredoka One', cursive; font-size: 2.3rem; line-height: 1; }
.rtitle.w { color: var(--gold); filter: var(--gold-filter); }
.rtitle.l { color: #f87171; }
.rtitle.d { color: var(--rtitle-d); }

.rmsg { font-size: .93rem; color: var(--text-body); font-weight: 600; line-height: 1.5; }

.rbts { display: flex; gap: 10px; width: 100%; }
.rbts button {
  flex: 1; padding: 13px; border-radius: 14px; cursor: pointer;
  font-family: 'Nunito', sans-serif; font-size: .93rem; font-weight: 800;
  transition: all .2s ease;
}
.pa {
  flex: 2 !important; border: none;
  background: linear-gradient(135deg, var(--pa-from), var(--pa-to));
  color: #fff; font-family: 'Fredoka One', cursive !important; font-size: 1.1rem !important;
}
.pa:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--pa-sh); }
.se { border: 1px solid var(--border); background: var(--surface); color: var(--text-body); }
.se:hover { background: var(--hover-surface); color: var(--text-main); }

/* ═══════════════════════════════════════════
   AI SPEECH BUBBLE
═══════════════════════════════════════════ */
#bubble {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--bubble-bg); backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: .82rem; font-weight: 700;
  max-width: 210px; z-index: 50;
  opacity: 0; transform: translateY(8px) scale(.96);
  transition: all .3s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
  color: var(--text-main);
}
#bubble.on { opacity: 1; transform: none; }

/* ═══════════════════════════════════════════
   FLOATING TEXT
═══════════════════════════════════════════ */
.ft {
  position: fixed;
  font-family: 'Fredoka One', cursive; font-size: 1.15rem;
  pointer-events: none; z-index: 200;
  animation: ftUp 1.2s ease forwards;
}
@keyframes ftUp { to { opacity: 0; transform: translateY(-70px) scale(1.25); } }

/* ── Hint highlight ── */
.hint {
  box-shadow: 0 0 24px var(--gold), inset 0 0 14px rgba(249,202,36,.2) !important;
  border-color: var(--gold) !important;
}

/* ═══════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════ */
@media (max-width: 380px) {
  .card { padding: 18px; }
  .num { font-size: 1.75rem; }
}
@media (max-height: 680px) {
  #app { gap: 10px; }
  h1 { font-size: var(--h1-compact); }
  .scores { padding: 9px 14px; }
}
