/* ════════════════════════════════════════════
   VARIABLES & RESET
════════════════════════════════════════════ */
:root {
  --bg:        #f0f4ff;
  --surface:   #ffffff;
  --surface2:  #f1f5f9;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --text-muted:#64748b;
  --accent:    #6366f1;
  --accent-dk: #4f46e5;
  --sel:       #818cf8;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(99,102,241,.12);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ════════════════════════════════════════════
   LAYOUT SHELL
════════════════════════════════════════════ */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ════════════════════════════════════════════
   HEADER
════════════════════════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: .12em;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.header-meta .sep { color: var(--border); }
.diff-label { color: var(--text); }
.header-progress { color: var(--accent); }
.timer { font-variant-numeric: tabular-nums; color: var(--text); }
.timer-icon { font-size: .9rem; }

/* ════════════════════════════════════════════
   SETUP SCREEN
════════════════════════════════════════════ */
.setup-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.setup-section h2 {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Theme buttons */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: border-color .15s, background .15s, color .15s, transform .1s;
}
.theme-btn .ti { font-size: 1.5rem; line-height: 1; }
.theme-btn:hover { border-color: var(--accent); color: var(--accent); }
.theme-btn.active {
  border-color: var(--accent);
  background: #eef2ff;
  color: var(--accent);
}
.theme-btn:active { transform: scale(.96); }

/* Difficulty buttons */
.diff-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 6px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s, transform .1s;
}
.diff-btn strong { font-size: .88rem; color: var(--text); }
.diff-btn small  { font-size: .7rem; color: var(--text-muted); }
.diff-btn:hover  { border-color: var(--accent); }
.diff-btn.active {
  border-color: var(--accent);
  background: #eef2ff;
}
.diff-btn.active strong { color: var(--accent); }
.diff-btn:active { transform: scale(.96); }

/* ════════════════════════════════════════════
   SHARED BUTTONS
════════════════════════════════════════════ */
.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
  font-size: .85rem;
  padding: 10px 18px;
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn:active { transform: scale(.96); }
.btn-full { width: 100%; }

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,.35);
}
.btn-primary:hover { background: var(--accent-dk); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

/* ════════════════════════════════════════════
   GAME SCREEN
════════════════════════════════════════════ */
.game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow: hidden;
}

.game-layout {
  flex: 1;
  display: flex;
  flex-direction: row;
  gap: 20px;
  align-items: flex-start;
  min-height: 0;
}

/* ─── Grid ──────────────────────────────────── */
.grid-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

#grid {
  display: grid;
  grid-template-columns: repeat(var(--gs, 10), 1fr);
  gap: 2px;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  width: min(480px, min(90vw, calc(100dvh - 230px)));
  aspect-ratio: 1;
  flex-shrink: 0;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-size: var(--cfs, 16px);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  aspect-ratio: 1;
}

.cell.selecting {
  background: var(--sel) !important;
  color: white !important;
}

.cell.found {
  background: var(--wc, #fde047);
  color: #1a1a2e;
}

.cell.found.revealed {
  background: #d1d5db !important;
  color: #9ca3af !important;
}

.cell.hinting {
  animation: hint-blink 0.45s ease infinite alternate;
}

@keyframes hint-blink {
  from { background: var(--surface); }
  to   { background: #fef08a; color: #713f12; }
}

/* ─── Sidebar ────────────────────────────────── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-title {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.word-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  overflow-y: auto;
  max-height: calc(100dvh - 280px);
}

.word-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--surface2);
  transition: opacity .3s;
}

.word-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,.08);
}

.word-text {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text);
  transition: all .25s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word-item.found .word-text {
  text-decoration: line-through;
  color: var(--text-muted);
  opacity: .65;
}

.word-item.found.revealed .word-text {
  color: #9ca3af;
}

.word-item.hinting {
  animation: item-blink .45s ease infinite alternate;
}

@keyframes item-blink {
  from { background: var(--surface2); }
  to   { background: #fef9c3; }
}

/* Sidebar actions */
.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: auto;
}

/* ─── Progress bar ────────────────────────────── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #818cf8, #a855f7);
  border-radius: 99px;
  transition: width .4s cubic-bezier(.4,0,.2,1);
}

.progress-text {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ════════════════════════════════════════════
   WIN MODAL
════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  padding: 16px;
}

.modal-content {
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: modal-pop .35s cubic-bezier(.34,1.56,.64,1) both;
}

@keyframes modal-pop {
  from { transform: scale(.8) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0);     opacity: 1; }
}

.win-icon {
  font-size: 3.5rem;
  animation: bounce-in .5s cubic-bezier(.34,1.56,.64,1) both;
}

@keyframes bounce-in {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

.modal-content h2 {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text);
}

.win-stats {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 16px;
  background: var(--surface2);
  border-radius: 10px;
}

.ws-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.ws-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

/* ════════════════════════════════════════════
   UTILITIES
════════════════════════════════════════════ */
.hidden { display: none !important; }

/* ════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 660px)
════════════════════════════════════════════ */
@media (max-width: 660px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }

  #grid {
    width: min(420px, 95vw);
  }

  .sidebar {
    width: 100%;
    max-width: 480px;
  }

  .word-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
    max-height: none;
    overflow: visible;
  }

  .sidebar-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-actions .btn { flex: 1; min-width: 80px; }

  .progress-wrap {
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    text-align: center;
  }
}

@media (max-width: 380px) {
  .theme-grid { grid-template-columns: repeat(2, 1fr); }
  .diff-group  { grid-template-columns: 1fr; }
  .setup-card  { padding: 22px 16px; }
}

/* ════════════════════════════════════════════
   SEO / ACCESSIBILITY ADDITIONS
════════════════════════════════════════════ */

/* Screen-reader only text (visually hidden but indexable) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Descriptive paragraph visible to crawlers, subtle to users */
.seo-description {
  font-size: .72rem;
  color: var(--text-muted);
  line-height: 1.55;
  text-align: center;
  opacity: .7;
  margin-top: -8px;
}
