/* Neon TTT theme — paint only; layout from spine.js. Brick: Unsplash photo tile. */

/* ── Unsplash brick wall (photo) + night vignette ──
   Photo: https://unsplash.com/photos/UrPHHbAgx7E (purple/black brick)
   Unsplash License — free to use. CSS/SVG/shaders cannot match this grit. */
html {
  background-color: #0c0810;
}
html::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: #0c0810;
  background-image:
    radial-gradient(ellipse 90% 75% at 50% 38%, transparent 12%, #000000d8 100%),
    linear-gradient(180deg, #1a0a28aa 0%, #0c0810cc 100%),
    url("./assets/brick-wall.webp");
  background-size: auto, auto, cover;
  background-repeat: no-repeat;
  background-position: center, center, center;
  filter: saturate(1.15) brightness(0.72) contrast(1.08);
}
/* glow.js GPU wall replaces CSS photo */
html[data-glow="gpu"]::before {
  background-image: none !important;
  filter: none !important;
  background-color: #050308 !important;
}
ux-body {
  background: transparent !important;
}
ux-body::before,
ux-body::after {
  content: none !important;
}

/* Head/tail above body so title + chrome aren't covered by body paint */
ux-head,
ux-tail {
  background: transparent !important;
  z-index: 2;
  overflow: visible !important;
}

ux-cell {
  padding: 0.35em;
}
ux-cell[max],
ux-cell:has(> ux-cell) {
  padding: 0;
}

/* ── Head — three upright title cells (tic/tac/toe); equalStrip stacks in wide ── */
@keyframes neon-flicker {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% { opacity: 1; }
  20%, 24%, 55% { opacity: 0.55; }
}
ux-head > ux-cell.ttt-title {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  /* Fight spine equalStrip inline overflow:hidden (clips glow) */
  overflow: visible !important;
  display: grid;
  place-items: center;
  padding: 0.15em 0.25em;
  box-sizing: border-box;
  font-family: "Montserrat", ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  transform: none;
  /* Robust visible fallback before/without JS fit */
  font-size: clamp(11px, 4.2vmin, 40px);
  color: #f8fbff;
  -webkit-text-fill-color: #f8fbff;
  text-shadow:
    0 0 4px #fff,
    0 0 10px #fff,
    0 0 18px #00f2ff,
    0 0 36px #00f2ff,
    0 0 55px #a855f7,
    0 0 80px #ff2d95,
    0 0 120px #ff2d9588;
  animation: neon-flicker 2.2s infinite alternate;
  opacity: 1;
}

/* ── Tail chrome ── */

ux-tail > ux-cell {
  overflow: hidden;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.2em;
  padding: 0.25em 0.35em;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

ux-tail > .ttt-status {
  color: #e8e0ff;
  font: 700 13px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 10px #bc13fe99;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}
ux-tail > .ttt-status.is-x {
  color: #ffb3c4;
  text-shadow: 0 0 12px #ff2d55aa;
}
ux-tail > .ttt-status.is-o {
  color: #b8ff9a;
  text-shadow: 0 0 12px #39ff1488;
}
ux-tail > .ttt-status[data-kind="win"] {
  font-size: 14px;
  letter-spacing: 0.1em;
  animation: neon-flicker 0.9s ease-in-out 2;
}
ux-tail > .ttt-status[data-kind="draw"] {
  color: #f0d27a;
  text-shadow: 0 0 12px #f0d27a88;
}

ux-tail > .ttt-scores {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.55em 0.85em;
  font: 600 12px/1.2 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  color: #c4b8e0;
}
.ttt-score {
  white-space: nowrap;
  padding: 0.2em 0.45em;
  border-radius: 4px;
  background: color-mix(in srgb, #7c3aed 14%, transparent);
  border: 1px solid #bc13fe44;
  text-shadow: 0 0 6px #bc13fe55;
}
.ttt-score[data-sx] {
  color: #ffb3c4;
  border-color: #ff2d5544;
  background: color-mix(in srgb, #ff2d55 12%, transparent);
}
.ttt-score[data-so] {
  color: #b8ff9a;
  border-color: #39ff1444;
  background: color-mix(in srgb, #39ff14 10%, transparent);
}
.ttt-score[data-sd] {
  color: #f0d27a;
  border-color: #f0d27a44;
}

ux-tail > .ttt-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
}
html[data-o="t"] ux-tail > .ttt-actions {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.45em 0.65em;
}

.ttt-btn {
  appearance: none;
  cursor: pointer;
  border: 1px solid #00f2ff88;
  border-radius: 6px;
  padding: 0.35em 0.75em;
  background: linear-gradient(180deg, #1a1030 0%, #0c0818 100%);
  color: #e8fbff;
  font: 700 11px/1.2 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 8px #00f2ff66;
  box-shadow:
    0 0 10px #00f2ff33,
    inset 0 0 12px #bc13fe22;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.ttt-btn:hover {
  border-color: #00f2ff;
  box-shadow:
    0 0 16px #00f2ff55,
    inset 0 0 14px #bc13fe33;
}
.ttt-btn:active {
  transform: scale(0.97);
}
.ttt-btn-ghost {
  border-color: #a89bc466;
  color: #c4b8e0;
  text-shadow: none;
  box-shadow: none;
  background: transparent;
}
.ttt-btn-ghost:hover {
  border-color: #f0d27a88;
  color: #f0d27a;
  box-shadow: 0 0 10px #f0d27a33;
}

.ttt-copy {
  color: #7a6f94;
  font: 500 10px/1.2 ui-monospace, Menlo, Consolas, monospace;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* Wide tail: stack chrome cleanly in the right strip */
html[data-o="w"] ux-tail > .ttt-status,
html[data-o="w"] ux-tail > .ttt-scores,
html[data-o="w"] ux-tail > .ttt-actions {
  writing-mode: horizontal-tb;
}

/* ── Board ── */
ux-body > ux-cell[c] {
  position: relative;
  /* Do NOT set width/height:100% — that defeats spine cqmin square */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  background: transparent;
  overflow: visible;
}

/* Neon grid — borders only (no cell box-shadow = no fake side frame) */
ux-cell.ttt-cell {
  container-type: size;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  cursor: pointer;
  border-style: solid;
  border-color: #e0ecff;
  border-width: 0;
  /* Leave air from grid lines — QA: X too close on tall */
  font: 800 min(62cqmin, 8rem) / 1 ui-sans-serif, system-ui, sans-serif;
  user-select: none;
  color: transparent;
  overflow: visible;
  /* No isolation — isolating flatten+blur composites dark over the brick wall */
  box-shadow: none;
  background: transparent;
}
ux-cell.ttt-cell:not(.filled):hover {
  background: color-mix(in srgb, #7c3aed 18%, transparent);
}
ux-cell.ttt-cell.filled {
  background: transparent;
}
ux-cell.ttt-cell[data-i="0"] { border-width: 0 3px 3px 0; }
ux-cell.ttt-cell[data-i="1"] { border-width: 0 3px 3px 0; }
ux-cell.ttt-cell[data-i="2"] { border-width: 0 0 3px 0; }
ux-cell.ttt-cell[data-i="3"] { border-width: 0 3px 3px 0; }
ux-cell.ttt-cell[data-i="4"] { border-width: 0 3px 3px 0; }
ux-cell.ttt-cell[data-i="5"] { border-width: 0 0 3px 0; }
ux-cell.ttt-cell[data-i="6"] { border-width: 0 3px 0 0; }
ux-cell.ttt-cell[data-i="7"] { border-width: 0 3px 0 0; }
ux-cell.ttt-cell[data-i="8"] { border-width: 0 0 0 0; }

/*
  Neon marks — brighten only.
  Glyph blur flattens onto transparent-black and darkens cell edges.
  Glow is a radial bloom with mix-blend-mode:plus-lighter/screen (additive).
*/
ux-cell.ttt-cell > .ttt-core {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  line-height: 1;
  font: inherit;
  pointer-events: none;
  user-select: none;
  position: relative;
  z-index: 2;
  color: #fff;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

/* Additive light pool behind the letter — fades to transparent (never dark) */
ux-cell.ttt-cell.filled::before {
  content: "";
  grid-area: 1 / 1;
  justify-self: center;
  align-self: center;
  width: 85%;
  height: 85%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  mix-blend-mode: plus-lighter;
  background: radial-gradient(
    circle closest-side,
    color-mix(in srgb, var(--ttt-glow, #fff) 75%, #fff) 0%,
    color-mix(in srgb, var(--ttt-glow, #fff) 35%, transparent) 45%,
    transparent 72%
  );
}
@supports not (mix-blend-mode: plus-lighter) {
  ux-cell.ttt-cell.filled::before {
    mix-blend-mode: screen;
  }
}

ux-cell.ttt-cell.mark-x {
  --ttt-glow: #ff4d6d;
}
ux-cell.ttt-cell.mark-o {
  --ttt-glow: #5cff3a;
}

ux-cell.ttt-cell.mark-x > .ttt-core {
  text-shadow:
    0 0 3px #fff,
    0 0 10px #ff2d55,
    0 0 18px #ff2d55aa,
    0 0 28px #ff2d5566;
}
ux-cell.ttt-cell.mark-o > .ttt-core {
  text-shadow:
    0 0 3px #fff,
    0 0 10px #39ff14,
    0 0 18px #39ff14aa,
    0 0 28px #39ff1466;
}

/* Win line */
.ttt-win {
  position: absolute;
  height: 5px;
  background: #fff;
  border-radius: 2px;
  box-shadow:
    0 0 8px #fff,
    0 0 16px #f0d27a,
    0 0 32px #f0d27a,
    0 0 48px #ff2d9555;
  transform-origin: 0 50%;
  pointer-events: none;
  z-index: 5;
  display: none;
  filter: none;
}
.ttt-win.is-on { display: block; }

/* Hold ~ debug paths (spine sets html[data-d]) */
html[data-d] ux-cell:not(.ttt-cell) {
  outline: 1px solid #8888;
}
html[data-d] ux-cell[data-p]::after {
  content: attr(data-p);
  position: absolute;
  top: 2px;
  left: 3px;
  z-index: 4;
  padding: 1px 4px;
  font: 600 10px/1.2 ui-monospace, monospace;
  color: #f0d27a;
  background: #000a;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  ux-head > ux-cell.ttt-title,
  ux-tail > .ttt-status[data-kind="win"] {
    animation: none;
    opacity: 1;
  }
}


/* Shared-budget compact: keep HUD inside strip when viewport is tight */
html[data-compact] ux-tail > .ttt-copy {
  display: none;
}
html[data-compact] ux-tail > .ttt-status {
  font-size: 11px;
}
html[data-compact] ux-tail > .ttt-scores {
  gap: 0.25em 0.4em;
  font-size: 10px;
}
html[data-compact] .ttt-score {
  padding: 0.12em 0.3em;
}
html[data-compact] .ttt-btn {
  padding: 0.25em 0.5em;
  font-size: 10px;
}
html[data-o="t"][data-compact] ux-tail > .ttt-actions {
  gap: 0.3em 0.4em;
}
html[data-compact] ux-head > ux-cell.ttt-title {
  letter-spacing: 0.04em;
}
