/* ========================================
   Word Puzzle Free - Global Styles
   Premium NYT-inspired design system
   ======================================== */

/* Self-hosted Fonts (variable) */
@font-face {
  font-family: 'Playfair Display';
  src: url('/assets/fonts/playfair-display-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Playfair Display';
  src: url('/assets/fonts/playfair-display-latin-italic.woff2') format('woff2');
  font-weight: 400 500;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Source Sans 3';
  src: url('/assets/fonts/source-sans-3-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

/* CSS Custom Properties */
:root {
  /* Core palette */
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --text: #121213;
  --text-secondary: #5A5A5C;
  --text-muted: #878A8C;
  --border: #E2E2E0;
  --border-light: #F0F0EE;

  /* Game colors */
  --green: #6AAA64;
  --green-light: #6AAA6420;
  --yellow: #C9B458;
  --yellow-light: #C9B45820;
  --gray: #787C7E;
  --gray-light: #787C7E20;

  /* Game accent colors */
  --color-word-guess: #6AAA64;
  --color-spell-hive: #F5C242;
  --color-word-links: #8B5CF6;
  --color-letter-box: #EF4444;
  --color-word-weave: #3B82F6;
  --color-crossword: #1E293B;
  --color-mahjong: #059669;
  --color-jigsaw: #EC4899;
  --color-sudoku: #6366F1;
  --color-word-search: #F97316;
  --color-anagram: #14B8A6;
  --color-hangman: #DC2626;
  --color-word-ladder: #0891B2;
  --color-cryptogram: #7C3AED;

  /* Typography */
  --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  --space-4xl: 96px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.1);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 8px 30px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.04);

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Layout */
  --max-width: 1200px;
  --header-height: 64px;
}

/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
}

/* ========================================
   Typography
   ======================================== */

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2.2rem); }
h3 { font-size: clamp(1.2rem, 2.5vw, 1.5rem); }
h4 { font-size: 1.1rem; }

/* ========================================
   Header / Navigation
   ======================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(250, 250, 248, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  display: flex;
  align-items: center;
}

.header-inner {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.site-logo svg {
  width: 32px;
  height: 32px;
}

.site-logo-text {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-logo-text span {
  color: var(--green);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.header-nav a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
  position: relative;
}

.header-nav a:hover {
  color: var(--text);
}

.header-nav a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--green);
  transition: width var(--transition-base);
}

.header-nav a:hover::after {
  width: 100%;
}

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  transition: var(--transition-fast);
}

/* ========================================
   Hero Section (Homepage) - Enhanced
   ======================================== */

.hero {
  text-align: center;
  padding: var(--space-4xl) var(--space-lg) var(--space-3xl);
  max-width: 800px;
  margin: 0 auto;
}

.hero-enhanced {
  position: relative;
  max-width: 100%;
  padding: var(--space-3xl) var(--space-lg) var(--space-2xl);
  overflow: hidden;
  background: linear-gradient(180deg, #FAFAF8 0%, #F0F5EE 50%, #FAFAF8 100%);
}

.hero-content {
  position: relative;
  z-index: 2;
  max-width: 700px;
  margin: 0 auto;
}

/* Floating letter tiles background */
.hero-floating-tiles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.float-tile {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  animation: float-drift 12s ease-in-out infinite;
  opacity: 0.12;
}

.ft-1 { background: var(--green); top: 10%; left: 5%; animation-delay: 0s; animation-duration: 14s; }
.ft-2 { background: var(--yellow); top: 20%; right: 8%; animation-delay: -2s; animation-duration: 16s; }
.ft-3 { background: #8B5CF6; bottom: 20%; left: 10%; animation-delay: -4s; animation-duration: 13s; }
.ft-4 { background: #EC4899; top: 60%; right: 12%; animation-delay: -6s; animation-duration: 15s; }
.ft-5 { background: #3B82F6; top: 30%; left: 18%; animation-delay: -3s; animation-duration: 17s; opacity: 0.08; }
.ft-6 { background: #F97316; bottom: 30%; right: 20%; animation-delay: -5s; animation-duration: 12s; opacity: 0.08; }
.ft-7 { background: #14B8A6; top: 70%; left: 22%; animation-delay: -7s; animation-duration: 18s; opacity: 0.06; }
.ft-8 { background: #6366F1; top: 15%; right: 25%; animation-delay: -1s; animation-duration: 11s; opacity: 0.06; }

@keyframes float-drift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-12px) rotate(3deg); }
  50% { transform: translateY(-6px) rotate(-2deg); }
  75% { transform: translateY(-16px) rotate(4deg); }
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--green-light);
  color: var(--green);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 16px;
  border-radius: 100px;
  margin-bottom: var(--space-lg);
}

.hero-badge-dot {
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.hero h1 {
  margin-bottom: var(--space-md);
  color: var(--text);
}

.hero h1 em {
  font-style: italic;
  color: var(--green);
}

.hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.7;
}

/* Hero stats bar */
.hero-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xl);
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
}

.hero-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hero-stat strong {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.hero-stat span {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.hero-stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
}

/* Section header with icon */
.section-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.section-icon {
  width: 20px;
  height: 20px;
  color: var(--text);
  flex-shrink: 0;
}

/* ========================================
   Continue Playing Banner
   ======================================== */

.continue-banner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg) var(--space-xl);
}

.continue-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  padding: var(--space-xl);
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 30%, #fefce8 70%, #fff7ed 100%);
  border: 1.5px solid #bbf7d0;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(106,170,100,0.08), 0 1px 4px rgba(0,0,0,0.04);
  position: relative;
  overflow: hidden;
}

.continue-inner::before {
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(106,170,100,0.1) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.continue-inner::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: 40%;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, rgba(201,180,88,0.08) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.continue-left {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.continue-illustration {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  animation: continue-pulse 3s ease-in-out infinite;
}

@keyframes continue-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.continue-text {
  flex-shrink: 0;
}

.continue-text strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.continue-text span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.continue-games {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Rich game cards instead of plain chips */
.continue-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: 12px;
  transition: all 0.2s ease;
  text-decoration: none;
  color: var(--text);
  min-width: 180px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: relative;
  overflow: hidden;
}

.continue-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--chip-color, var(--green));
  border-radius: 3px 0 0 3px;
}

.continue-card:hover {
  border-color: var(--chip-color, var(--green));
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.continue-card-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--chip-color, var(--green)) 8%, transparent);
  border-radius: 8px;
}

.continue-card-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-grow: 1;
}

.continue-card-name {
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.2;
}

.continue-card-status {
  font-size: 0.7rem;
  color: var(--chip-color, var(--green));
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.continue-card-arrow {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.2s ease, color 0.2s ease;
}

.continue-card:hover .continue-card-arrow {
  transform: translateX(3px);
  color: var(--chip-color, var(--green));
}

@media (max-width: 768px) {
  .continue-inner {
    padding: var(--space-lg);
  }
  .continue-games {
    width: 100%;
  }
  .continue-card {
    min-width: 160px;
    flex: 1 1 calc(50% - 5px);
  }
}

@media (max-width: 480px) {
  .continue-left {
    gap: var(--space-md);
  }
  .continue-illustration {
    width: 48px;
    height: 48px;
  }
  .continue-illustration svg {
    width: 48px;
    height: 48px;
  }
  .continue-text strong {
    font-size: 1.05rem;
  }
  .continue-card {
    min-width: 140px;
    padding: 8px 12px 8px 10px;
  }
  .continue-card-icon {
    width: 32px;
    height: 32px;
  }
  .continue-card-icon svg {
    width: 24px;
    height: 18px;
  }
}

/* ========================================
   Game Grid (Homepage)
   ======================================== */

.games-section {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg) var(--space-4xl);
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--text);
}

.section-header h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-body);
  font-weight: 700;
}

.section-header span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-lg);
}

/* Game Card */
.game-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-slow), box-shadow var(--transition-slow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-light);
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-card-hover);
}

.game-card:active {
  transform: translateY(-2px);
}

.game-card-visual {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.game-card-visual svg {
  width: 64px;
  height: 64px;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.1));
}

.game-card-visual::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.08;
  background: radial-gradient(circle at 30% 40%, currentColor 0%, transparent 70%);
}

.game-card-visual::after {
  content: '';
  position: absolute;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.06;
  right: -40px;
  bottom: -60px;
}

/* Rich game preview visual (homepage only) */
.game-card-visual-rich {
  height: 200px;
  padding: 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--card-accent, #6AAA64) 3%, transparent) 0%, color-mix(in srgb, var(--card-accent, #6AAA64) 8%, transparent) 100%);
}

.game-card-visual-rich::before,
.game-card-visual-rich::after {
  display: none;
}

.game-card-visual-rich svg {
  width: 100%;
  height: 100%;
  max-height: 200px;
  filter: none;
}

.game-card-body {
  padding: var(--space-lg);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.game-card-category {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-xs);
}

.game-card-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: var(--space-sm);
  color: var(--text);
}

.game-card-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.55;
  flex: 1;
}

.game-card-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-card-play {
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  transition: gap var(--transition-fast);
}

.game-card:hover .game-card-play {
  gap: var(--space-sm);
}

.game-card-play svg {
  width: 16px;
  height: 16px;
}

.game-card-difficulty {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 3px;
}

.game-card-difficulty .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
}

.game-card-difficulty .dot.active {
  background: currentColor;
}

/* Featured game (larger card) */
.game-card.featured {
  grid-column: span 2;
}

.game-card.featured .game-card-visual {
  height: 200px;
}

/* ========================================
   Game Page Layout
   ======================================== */

.game-page {
  max-width: 700px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg) var(--space-4xl);
  min-height: calc(100vh - var(--header-height));
}

.game-page-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.game-page-title {
  font-family: var(--font-heading);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin-bottom: var(--space-sm);
}

.game-page-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* How to play modal/section */
.how-to-play-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  transition: all var(--transition-fast);
  margin-top: var(--space-sm);
}

.how-to-play-btn:hover {
  color: var(--text);
  border-color: var(--text);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
  padding: var(--space-lg);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: var(--space-xl);
  transform: translateY(20px) scale(0.98);
  transition: transform var(--transition-slow);
  box-shadow: var(--shadow-xl);
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.modal-header h3 {
  font-family: var(--font-heading);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--transition-fast);
  font-size: 1.2rem;
  color: var(--text-secondary);
}

.modal-close:hover {
  background: var(--border-light);
}

.modal-body p {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
  line-height: 1.65;
}

.modal-body ul {
  list-style: none;
  margin-bottom: var(--space-md);
}

.modal-body li {
  font-size: 0.92rem;
  color: var(--text-secondary);
  padding-left: var(--space-lg);
  position: relative;
  margin-bottom: var(--space-sm);
  line-height: 1.55;
}

.modal-body li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

/* ========================================
   Game Board Common Styles
   ======================================== */

.game-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.game-grid {
  display: grid;
  gap: 5px;
}

.game-tile {
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 1.8rem;
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--border);
  background: var(--bg-card);
  transition: border-color var(--transition-fast), transform var(--transition-fast);
  user-select: none;
}

.game-tile.filled {
  border-color: var(--gray);
  animation: pop 100ms ease;
}

.game-tile.correct {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.game-tile.present {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #fff;
}

.game-tile.absent {
  background: var(--gray);
  border-color: var(--gray);
  color: #fff;
}

@keyframes pop {
  50% { transform: scale(1.1); }
}

@keyframes flip-in {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}

.game-tile.reveal {
  animation: flip-in 500ms ease forwards;
}

/* Virtual keyboard */
.keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 auto;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  height: 52px;
  min-width: 36px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #D3D6DA;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  transform: scale(0.95);
}

.key.wide {
  min-width: 58px;
  font-size: 0.72rem;
}

.key.correct { background: var(--green); color: #fff; }
.key.present { background: var(--yellow); color: #fff; }
.key.absent { background: var(--gray); color: #fff; }

/* ========================================
   Toast / Notifications
   ======================================== */

.toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--space-md));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  animation: toast-in 300ms ease, toast-out 300ms ease 2s forwards;
  pointer-events: auto;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ========================================
   Stats / Results
   ======================================== */

.stats-row {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
  padding: var(--space-lg) 0;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========================================
   Footer
   ======================================== */

.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.footer-links a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

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

.footer-copy {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========================================
   Utility Classes
   ======================================== */

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--green);
  color: #fff;
}

.btn-primary:hover {
  background: #5a9a54;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--text);
}

/* ========================================
   Responsive Design
   ======================================== */

/* Tablet */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  .hero {
    padding: var(--space-2xl) var(--space-lg) var(--space-xl);
  }

  .hero-enhanced {
    padding: var(--space-2xl) var(--space-lg) var(--space-lg);
  }

  .float-tile {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    opacity: 0.08;
  }

  .hero-stats {
    gap: var(--space-lg);
  }

  .hero-stat strong {
    font-size: 1.3rem;
  }

  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }

  .game-card.featured {
    grid-column: span 2;
  }

  .game-card-visual {
    height: 130px;
  }

  .game-card-visual-rich {
    height: 160px;
  }

  .header-nav {
    display: none;
  }

  .header-nav.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: var(--space-lg);
    box-shadow: var(--shadow-lg);
  }

  .menu-toggle {
    display: flex;
  }

  .game-tile {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }

  .key {
    height: 48px;
    min-width: 30px;
    font-size: 0.75rem;
  }

  .key.wide {
    min-width: 50px;
  }

  .stats-row {
    gap: var(--space-md);
  }
}

/* Mobile */
@media (max-width: 480px) {
  .games-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .game-card.featured {
    grid-column: span 1;
  }

  .game-card-visual {
    height: 120px;
  }

  .game-card-visual-rich {
    height: 140px;
  }

  .hero-stats {
    gap: var(--space-md);
    flex-wrap: wrap;
  }

  .hero-stat-divider {
    display: none;
  }

  .float-tile {
    display: none;
  }

  .game-tile {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
  }

  .key {
    height: 44px;
    min-width: 26px;
    padding: 0 5px;
    font-size: 0.7rem;
  }

  .key.wide {
    min-width: 44px;
    font-size: 0.65rem;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .modal {
    padding: var(--space-lg);
  }

  .section-header {
    flex-direction: column;
    gap: var(--space-xs);
  }
}

/* ========================================
   Page Transition Animation
   ======================================== */

.page-enter {
  animation: page-enter 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

/* ========================================
   Scrollbar Styling
   ======================================== */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gray);
}

/* ========================================
   Game-specific common patterns
   ======================================== */

/* Timer */
.game-timer {
  font-family: var(--font-body);
  font-size: 1.2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Score display */
.game-score {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
}

/* Difficulty selector */
.difficulty-selector {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  margin-bottom: var(--space-lg);
}

.difficulty-btn {
  padding: 8px 20px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.difficulty-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

.difficulty-btn.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

/* Win screen */
.win-screen {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
}

.win-screen h2 {
  font-family: var(--font-heading);
  margin-bottom: var(--space-sm);
}

.win-screen p {
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

/* Loading spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: var(--space-xl) auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Back to home link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
  transition: color var(--transition-fast);
}

.back-link:hover {
  color: var(--text);
}

.back-link svg {
  width: 16px;
  height: 16px;
}

/* ========================================
   Puzzle Selector / Level Picker
   ======================================== */

.puzzle-selector {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-lg);
}

.ps-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-body);
}

.ps-toggle:hover {
  border-color: var(--ps-accent, var(--green));
  color: var(--text);
}

.ps-badge {
  font-size: 0.72rem;
  background: var(--border-light);
  padding: 2px 8px;
  border-radius: 100px;
  color: var(--text-muted);
}

.ps-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.96);
  width: 340px;
  max-width: calc(100vw - 32px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-lg);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-slow);
}

.ps-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) scale(1);
}

.ps-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.ps-panel-header h4 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
}

.ps-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-body);
}

.ps-close:hover {
  background: var(--border-light);
}

.ps-progress {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.ps-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}

.ps-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--transition-slow);
}

.ps-progress-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.ps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: var(--space-md);
  padding-right: 4px;
}

.ps-item {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  font-family: var(--font-body);
}

.ps-item:hover {
  border-color: var(--ps-accent, var(--green));
  color: var(--text);
  background: var(--bg-card);
}

.ps-item.current {
  border-color: var(--ps-accent, var(--green));
  background: var(--bg-card);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ps-accent, var(--green)) 20%, transparent);
}

.ps-item.completed {
  background: var(--ps-accent, var(--green));
  border-color: var(--ps-accent, var(--green));
  color: #fff;
}

.ps-item.in-progress {
  border-color: var(--ps-accent, var(--green));
  border-style: dashed;
  color: var(--ps-accent, var(--green));
}

.ps-check {
  position: absolute;
  top: 2px;
  right: 2px;
}

.ps-legend {
  display: flex;
  gap: var(--space-md);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.ps-legend span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ps-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1.5px solid var(--border);
  background: var(--bg);
}

.ps-dot.completed {
  background: var(--green);
  border-color: var(--green);
}

.ps-dot.in-progress {
  border-color: var(--green);
  border-style: dashed;
}

.ps-dot.current {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(106,170,100,0.2);
}

/* ========================================
   Auto-Generated Game Page Sections
   ======================================== */

.game-extra-sections {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.extra-section {
  padding: var(--space-2xl) 0;
  border-top: 1px solid var(--border-light);
}

.extra-section-inner {
  max-width: 700px;
  margin: 0 auto;
}

.extra-section-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  padding-left: var(--space-md);
  border-left: 3px solid var(--green);
}

.extra-section-content {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.75;
}

.extra-section-content p {
  margin-bottom: var(--space-md);
}

.extra-section-content ol,
.extra-section-content ul {
  padding-left: var(--space-lg);
  margin-bottom: var(--space-md);
}

.extra-section-content li {
  margin-bottom: var(--space-sm);
  line-height: 1.65;
}

/* Tips list */
.tips-list {
  list-style: none;
  padding: 0;
}

.tips-list li {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.65;
  padding: var(--space-md);
  padding-left: calc(var(--space-lg) + 8px);
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}

.tips-list li::before {
  content: '💡';
  position: absolute;
  left: var(--space-md);
  top: var(--space-md);
  font-size: 0.85rem;
}

/* FAQ Accordion */
.faq-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.faq-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
}

.faq-question {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: none;
  font-family: var(--font-body);
  transition: background var(--transition-fast);
}

.faq-question:hover {
  background: var(--border-light);
}

.faq-question svg {
  flex-shrink: 0;
  transition: transform var(--transition-base);
  color: var(--text-muted);
}

.faq-question[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-slow), padding var(--transition-slow);
  padding: 0 var(--space-lg);
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.faq-answer.open {
  max-height: 400px;
  padding: 0 var(--space-lg) var(--space-lg);
}

/* Related Games Grid */
.related-games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

.related-game-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.related-game-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.related-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 6px;
}

.related-game-card strong {
  display: block;
  font-size: 0.92rem;
  color: var(--text);
  margin-bottom: 2px;
}

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

@media (max-width: 480px) {
  .related-games-grid {
    grid-template-columns: 1fr;
  }

  .extra-section-title {
    font-size: 1.2rem;
  }
}
