:root {
  /* board surface -- kept light so marks/grid stay crisp and readable */
  --paper: #F7F5F1;
  --grid: #C9D6E3;
  --ink: #2B3A4A;
  --ink-soft: #5B6B7C;
  --highlight: #F2C14E;

  /* accent palette -- used for marks, tabs, glows, and CTA gradients */
  --neon-pink: #FF2E9A;
  --neon-cyan: #23E7E7;
  --neon-lime: #C6FF3C;
  --neon-purple: #9B5CFF;
  --neon-orange: #FF8C3C;

  /* dark page chrome -- everything outside the board surface */
  --page-text: #F3F1EC;
  --page-text-soft: rgba(243, 241, 236, 0.62);
  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-bg-strong: rgba(255, 255, 255, 0.14);
  --glass-border: rgba(255, 255, 255, 0.20);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  color: var(--page-text);
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  position: relative;
  overflow-x: hidden;
  background: linear-gradient(135deg, #10121c 0%, #1a1830 26%, #362c47 50%, #7c6459 72%, #e9cfb1 88%, #f4e4d4 100%);
}

body::before, body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(70px);
  z-index: 0;
  pointer-events: none;
}

body::before {
  width: 440px;
  height: 440px;
  top: -140px;
  left: -140px;
  background: radial-gradient(circle, rgba(35, 231, 231, 0.22), transparent 70%);
}

body::after {
  width: 500px;
  height: 500px;
  bottom: -180px;
  right: -180px;
  background: radial-gradient(circle, rgba(255, 170, 110, 0.30), transparent 70%);
}

.sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  padding: 36px 32px 32px;
}

header {
  text-align: center;
  margin-bottom: 18px;
}

h1 {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 44px;
  margin: 0;
  color: var(--page-text);
  line-height: 1;
}

.dot { font-weight: 700; }
.dot-cyan { color: var(--neon-cyan); }
.dot-pink { color: var(--neon-pink); }

.subtitle {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--page-text-soft);
  margin: 10px 0 0;
}

.streak-badge {
  display: inline-block;
  margin: 14px 0 0;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--page-text);
  background: var(--glass-bg);
  border: 1.5px solid transparent;
  border-radius: 24px;
  padding: 7px 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgba(255, 140, 60, 0.4), 0 0 18px rgba(255, 90, 140, 0.35);
}

.streak-badge[hidden] { display: none; }

.status {
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 15px;
  min-height: 22px;
  margin: 16px 0 18px;
  color: var(--page-text);
}

.status.win { color: var(--neon-pink); }
.status.win.o-win { color: var(--neon-cyan); }
.status.thinking { color: var(--page-text-soft); }

.mode-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.mode-toggle {
  display: inline-flex;
  border: 1.5px solid var(--glass-border);
  border-radius: 24px;
  overflow: hidden;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
}

.mode-btn {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--page-text-soft);
  background: transparent;
  border: none;
  padding: 9px 18px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-btn.active {
  background: linear-gradient(90deg, var(--neon-pink), var(--neon-cyan));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 18px rgba(35, 231, 231, 0.4), 0 0 18px rgba(255, 46, 154, 0.3);
}

.mode-btn:not(.active):hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--page-text);
}

.difficulty {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--page-text);
  background: var(--glass-bg);
  border: 1.5px solid var(--glass-border);
  border-radius: 24px;
  padding: 9px 14px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgba(35, 231, 231, 0.22), 0 0 14px rgba(35, 231, 231, 0.16);
}

.scorecard {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 26px;
}

.tab {
  flex: 1;
  max-width: 120px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 14px 10px 12px;
  text-align: center;
  backdrop-filter: blur(14px);
}

.tab-label {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--page-text);
  margin: 0 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-count {
  font-family: 'Fraunces', serif;
  font-size: 30px;
  font-weight: 700;
  margin: 0;
}

.tab.x-tab .tab-count { color: var(--neon-pink); }
.tab.o-tab .tab-count { color: var(--neon-cyan); }
.tab.tie-tab .tab-count { color: var(--page-text-soft); }

.tab-count::after {
  content: "";
  display: block;
  width: 34px;
  height: 3px;
  margin: 9px auto 0;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.85;
}

.board-wrap {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 0 auto 24px;
  background: var(--paper);
  border-radius: 28px;
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.35),
    0 0 26px rgba(255, 46, 154, 0.35),
    0 0 44px rgba(35, 231, 231, 0.28),
    0 24px 54px rgba(0, 0, 0, 0.35);
}

.board-wrap.size-4 { width: 320px; height: 320px; }
.board-wrap.size-5 { width: 340px; height: 340px; }

svg.grid-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cells {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
}

.cells.disabled {
  pointer-events: none;
}

.cell {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell:focus-visible {
  outline: none;
}
.cell:focus-visible svg.mark-svg {
  outline: 2px dashed var(--ink-soft);
  outline-offset: 4px;
  border-radius: 6px;
}

.cells.turn-x .cell:hover:not(.filled) {
  box-shadow: inset 0 0 0 3px var(--neon-pink), 0 0 14px rgba(255, 46, 154, 0.35);
  border-radius: 10px;
}

.cells.turn-o .cell:hover:not(.filled) {
  box-shadow: inset 0 0 0 3px var(--neon-cyan), 0 0 14px rgba(35, 231, 231, 0.35);
  border-radius: 10px;
}

.cell.hint {
  border-radius: 10px;
  animation: hintPulse 1s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 0 0 3px var(--neon-lime), 0 0 10px rgba(198, 255, 61, 0.4); }
  50% { box-shadow: inset 0 0 0 3px var(--neon-lime), 0 0 24px rgba(198, 255, 61, 0.9); }
}

@media (prefers-reduced-motion: reduce) {
  .cell.hint {
    animation: none;
    box-shadow: inset 0 0 0 3px var(--neon-lime), 0 0 10px rgba(198, 255, 61, 0.5);
  }
}

.cell svg.mark-svg {
  width: 70%;
  height: 70%;
  max-width: 76px;
  max-height: 76px;
  overflow: visible;
}

.mark-stroke {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 9;
  stroke-dasharray: 170;
  stroke-dashoffset: 170;
  transition: stroke-dashoffset 0.32s ease;
}

.cell.filled .mark-stroke {
  stroke-dashoffset: 0;
}

.cell.filled .mark-stroke.stroke-2 {
  transition-delay: 0.15s;
}

.x-color { stroke: var(--neon-pink); }
.o-color { stroke: var(--neon-cyan); }

.win-line {
  stroke: var(--highlight);
  stroke-width: 22;
  stroke-linecap: round;
  fill: none;
  opacity: 0.65;
  stroke-dasharray: 400;
  stroke-dashoffset: 400;
  transition: stroke-dashoffset 0.4s ease;
}

.win-line.drawn {
  stroke-dashoffset: 0;
  filter: drop-shadow(0 0 6px rgba(198, 255, 61, 0.85));
}

.cell.won-cell { position: relative; z-index: 2; }

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.ticket {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, var(--neon-pink), var(--neon-cyan));
  border: none;
  border-radius: 24px;
  padding: 11px 24px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 0 22px rgba(255, 46, 154, 0.45), 0 0 22px rgba(35, 231, 231, 0.35), 0 10px 24px rgba(0, 0, 0, 0.3);
}

.ticket:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 28px rgba(255, 46, 154, 0.6), 0 0 28px rgba(35, 231, 231, 0.5), 0 14px 30px rgba(0, 0, 0, 0.35);
}

.ticket:active {
  transform: translateY(0) scale(0.98);
}

.reset-scores {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--page-text-soft);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 6px;
}

.reset-scores:hover { color: var(--page-text); }

@media (max-width: 420px) {
  .sheet { padding: 28px 20px 24px; }
  .board-wrap { width: 260px; height: 260px; }
  .board-wrap.size-4 { width: 280px; height: 280px; }
  .board-wrap.size-5 { width: 300px; height: 300px; }
  h1 { font-size: 34px; }
}

/* ---- corner buttons (names / stats) -------------------------------- */

.corner-btn {
  position: absolute;
  top: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--page-text);
  background: var(--glass-bg);
  border: 1.5px solid var(--glass-border);
  border-radius: 24px;
  padding: 7px 14px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: box-shadow 0.15s ease, background 0.15s ease;
}

.corner-btn.left {
  left: 16px;
  box-shadow: 0 0 0 1px rgba(35, 231, 231, 0.3), 0 0 14px rgba(35, 231, 231, 0.25);
}

.corner-btn.right {
  right: 16px;
  box-shadow: 0 0 0 1px rgba(155, 92, 255, 0.35), 0 0 14px rgba(155, 92, 255, 0.3);
}

.corner-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* ---- shared overlay (name modal + win popup + stats modal) -------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 16, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.modal-card, .popup-card {
  background: linear-gradient(160deg, rgba(38, 34, 56, 0.94), rgba(18, 17, 28, 0.96));
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 30px 26px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5);
  text-align: center;
  color: var(--page-text);
  backdrop-filter: blur(20px);
}

.modal-title, .popup-title {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  margin: 0 0 18px;
  color: var(--page-text);
}

.modal-title { font-size: 22px; }

.field {
  margin-bottom: 14px;
  text-align: left;
}

.field[hidden] { display: none; }

.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--page-text-soft);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--glass-border);
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--page-text);
}

.field input::placeholder { color: rgba(243, 241, 236, 0.4); }

.field input:focus {
  outline: 2px solid var(--neon-cyan);
  outline-offset: 1px;
}

#save-names { margin-top: 4px; }

/* ---- stats modal ------------------------------------------------- */

.stats-card {
  max-width: 340px;
  text-align: left;
}

.stats-card .modal-title { text-align: center; }

.stat-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.stat-chip {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}

.stat-chip-value {
  display: block;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--page-text);
}

.stat-chip-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--page-text-soft);
  margin-top: 2px;
}

.stats-breakdown {
  margin: 16px 0 4px;
}

.breakdown-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.breakdown-label {
  color: var(--page-text);
  font-weight: 600;
}

.breakdown-detail {
  color: var(--page-text-soft);
}

.breakdown-empty {
  font-size: 13px;
  color: var(--page-text-soft);
  text-align: center;
  margin: 10px 0;
}

.achievements-title {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--page-text);
  margin: 14px 0 8px;
  text-align: center;
}

.achievements-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.achievement-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  border: 1.5px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--page-text-soft);
}

.achievement-chip.unlocked {
  background: rgba(255, 255, 255, 0.08);
  color: var(--page-text);
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--neon-lime), 0 0 14px rgba(198, 255, 61, 0.5);
}

.achievement-chip.locked {
  border-style: dashed;
  opacity: 0.65;
}

.achievement-icon { font-size: 13px; }
.achievement-label { line-height: 1.2; }

/* ---- win popup ------------------------------------------------------ */

.popup-title {
  font-size: 28px;
  margin-bottom: 22px;
}

.popup-card.win .popup-title { color: var(--neon-pink); }
.popup-card.win {
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5), 0 0 0 3px var(--neon-lime), 0 0 34px rgba(198, 255, 61, 0.4);
}

.popup-card.tie .popup-title { color: var(--page-text-soft); font-size: 24px; }

.popup-subtitle {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-style: italic;
  color: var(--page-text-soft);
  margin: -12px 0 20px;
}

.popup-subtitle[hidden] { display: none; }

.popup-card.animate {
  animation: stampIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes stampIn {
  0% { transform: scale(0.7) rotate(-8deg); opacity: 0; }
  70% { transform: scale(1.05) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(-1deg); opacity: 1; }
}

.popup-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.popup-dismiss {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--page-text-soft);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 4px;
}

.popup-dismiss:hover { color: var(--page-text); }

/* ---- undo / hint buttons ------------------------------------------ */

.undo-btn {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--page-text);
  background: var(--glass-bg);
  border: 1.5px solid var(--glass-border);
  border-radius: 24px;
  padding: 10px 18px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.undo-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.undo-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#hint-move {
  box-shadow: 0 0 0 1px rgba(242, 193, 78, 0.4), 0 0 16px rgba(242, 193, 78, 0.35);
}

#hint-move:hover:not(:disabled) {
  box-shadow: 0 0 0 1px rgba(242, 193, 78, 0.6), 0 0 22px rgba(242, 193, 78, 0.55);
}

/* ---- instant (non-animated) board redraw, used by undo/new round -- */

.cells.instant .mark-stroke {
  transition: none;
}

/* ---- confetti (win celebration) ----------------------------------- */

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 60;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation-name: confettiFall;
  animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--drift), 112vh) rotate(var(--rot)); opacity: 0; }
}
