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

:root {
  --bg: #f5f3ee;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #ccc;
  --border-strong: #1a1a1a;
  --cell-hl: #ddeeff;
  --cell-sel: #88bbee;
  --cell-ok: #d4edda;
  --cell-err: #f8d7da;
  --accent: #1a1a1a;
  --accent-fg: #ffffff;
  --success-bg: #d4edda;
  --success-fg: #155724;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --bg-card: #242424;
    --text: #f0ede6;
    --text-muted: #999;
    --border: #444;
    --border-strong: #f0ede6;
    --cell-hl: #1a2a3a;
    --cell-sel: #1a3a5c;
    --cell-ok: #1a3a1a;
    --cell-err: #3a1a1a;
    --accent: #f0ede6;
    --accent-fg: #1a1a1a;
    --success-bg: #1a3a1a;
    --success-fg: #6fcf8a;
  }
}

body {
  font-family: 'Libre Baskerville', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 2rem 1rem 4rem;
}

#app {
  max-width: 820px;
  margin: 0 auto;
}

header {
  margin-bottom: 2rem;
}

h1 {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 4px;
}

.tagline {
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
}

#input-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.input-row {
  display: flex;
  gap: 10px;
}

#theme-input {
  flex: 1;
  font-family: 'Libre Baskerville', serif;
  font-size: 16px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

#theme-input:focus { border-color: var(--border-strong); }
#theme-input::placeholder { color: var(--text-muted); font-style: italic; }

#generate-btn {
  font-family: 'Libre Baskerville', serif;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 22px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

#generate-btn:hover { opacity: 0.8; }
#generate-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.options-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

#word-count-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  width: 56px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  text-align: center;
}

#word-count-input:focus { border-color: var(--border-strong); }

#status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  min-height: 18px;
}

#status.error { color: #c0392b; font-style: normal; }

#puzzle-title {
  font-size: 22px;
  font-weight: 700;
  font-style: italic;
  margin-bottom: 1.25rem;
  letter-spacing: -0.5px;
}

#puzzle-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

#grid-area { flex: 0 0 auto; }

#crossword-grid {
  border-collapse: collapse;
  border: 2px solid var(--border-strong);
}

#crossword-grid td {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  position: relative;
  padding: 0;
  cursor: pointer;
}

#crossword-grid td.black {
  background: var(--border-strong);
  cursor: default;
}

#crossword-grid td.highlight { background: var(--cell-hl); }
#crossword-grid td.selected { background: var(--cell-sel) !important; }
#crossword-grid td.correct  { background: var(--cell-ok) !important; }
#crossword-grid td.wrong    { background: var(--cell-err) !important; }

.cell-num {
  position: absolute;
  top: 2px;
  left: 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  color: var(--text-muted);
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

#crossword-grid td input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  caret-color: transparent;
  text-transform: uppercase;
  padding-top: 9px;
  cursor: pointer;
}

#controls {
  margin-top: 1rem;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ctrl-btn {
  font-family: 'Libre Baskerville', serif;
  font-size: 13px;
  padding: 7px 16px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}

.ctrl-btn:hover { background: var(--bg); }

#score-bar {
  margin-top: 1rem;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

#congrats {
  margin-top: 0.75rem;
  padding: 10px 16px;
  background: var(--success-bg);
  color: var(--success-fg);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
}

#clues-area {
  flex: 1;
  min-width: 200px;
}

.clue-group { margin-bottom: 1.5rem; }

.clue-group h3 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.clue-item {
  display: flex;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 5px;
  cursor: pointer;
  margin-bottom: 3px;
  align-items: flex-start;
  transition: background 0.1s;
}

.clue-item:hover { background: var(--cell-hl); }
.clue-item.active { background: var(--cell-hl); }
.clue-item.solved { opacity: 0.45; }

.clue-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  min-width: 22px;
  padding-top: 2px;
  flex-shrink: 0;
}

.clue-text { font-size: 13px; line-height: 1.45; }

.clue-star {
  font-size: 9px;
  color: var(--text-muted);
  vertical-align: super;
  margin-right: 2px;
  line-height: 1;
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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