/* ==========================================================================
   Tic Tac Toe - Clean, Accessible, Zero-Dependency CSS
   ========================================================================== */

:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #273549;
  --board-bg: #1e2538;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --color-x: #38bdf8;
  --color-o: #f59e0b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-focus: #38bdf8;
  --success: #10b981;
  --border: #334155;
  --border-light: #475569;
  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
  --transition-fast: 0.15s ease;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Accessibility helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.hidden {
  display: none !important;
}

/* Base Styles */
body {
  font-family: var(--font);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.site-header {
  background-color: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.nav-back-link:hover {
  color: var(--text-main);
  background-color: var(--bg-surface-hover);
}

.nav-back-link:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

.game-badge {
  background-color: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Main Container */
.main-wrapper {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Hero Title */
.game-hero {
  text-align: center;
}

.game-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.game-subtitle {
  color: var(--text-muted);
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  max-width: 600px;
  margin: 0 auto;
}

/* Game Surface Card */
.game-card-surface {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  position: relative;
}

/* Mode Bar */
.mode-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.segmented-control {
  display: flex;
  background-color: rgba(15, 23, 42, 0.8);
  padding: 0.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  gap: 0.25rem;
}

.segment-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.segment-btn:hover {
  color: var(--text-main);
}

.segment-btn.active {
  background-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}

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

.difficulty-group {
  display: flex;
  background-color: rgba(15, 23, 42, 0.8);
  padding: 0.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  gap: 0.25rem;
}

.btn-diff {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-diff:hover {
  color: var(--text-main);
}

.btn-diff.active {
  background-color: rgba(99, 102, 241, 0.35);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.5);
}

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

/* Status Panel */
.status-panel {
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: center;
}

.turn-indicator {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-main);
}

.mark-x {
  color: var(--color-x);
}

.mark-o {
  color: var(--color-o);
}

.scores-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.score-box {
  background-color: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.5rem;
  display: flex;
  flex-direction: column;
}

.score-tag {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.score-val {
  font-size: 1.25rem;
  font-weight: 800;
  margin-top: 0.15rem;
}

.box-x .score-val { color: var(--color-x); }
.box-ties .score-val { color: var(--text-muted); }
.box-o .score-val { color: var(--color-o); }

/* Toolbar Controls */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.instructions-pill {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  background-color: rgba(15, 23, 42, 0.6);
  padding: 0.4rem 0.8rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
}

.utility-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-icon {
  background-color: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-light);
}

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

.btn-action {
  background-color: var(--accent);
  border: none;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.9rem;
  height: 44px;
  padding: 0 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.btn-action:hover {
  background-color: var(--accent-hover);
}

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

/* Board Architecture */
.board-wrapper {
  display: flex;
  justify-content: center;
  margin: 0 auto;
}

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1 / 1;
  background-color: var(--board-bg);
  padding: 10px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.ttt-cell {
  background-color: #0f172a;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14%;
  outline: none;
  transition: all var(--transition-fast);
  position: relative;
}

.ttt-cell:hover:not(:disabled) {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent);
  transform: scale(1.02);
}

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

.ttt-cell:disabled {
  cursor: default;
}

.ttt-cell.winning-cell {
  background-color: rgba(99, 102, 241, 0.25);
  border-color: #818cf8;
  animation: winCellPulse 0.6s ease-in-out infinite alternate;
}

@keyframes winCellPulse {
  0% { transform: scale(1); box-shadow: 0 0 10px rgba(129, 140, 248, 0.3); }
  100% { transform: scale(1.05); box-shadow: 0 0 20px rgba(129, 140, 248, 0.6); }
}

.mark-svg {
  width: 100%;
  height: 100%;
  display: block;
  animation: markAppear 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes markAppear {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Modal Overlay */
.modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modalScaleUp 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalScaleUp {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-icon-wrapper {
  margin-bottom: 0.75rem;
  display: inline-flex;
}

.victory-heading {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.victory-subtext {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.btn-primary-modal {
  background-color: var(--accent);
  color: #ffffff;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.85rem 1.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
  min-height: 48px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
  transition: background-color var(--transition-fast);
}

.btn-primary-modal:hover {
  background-color: var(--accent-hover);
}

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

/* SEO Content Section */
.content-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 3vw, 2.25rem);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.meta-freshness {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.meta-dot {
  color: var(--border-light);
}

.content-section h2 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.85rem;
  letter-spacing: -0.015em;
}

.content-section p {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.content-list {
  padding-left: 1.25rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.content-list strong {
  color: var(--text-main);
}

.content-list em {
  color: #cbd5e1;
  font-style: normal;
  font-weight: 600;
}

/* FAQ Accordion */
.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  background-color: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.faq-item[open] {
  border-color: var(--border-light);
}

.faq-question {
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: "+";
  font-size: 1.3rem;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.faq-item[open] .faq-question::after {
  content: "−";
  color: var(--accent);
}

.faq-question:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: -2px;
}

.faq-answer {
  padding: 0 1.25rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.faq-answer p {
  margin: 0;
}

/* Cross-Link Cards */
.cross-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.cross-link-card {
  background-color: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.cross-link-card:hover {
  border-color: var(--accent);
  background-color: var(--bg-surface-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.cross-link-card:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

.cl-title {
  color: var(--text-main);
  font-weight: 700;
  font-size: 1.05rem;
}

.cl-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Site Footer */
.site-footer {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 1.75rem 1rem;
  margin-top: auto;
}

.footer-container {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--text-main);
}

.footer-links a:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  .footer-container {
    flex-direction: row;
    justify-content: space-between;
  }
}
