/* Tic Tac Toe */
/* Aesthetic aligned with chaddytwiceover.com */

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-glass: rgba(20, 20, 20, 0.75);
  --surface-raised: #1c1c1c;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.18);
  
  --text: #edebe6;
  --text-dim: #9a9a95;
  --text-faint: #5a5a58;
  
  /* Signature Brand Accent */
  --neon: #d6ff5c;
  --neon-glow: rgba(214, 255, 92, 0.35);
  
  /* Default Palette (Mint & Amber) */
  --x-color: #7affd2;
  --x-glow: rgba(122, 255, 210, 0.5);
  --o-color: #ffb86b;
  --o-glow: rgba(255, 184, 107, 0.5);
  --win-color: #d6ff5c;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Geist Mono', 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

/* Palette Themes */
[data-theme-palette="neon"] {
  --x-color: #d6ff5c;
  --x-glow: rgba(214, 255, 92, 0.5);
  --o-color: #ff52bf;
  --o-glow: rgba(255, 82, 191, 0.5);
  --win-color: #d6ff5c;
}

[data-theme-palette="monochrome"] {
  --x-color: #edebe6;
  --x-glow: rgba(237, 235, 230, 0.4);
  --o-color: #888884;
  --o-glow: rgba(136, 136, 132, 0.4);
  --win-color: #edebe6;
}

[data-theme-palette="sunset"] {
  --x-color: #ff7a45;
  --x-glow: rgba(255, 122, 69, 0.5);
  --o-color: #36cfc9;
  --o-glow: rgba(54, 207, 201, 0.5);
  --win-color: #ffc069;
}

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

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overflow-y: auto;
}

/* chaddytwiceover constellation dot pattern */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='%23ffffff' fill-opacity='0.9'%3E%3Ccircle cx='8' cy='12' r='1'/%3E%3Ccircle cx='37' cy='84' r='1'/%3E%3Ccircle cx='66' cy='24' r='1'/%3E%3Ccircle cx='98' cy='58' r='1'/%3E%3Ccircle cx='26' cy='42' r='1'/%3E%3Ccircle cx='114' cy='94' r='1'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 120px 120px;
  z-index: 0;
}

/* App Container - optimized to fit iframe without vertical scroll */
.app-container {
  width: 100%;
  max-width: 380px;
  min-height: 100%;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

/* TOP UTILITY BAR */
.top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.score-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
  user-select: none;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill-dot.dot-x {
  background: var(--x-color);
  box-shadow: 0 0 6px var(--x-glow);
}

.pill-dot.dot-o {
  background: var(--o-color);
  box-shadow: 0 0 6px var(--o-glow);
}

.pill-label {
  color: var(--text-faint);
  font-weight: 600;
}

.pill-val {
  color: var(--text);
  font-weight: 700;
}

.streak-pill {
  display: none;
}

@media (min-width: 440px) {
  .streak-pill {
    display: inline-flex;
  }
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--surface-glass);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  backdrop-filter: blur(8px);
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-raised);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: 1px;
}

/* MAIN GAME AREA */
.game-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* STATUS BADGE */
.status-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-radius: 9999px;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text);
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  min-height: 30px;
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--neon);
  box-shadow: 0 0 8px var(--neon-glow);
  animation: pulse-dot 1.8s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.4); opacity: 0.4; }
}

.status-pill.status-x .status-indicator {
  background: var(--x-color);
  box-shadow: 0 0 8px var(--x-glow);
}

.status-pill.status-o .status-indicator {
  background: var(--o-color);
  box-shadow: 0 0 8px var(--o-glow);
}

.status-pill.status-win {
  border-color: var(--win-color);
  background: rgba(214, 255, 92, 0.08);
  box-shadow: 0 0 20px rgba(214, 255, 92, 0.15);
  color: var(--win-color);
}

.status-pill.status-win .status-indicator {
  background: var(--win-color);
  box-shadow: 0 0 10px var(--win-color);
  animation: none;
}

.status-pill.status-draw {
  border-color: var(--text-dim);
  color: var(--text-dim);
}

/* 3X3 BOARD FRAME */
.board-frame {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.4);
}

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

.cell {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(10, 10, 10, 0.7);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.cell:hover:not(.x):not(.o):not(:disabled) {
  background: var(--surface-raised);
  border-color: var(--border-strong);
}

.cell:active:not(.x):not(.o):not(:disabled) {
  transform: scale(0.96);
}

.cell:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: -2px;
}

/* Cell Marks SVG / Geometric styling */
.cell-mark {
  width: 58%;
  height: 58%;
  pointer-events: none;
  animation: pop-mark 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pop-mark {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.cell-mark.mark-x path {
  stroke: var(--x-color);
  stroke-width: 3.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--x-glow));
}

.cell-mark.mark-o circle {
  stroke: var(--o-color);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 6px var(--o-glow));
}

/* Ghost mark preview on hover */
.cell.preview-x::after,
.cell.preview-o::after {
  content: "";
  position: absolute;
  width: 48%;
  height: 48%;
  opacity: 0.22;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.cell.preview-x::after {
  background: radial-gradient(circle, var(--x-color) 10%, transparent 70%);
  border-radius: 50%;
}

.cell.preview-o::after {
  border: 3px dashed var(--o-color);
  border-radius: 50%;
}

/* Highlight Winning Cells */
.cell.cell-winner {
  background: rgba(214, 255, 92, 0.08);
  border-color: var(--win-color);
  box-shadow: inset 0 0 16px rgba(214, 255, 92, 0.2), 0 0 14px rgba(214, 255, 92, 0.25);
  animation: winner-cell-pulse 1.6s infinite alternate ease-in-out;
}

@keyframes winner-cell-pulse {
  from { border-color: rgba(214, 255, 92, 0.5); }
  to { border-color: var(--win-color); box-shadow: inset 0 0 20px rgba(214, 255, 92, 0.35); }
}

/* Hint highlight */
.cell.cell-hint {
  border-color: var(--neon);
  box-shadow: 0 0 16px var(--neon-glow), inset 0 0 12px var(--neon-glow);
  animation: hint-flash 0.8s 2 ease-in-out;
}

@keyframes hint-flash {
  0%, 100% {
    border-color: var(--neon);
    background: rgba(214, 255, 92, 0.08);
  }
  50% {
    border-color: #ffffff;
    background: rgba(214, 255, 92, 0.22);
    box-shadow: 0 0 20px var(--neon-glow), inset 0 0 16px var(--neon-glow);
  }
}

/* SVG WINNING LINE OVERLAY */
.winning-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  display: none;
}

.winning-svg.show {
  display: block;
}

.win-line {
  stroke: var(--win-color);
  stroke-width: 4;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px var(--win-color)) drop-shadow(0 0 16px var(--neon-glow));
  stroke-dasharray: 450;
  stroke-dashoffset: 450;
  animation: draw-line 0.35s ease-out forwards;
}

@keyframes draw-line {
  to {
    stroke-dashoffset: 0;
  }
}

/* PRIMARY ACTION BUTTON */
.action-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 26px;
  border-radius: 9999px;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
}

.btn-primary:hover {
  background: var(--neon);
  color: var(--bg);
  box-shadow: 0 0 24px var(--neon-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: 2px;
}

.btn-arrow {
  font-family: var(--font-mono);
  transition: transform 0.2s ease;
}

.btn-primary:hover .btn-arrow {
  transform: translateX(3px);
}

/* SETTINGS CONTROLS PANEL */
.controls-panel {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Segmented Control Pill Group */
.seg-control {
  display: flex;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 2px;
  backdrop-filter: blur(8px);
  flex: 1;
}

.seg-control.full-width {
  width: 100%;
}

.seg-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.seg-control label {
  flex: 1;
  text-align: center;
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 9999px;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}

.seg-control label:hover {
  color: var(--text);
}

.seg-control input[type="radio"]:checked + label {
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.seg-control input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--neon);
  outline-offset: 1px;
}

/* PALETTE QUICK-SWATCHES */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 6px;
}

.theme-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.theme-swatches {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  padding: 0;
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.swatch-btn:hover {
  transform: scale(1.15);
  border-color: var(--border-strong);
}

.swatch-btn.active {
  border: 2px solid var(--text);
  box-shadow: 0 0 8px rgba(237, 235, 230, 0.3);
}

.swatch-btn:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: 1px;
}

.swatch-half {
  width: 50%;
  height: 100%;
}

.swatch-mint { background: #7affd2; }
.swatch-amber { background: #ffb86b; }
.swatch-lime { background: #d6ff5c; }
.swatch-fuchsia { background: #ff52bf; }
.swatch-white { background: #edebe6; }
.swatch-dim { background: #666662; }
.swatch-orange { background: #ff7a45; }
.swatch-cyan { background: #36cfc9; }

/* UTILITY HELPERS */
.hidden {
  display: none !important;
}

/* RESPONSIVE & COMPACT ADJUSTMENTS */
@media (max-height: 640px) {
  .app-container {
    padding: 6px 12px;
    gap: 8px;
  }
  .board-frame {
    max-width: min(260px, 42vh);
    padding: 6px;
    border-radius: 14px;
  }
  .board {
    gap: 6px;
  }
  .cell {
    border-radius: 8px;
  }
  .btn-primary {
    min-height: 32px;
    padding: 6px 20px;
  }
  .status-pill {
    min-height: 26px;
    padding: 4px 10px;
    font-size: 10px;
  }
}

@media (min-width: 540px) {
  .app-container {
    max-width: 400px;
  }
}

/* REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
