/* ============================================================
   PuzzleMakerLab — style.css
   Palette: #EFF6FF (light blue), #FFFFFF (white), #FF8C42 (soft orange)
   Fonts: Fraunces (display) + DM Sans (body)
   ============================================================ */

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

:root {
  --blue-50:  #EFF6FF;
  --blue-100: #DBEAFE;
  --blue-200: #BFDBFE;
  --blue-400: #60A5FA;
  --blue-500: #3B82F6;
  --blue-600: #2563EB;
  --blue-700: #1D4ED8;
  --blue-900: #1E3A5F;

  --orange:       #FF8C42;
  --orange-light: #FFF0E6;
  --orange-dark:  #E06A1A;

  --white: #FFFFFF;
  --gray-50:  #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-600: #4B5563;
  --gray-800: #1F2937;
  --gray-900: #111827;

  --found-1: #3B82F6;
  --found-2: #10B981;
  --found-3: #F59E0B;
  --found-4: #EF4444;
  --found-5: #8B5CF6;
  --found-6: #EC4899;
  --found-7: #06B6D4;
  --found-8: #84CC16;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.14);
  --shadow-xl: 0 16px 48px rgba(0,0,0,.18);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 32px;

  --transition: .18s ease;

  --cell-size: 36px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: var(--font-body);
  background: var(--blue-50);
  color: var(--gray-800);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Screen-reader only ── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ── Container ── */
.container { max-width: 1140px; margin: 0 auto; padding: 0 24px; }

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--blue-100);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1140px; margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--blue-700);
}
.logo em { font-style: italic; color: var(--orange); }
.logo-icon { font-size: 1.4rem; }

.header-nav { display: flex; gap: 28px; }
.header-nav a {
  text-decoration: none;
  color: var(--gray-600);
  font-size: .9rem;
  font-weight: 500;
  letter-spacing: .01em;
  transition: color var(--transition);
}
.header-nav a:hover { color: var(--blue-600); }

/* ============================================================
   HERO
   ============================================================ */
.hero {
  position: relative;
  min-height: 90vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 48px;
  padding: 80px 48px;
  max-width: 1140px;
  margin: 0 auto;
  overflow: hidden;
}

/* Decorative letter grid background */
.hero-bg-grid {
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 39px, var(--blue-100) 39px, var(--blue-100) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, var(--blue-100) 39px, var(--blue-100) 40px);
  opacity: .45;
  pointer-events: none;
}

.hero-content { position: relative; z-index: 1; }

.hero-badge {
  display: inline-block;
  background: var(--orange-light);
  color: var(--orange-dark);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 100px;
  margin-bottom: 24px;
  border: 1px solid #ffd4b3;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 5vw, 4.2rem);
  font-weight: 300;
  line-height: 1.08;
  color: var(--blue-900);
  margin-bottom: 22px;
}
.hero-title em {
  font-style: italic;
  color: var(--orange);
  font-weight: 700;
}

.hero-sub {
  font-size: 1.05rem;
  color: var(--gray-600);
  max-width: 400px;
  margin-bottom: 36px;
}

.btn-hero {
  background: var(--blue-600);
  color: #fff;
  padding: 16px 36px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 20px rgba(59,130,246,.35);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn-hero:hover {
  background: var(--blue-700);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(59,130,246,.45);
}

/* Hero preview animated grid */
.hero-preview {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
}
.preview-grid {
  display: grid;
  gap: 3px;
  background: var(--white);
  padding: 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--blue-100);
}
.preview-cell {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: .9rem;
  font-weight: 700;
  color: var(--blue-700);
  border-radius: 5px;
  transition: background .3s, color .3s;
}
.preview-cell.lit {
  background: var(--orange);
  color: #fff;
  animation: litPulse 2.4s ease-in-out infinite;
}
@keyframes litPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .7; }
}

/* ============================================================
   SECTIONS
   ============================================================ */
.section { padding: 80px 0; }
.section-header { text-align: center; margin-bottom: 48px; }
.section-header h2 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  font-weight: 700;
  color: var(--blue-900);
  margin-bottom: 8px;
}
.section-header p { color: var(--gray-600); font-size: 1.05rem; }

/* ============================================================
   GENERATOR
   ============================================================ */
.generator-section { background: var(--white); }
.generator-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

/* ── Cards ── */
.card {
  background: var(--white);
  border: 1.5px solid var(--blue-100);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue-900);
  margin-bottom: 18px;
  display: flex; align-items: center; gap: 8px;
}
.card-icon { font-size: 1.1rem; }

/* ── Textarea ── */
.word-textarea {
  width: 100%; resize: vertical;
  border: 1.5px solid var(--blue-200);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--font-body);
  font-size: .95rem;
  color: var(--gray-800);
  background: var(--blue-50);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 200px;
}
.word-textarea:focus {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px rgba(96,165,250,.2);
}

.hint-text { font-size: .82rem; color: var(--gray-400); margin-top: 8px; }
.word-count-bar {
  display: flex; justify-content: space-between;
  font-size: .82rem; margin-top: 6px;
  color: var(--gray-600);
}
.word-limit { color: var(--gray-400); }

/* ── Option Groups ── */
.option-group {
  border: none; margin-bottom: 24px;
}
.option-group legend {
  font-size: .82rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--gray-400); margin-bottom: 12px;
}

/* Slider */
.slider-wrapper { display: flex; align-items: center; gap: 16px; }
.slider {
  -webkit-appearance: none;
  flex: 1; height: 6px;
  background: var(--blue-100);
  border-radius: 100px; outline: none; cursor: pointer;
  transition: background var(--transition);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  background: var(--blue-500);
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(59,130,246,.4);
  cursor: pointer;
  transition: background var(--transition);
}
.slider::-webkit-slider-thumb:hover { background: var(--blue-600); }
.slider-output {
  font-weight: 600; color: var(--blue-700);
  min-width: 56px; text-align: right; font-size: .92rem;
}

/* Toggle */
.toggle-label {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; font-size: .95rem; color: var(--gray-700);
  margin-bottom: 12px;
  user-select: none;
}
.toggle-input { display: none; }
.toggle-track {
  position: relative;
  width: 44px; height: 24px;
  background: var(--gray-200);
  border-radius: 100px;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.toggle-input:checked + .toggle-track { background: var(--blue-500); }
.toggle-input:checked + .toggle-track::after { transform: translateX(20px); }

/* Radio group */
.radio-group { display: flex; gap: 10px; }
.radio-label { cursor: pointer; }
.radio-input { display: none; }
.radio-box {
  display: block;
  padding: 8px 18px;
  border: 1.5px solid var(--blue-200);
  border-radius: 100px;
  font-size: .88rem; font-weight: 500;
  color: var(--gray-600);
  transition: all var(--transition);
}
.radio-input:checked + .radio-box {
  background: var(--blue-600);
  border-color: var(--blue-600);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59,130,246,.3);
}
.radio-box:hover { border-color: var(--blue-400); color: var(--blue-600); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px;
  font-family: var(--font-body);
  font-size: .92rem; font-weight: 600;
  border: none; border-radius: var(--radius-xl);
  cursor: pointer; text-decoration: none;
  transition: all var(--transition);
  line-height: 1;
}
.btn-primary {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 3px 12px rgba(255,140,66,.35);
}
.btn-primary:hover {
  background: var(--orange-dark);
  transform: translateY(-1px);
  box-shadow: 0 5px 18px rgba(255,140,66,.45);
}
.btn-secondary {
  background: var(--blue-50);
  color: var(--blue-700);
  border: 1.5px solid var(--blue-200);
}
.btn-secondary:hover { background: var(--blue-100); }
.btn-full { width: 100%; justify-content: center; padding: 15px; font-size: 1rem; margin-top: 8px; }

/* Error Banner */
.error-banner {
  background: #FEF2F2;
  border: 1.5px solid #FECACA;
  color: #DC2626;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-top: 20px;
  font-size: .92rem;
}

/* ============================================================
   PLAY SECTION
   ============================================================ */
.play-section { background: var(--blue-50); }
.play-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 32px;
  align-items: start;
}

/* ── Puzzle Grid ── */
.puzzle-wrapper {
  position: relative;
  display: flex; justify-content: center;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  border: 1.5px solid var(--blue-100);
  overflow: hidden;
}
.grid-shine {
  position: absolute; top: -60%; left: -60%;
  width: 220%; height: 220%;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.08) 0%, transparent 60%);
  pointer-events: none;
}
.puzzle-grid {
  display: grid;
  gap: 2px;
  user-select: none;
  touch-action: none;
}
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue-900);
  border-radius: 5px;
  cursor: pointer;
  transition: background .12s, color .12s, transform .1s;
  position: relative;
}
.cell:hover { background: var(--blue-100); }
.cell.selecting { background: var(--orange-light); color: var(--orange-dark); transform: scale(1.08); }
.cell.found { color: #fff; border-radius: 6px; }
.cell.solution { background: #FEF3C7 !important; color: var(--gray-800) !important; }

/* Dynamic word colors applied via JS */
.cell.found-0 { background: var(--found-1); }
.cell.found-1 { background: var(--found-2); }
.cell.found-2 { background: var(--found-3); color: var(--gray-800) !important; }
.cell.found-3 { background: var(--found-4); }
.cell.found-4 { background: var(--found-5); }
.cell.found-5 { background: var(--found-6); }
.cell.found-6 { background: var(--found-7); }
.cell.found-7 { background: var(--found-8); color: var(--gray-800) !important; }

/* ── Sidebar ── */
.puzzle-sidebar { display: flex; flex-direction: column; gap: 18px; }

.stats-bar {
  display: flex; align-items: center; justify-content: space-around;
  background: var(--white);
  border: 1.5px solid var(--blue-100);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.stat { text-align: center; }
.stat-value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--blue-700);
  line-height: 1;
}
.stat-label { font-size: .75rem; color: var(--gray-400); text-transform: uppercase; letter-spacing: .06em; }
.stat-divider { width: 1px; height: 40px; background: var(--blue-100); }

/* Word List */
.word-list-card { flex: 1; }
.word-list {
  list-style: none;
  display: flex; flex-wrap: wrap; gap: 8px;
  max-height: 280px; overflow-y: auto;
}
.word-item {
  display: inline-flex; align-items: center;
  padding: 6px 14px;
  background: var(--blue-50);
  border: 1.5px solid var(--blue-200);
  border-radius: 100px;
  font-size: .88rem; font-weight: 600;
  color: var(--blue-700);
  letter-spacing: .04em;
  transition: all var(--transition);
}
.word-item.found-word {
  text-decoration: line-through;
  color: var(--gray-400);
  background: var(--gray-100);
  border-color: var(--gray-200);
}

/* Action Buttons */
.action-buttons { display: flex; flex-direction: column; gap: 10px; }

/* ============================================================
   ABOUT SECTION
   ============================================================ */
.about-section { background: var(--white); }
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
  align-items: center;
}
.about-text h2 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 700;
  color: var(--blue-900);
  margin-bottom: 16px;
}
.about-text p { color: var(--gray-600); margin-bottom: 24px; font-size: 1.02rem; }
.feature-list { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.feature-list li {
  display: flex; align-items: center; gap: 12px;
  font-size: .97rem; color: var(--gray-700);
}
.feature-list li span { font-size: 1.2rem; }

.about-visual {
  display: flex; flex-wrap: wrap; gap: 16px;
  justify-content: center;
}
.about-badge {
  padding: 16px 28px;
  background: var(--blue-50);
  border: 2px solid var(--blue-200);
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue-700);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.about-badge:hover { transform: translateY(-3px); }
.about-badge.accent { background: var(--orange-light); border-color: #ffd4b3; color: var(--orange-dark); }

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  background: var(--blue-900);
  padding: 40px 24px;
  text-align: center;
  color: var(--blue-200);
}
.footer-inner .logo-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--white);
  display: block;
  margin-bottom: 8px;
}
.footer-inner .logo-text em { color: var(--orange); }
.footer-inner p { font-size: .88rem; color: var(--blue-400); }

/* ============================================================
   SUCCESS OVERLAY
   ============================================================ */
.success-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(30,58,95,.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .3s ease;
}
.success-overlay[hidden] { display: none; }
.success-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 48px 56px;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: popUp .4s cubic-bezier(.34,1.56,.64,1);
}
.success-emoji { font-size: 3.5rem; margin-bottom: 16px; }
.success-card h2 {
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: var(--blue-900);
  margin-bottom: 10px;
}
.success-card p { color: var(--gray-600); margin-bottom: 28px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popUp {
  from { opacity: 0; transform: scale(.8); }
  to { opacity: 1; transform: scale(1); }
}

/* ============================================================
   CONFETTI CANVAS
   ============================================================ */
#confettiCanvas {
  position: fixed; inset: 0; z-index: 998;
  pointer-events: none;
  width: 100%; height: 100%;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .hero { grid-template-columns: 1fr; padding: 60px 24px; min-height: auto; gap: 40px; }
  .hero-preview { display: none; }
  .play-layout { grid-template-columns: 1fr; }
  .puzzle-sidebar { flex-direction: row; flex-wrap: wrap; }
  .word-list-card { flex: 1 1 100%; }
  .action-buttons { flex-direction: row; flex: 1 1 100%; }
  :root { --cell-size: 32px; }
}

@media (max-width: 768px) {
  .generator-layout { grid-template-columns: 1fr; }
  .about-grid { grid-template-columns: 1fr; gap: 32px; }
  .hero-title { font-size: 2.4rem; }
  :root { --cell-size: 28px; }
  .cell { font-size: .85rem; }
  .header-nav { display: none; }
  .stats-bar { gap: 8px; }
  .action-buttons { flex-direction: column; }
}

@media (max-width: 480px) {
  :root { --cell-size: 24px; }
  .cell { font-size: .75rem; border-radius: 3px; }
  .puzzle-wrapper { padding: 10px; }
  .hero { padding: 40px 16px; }
  .section { padding: 50px 0; }
  .radio-group { flex-wrap: wrap; }
  .success-card { padding: 32px 24px; }
}

/* ============================================================
   LOADING STATE
   ============================================================ */
#generateBtn.loading { pointer-events: none; opacity: .7; }
#generateBtn.loading .btn-icon { display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   SCROLLBAR (webkit)
   ============================================================ */
.word-list::-webkit-scrollbar { width: 4px; }
.word-list::-webkit-scrollbar-track { background: transparent; }
.word-list::-webkit-scrollbar-thumb { background: var(--blue-200); border-radius: 2px; }
