/* ===================================================================
   Design tokens
   =================================================================== */
:root {
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  /* The hero/nav is a fixed deep-space navy in both themes — it's the
     one constant brand anchor, echoing the wider spellings site. */
  --hero-1: #050a16;
  --hero-2: #0d1730;
  --hero-3: #171034;
  --hero-border: #1c2a48;
  --hero-text: #eef1fb;
  --hero-text-dim: #93a1c2;

  --gold: #f2b445;
  --gold-strong: #e59f26;
  --indigo: #7c7ff0;
  --indigo-strong: #6367e8;
  --pink: #ef5da8;
}

[data-theme="light"] {
  --bg-page: #f5f6fb;
  --bg-card: #ffffff;
  --bg-card-soft: #eef0fa;
  --bg-input: #ffffff;

  --border: #e1e4f0;
  --border-strong: #c9cee2;

  --text-primary: #121a2b;
  --text-secondary: #5b6478;
  --text-faint: #8791a8;

  --accent: var(--gold);
  --accent-strong: var(--gold-strong);
  --accent-soft: #fbedd2;
  --accent-contrast: #241505;

  --accent-2: var(--indigo-strong);
  --accent-2-strong: #4f52d6;
  --accent-2-soft: #e7e7fc;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-strong: #b91c1c;

  --cell-bg: #ffffff;
  --cell-border: #dfe3f0;
  --cell-hover-bg: #eef1fb;
  --cell-hover-border: var(--accent-2);
  --cell-selected-bg: var(--accent-2);
  --cell-selected-border: var(--accent-2-strong);
  --cell-revealed-bg: var(--accent-soft);
  --cell-revealed-border: var(--accent);
  --cell-highlight-bg: #c026d3;
  --cell-highlight-border: #a21caf;
  --cell-found-ring: var(--success);

  --shadow-sm: 0 1px 2px rgba(18, 26, 43, 0.05), 0 1px 3px rgba(18, 26, 43, 0.06);
  --shadow-md: 0 6px 20px rgba(18, 26, 43, 0.08);
  --shadow-lg: 0 24px 60px rgba(18, 26, 43, 0.16);

  --star-opacity: 0;
}

[data-theme="dark"] {
  --bg-page: #08101f;
  --bg-card: #101a2e;
  --bg-card-soft: #0b1526;
  --bg-input: #0b1526;

  --border: #202f4c;
  --border-strong: #304264;

  --text-primary: #eef1fb;
  --text-secondary: #97a3c4;
  --text-faint: #64709e;

  --accent: var(--gold);
  --accent-strong: #ffcb6b;
  --accent-soft: rgba(242, 180, 69, 0.14);
  --accent-contrast: #1a1206;

  --accent-2: var(--indigo);
  --accent-2-strong: #9497f9;
  --accent-2-soft: rgba(134, 137, 247, 0.16);

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-strong: #ef4444;

  --cell-bg: #0c1728;
  --cell-border: #223154;
  --cell-hover-bg: #17233d;
  --cell-hover-border: var(--accent-2);
  --cell-selected-bg: var(--accent-2);
  --cell-selected-border: var(--accent-2-strong);
  --cell-revealed-bg: var(--accent-soft);
  --cell-revealed-border: var(--accent);
  --cell-highlight-bg: #d946ef;
  --cell-highlight-border: #c026d3;
  --cell-found-ring: var(--success);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, 0.55);

  --star-opacity: 1;
}

/* ===================================================================
   Base
   =================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.15s ease;
}

html, body {
  background: var(--bg-page);
}

body {
  font-family: "Inter", "Segoe UI", sans-serif;
  color: var(--text-primary);
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: "Inter", sans-serif;
}

.display-font {
  font-family: "Unbounded", "Inter", sans-serif;
}

.mono {
  font-family: "Space Mono", monospace;
  letter-spacing: 0.02em;
}

@media (prefers-reduced-motion: reduce) {
  * , *::before, *::after { animation: none !important; }
}

/* Soft starfield wash across the page body in dark mode only */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--star-opacity);
  background-image:
    radial-gradient(1px 1px at 10% 20%, #ffffff 0, transparent 60%),
    radial-gradient(1px 1px at 80% 10%, #ffffff 0, transparent 60%),
    radial-gradient(1.5px 1.5px at 60% 40%, #ffffff 0, transparent 60%),
    radial-gradient(1px 1px at 30% 65%, #ffffff 0, transparent 60%),
    radial-gradient(1px 1px at 90% 75%, #ffffff 0, transparent 60%),
    radial-gradient(1.5px 1.5px at 45% 85%, #ffffff 0, transparent 60%),
    radial-gradient(1px 1px at 15% 92%, #ffffff 0, transparent 60%),
    radial-gradient(1px 1px at 70% 55%, #ffffff 0, transparent 60%);
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.app-shell { position: relative; z-index: 1; }

/* ===================================================================
   Hero (always the deep-space brand moment, both themes)
   =================================================================== */
.hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(120% 140% at 15% -10%, var(--hero-3) 0%, transparent 55%),
    radial-gradient(90% 120% at 100% 0%, #16264a 0%, transparent 50%),
    linear-gradient(160deg, var(--hero-1) 0%, var(--hero-2) 100%);
  color: var(--hero-text);
  border-bottom: 1px solid var(--hero-border);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 6% 25%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 14% 65%, #fff 0, transparent 55%),
    radial-gradient(1.5px 1.5px at 24% 40%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 36% 80%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 52% 15%, #fff 0, transparent 55%),
    radial-gradient(1.5px 1.5px at 64% 55%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 76% 30%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 88% 68%, #fff 0, transparent 55%),
    radial-gradient(1.5px 1.5px at 95% 20%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 44% 92%, #fff 0, transparent 55%);
  opacity: 0.6;
}

.hero-nav {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hero-content {
  position: relative;
  z-index: 2;
  text-align: center;
}

/* Twinkle accents — a handful, not a shower */
.twinkle {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  z-index: 1;
  opacity: 0.75;
  animation: twinkle 3.4s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 0.9; transform: scale(1.15); }
}

.constellation { position: absolute; z-index: 1; pointer-events: none; opacity: 0.5; }

/* Logo mark: star + search loop */
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--indigo) 0%, var(--gold) 100%);
  color: #12101f;
  flex-shrink: 0;
  box-shadow: 0 6px 20px rgba(124, 127, 240, 0.35);
}

.wordmark {
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--hero-text);
}
.wordmark .slash {
  background: linear-gradient(100deg, var(--gold) 0%, var(--pink) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-title {
  font-weight: 700;
  line-height: 1.05;
  background: linear-gradient(100deg, #ffffff 10%, var(--gold) 55%, var(--pink) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-tagline {
  color: var(--hero-text-dim);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.eyebrow::before, .eyebrow::after {
  content: "";
  width: 20px;
  height: 1px;
  background: currentColor;
  opacity: 0.5;
}

/* Theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--hero-border);
  color: var(--hero-text);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.12); }
.theme-toggle svg { width: 14px; height: 14px; }

/* ===================================================================
   Surfaces & cards
   =================================================================== */
.surface-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.input-card {
  position: relative;
  z-index: 3;
  margin-top: -3.5rem;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.icon-btn svg, .icon-btn img { width: 18px; height: 18px; }

textarea#wordInput {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-primary);
  font-family: "Inter", sans-serif;
}
textarea#wordInput::placeholder { color: var(--text-faint); }
textarea#wordInput:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px var(--accent-2-soft);
}

/* ===================================================================
   Buttons
   =================================================================== */
.btn {
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-pill);
  padding: 0.7rem 1.5rem;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(120deg, var(--accent-strong), var(--accent));
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-card-soft);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--border-strong); }

.btn-accent2 {
  background: linear-gradient(120deg, var(--accent-2-strong), var(--accent-2));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-accent2:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-strong); }

button:hover::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  animation: shimmer 0.6s infinite;
  border-radius: inherit;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ===================================================================
   Word list — a small "constellation" checklist
   =================================================================== */
#wordList {
  position: relative;
  padding-left: 1.25rem;
}
#wordList::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--border-strong);
}

.word-chip {
  position: relative;
  background: var(--bg-card-soft);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
}
.word-chip::before {
  content: "";
  position: absolute;
  left: -1.25rem;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px var(--bg-card);
}
.word-chip:hover {
  border-color: var(--accent-2);
  background: var(--accent-2-soft);
}
.word-chip.word-found {
  text-decoration: line-through;
  opacity: 0.6;
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--text-secondary);
}
.word-chip.word-found::before { background: var(--success); }

/* ===================================================================
   Modals
   =================================================================== */
.modal-backdrop { background: rgba(5, 9, 20, 0.6); backdrop-filter: blur(3px); }
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
}
.stat-tile {
  background: var(--bg-card-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.stat-tile.accent2 .stat-value { color: var(--accent-2); }
.stat-tile.accent .stat-value { color: var(--accent-strong); }

/* ===================================================================
   Word search grid
   =================================================================== */
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0.3; } }
@keyframes fadeIn { from { opacity: 0.3; } to { opacity: 1; } }

#canvas { position: fixed; pointer-events: none; z-index: 45; display: none; }
#canvas.show { display: block; }

.grid-frame {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  padding: 1.5rem;
}
.grid-frame::before, .grid-frame::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  opacity: 0.75;
  border-radius: 3px;
}
.grid-frame::before {
  top: 8px; left: 8px;
  border-right: none; border-bottom: none;
}
.grid-frame::after {
  bottom: 8px; right: 8px;
  border-left: none; border-top: none;
}

#wordSearch.regenerating { animation: fadeOut 0.3s ease-in-out forwards; }
#wordSearch.regenerated { animation: fadeIn 0.5s ease-in-out forwards; }

@media print {
  body { background: white; }
  body::before { display: none; }
  .max-w-7xl { max-width: 100%; }
  #inputArea, #printButton, #regenerateIcon, #shareIcon, #customizeIcon,
  #aboutIcon, #restartButton, #wordListContainer, #footer, .hidden,
  .text-center, .hero {
    display: none !important;
  }
  .grid-frame { box-shadow: none; border: none; }
}

#wordSearch {
  display: grid;
  grid-template-columns: repeat(var(--cols, 12), 1fr);
  grid-template-rows: repeat(var(--cols, 12), 1fr);
  gap: 0;
  width: min(560px, 86vw);
  aspect-ratio: 1 / 1;
  place-items: stretch;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

#wordSearch div {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--cell-border);
  background-color: var(--cell-bg);
  color: var(--text-primary);
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-weight: 500;
  font-size: clamp(9px, calc(290px / var(--cols, 12)), 19px);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  transition: all 0.15s ease;
  user-select: none;
}
#wordSearch div:hover {
  background-color: var(--cell-hover-bg);
  border-color: var(--cell-hover-border);
  box-shadow: inset 0 0 0 1px var(--cell-hover-border);
  z-index: 1;
}
#wordSearch div.revealed {
  background-color: var(--cell-revealed-bg);
  border-color: var(--cell-revealed-border);
  font-weight: 700;
}
#wordSearch div.highlighted {
  background-color: var(--cell-highlight-bg);
  border-color: var(--cell-highlight-border);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 10px var(--cell-highlight-bg);
  z-index: 2;
}
#wordSearch div.selected {
  background-color: var(--cell-selected-bg);
  border-color: var(--cell-selected-border);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 8px var(--cell-selected-bg);
  z-index: 2;
}
#wordSearch div.found {
  border: 2px solid var(--cell-found-ring);
  box-shadow: inset 0 0 0 1px var(--cell-found-ring);
}

/* Mobile layout - word list above grid */
@media (max-width: 1023px) {
  #gridContainer { order: 2; }
  #wordListContainer { order: 1; width: fit-content; margin: 0 auto; }
}

/* ===================================================================
   Footer
   =================================================================== */
.site-footer {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(80% 140% at 85% 0%, var(--hero-3) 0%, transparent 55%),
    linear-gradient(180deg, var(--hero-2) 0%, var(--hero-1) 100%);
  color: var(--hero-text-dim);
  border-top: 1px solid var(--hero-border);
}
.site-footer::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 30%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 32% 70%, #fff 0, transparent 55%),
    radial-gradient(1.5px 1.5px at 55% 20%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 78% 55%, #fff 0, transparent 55%),
    radial-gradient(1px 1px at 92% 20%, #fff 0, transparent 55%);
  opacity: 0.5;
}
.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--hero-text);
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--hero-border);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-pill);
  padding: 0.6rem 1.2rem;
}
.footer-link:hover { background: rgba(255, 255, 255, 0.1); }
.footer-sub {
  color: var(--hero-text-dim);
  font-size: 0.85rem;
}
.footer-sub a { color: var(--gold); text-decoration: none; }
.footer-sub a:hover { text-decoration: underline; }
