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

:root {
  --text-primary: #111;
  --text-secondary: #666;
  --bg: #fff;
  --border: #e5e5e5;
  --accent: #111;
  --cell-size: clamp(26px, 3.8vw, 38px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */

.screen { display: none; }
.screen.active { display: block; }

/* ── Entry screen ─────────────────────────────────────────────────────────── */

#entry-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 4rem 1.5rem;
}

.entry-container {
  width: min(480px, 100%);
}

h1 {
  font-size: 3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
  line-height: 1.6;
}

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

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
}

.hint {
  font-weight: 400;
  color: var(--text-secondary);
}

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.75rem;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  background: var(--bg);
  color: var(--text-primary);
  transition: border-color 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--text-primary);
}

.btn-ghost {
  background: none;
  border: none;
  padding: 0;
  margin-top: 0.6rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 1px solid var(--text-secondary);
  transition: opacity 0.2s;
}

.btn-ghost:hover { opacity: 0.6; }

/* Settings */
.settings {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
  padding: 0.75rem 0;
  width: 100%;
}

.toggle input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-label {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.validation-msg {
  font-size: 0.85rem;
  color: #c00;
  min-height: 1.2rem;
  margin-bottom: 1rem;
}

/* Primary button */
.btn-primary {
  width: 100%;
  padding: 0.75rem;
  background: var(--text-primary);
  color: var(--bg);
  border: 1px solid var(--text-primary);
  border-radius: 0;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover { opacity: 0.75; }
.btn-primary:active { opacity: 0.6; }

/* ── Game screen ──────────────────────────────────────────────────────────── */

#game-screen.active {
  display: block;
  padding: 3rem 1.5rem;
  max-width: 960px;
  margin: 0 auto;
}

.game-layout {
  display: flex;
  gap: 3rem;
  align-items: flex-start;
}

/* Grid */
.grid-area { flex: 1; min-width: 0; }

.grid {
  display: inline-grid;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  user-select: none;
  touch-action: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.42);
  font-weight: 600;
  letter-spacing: 0;
  background: var(--bg);
  cursor: pointer;
  transition: background 0.08s;
}

.cell.selected {
  background: #e8e8e8;
  color: var(--text-primary);
}

.cell.found {
  background: #111;
  color: #fff;
}

/* Sidebar */
.sidebar {
  width: 180px;
  flex-shrink: 0;
  padding-top: 0.25rem;
}

.sidebar h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.word-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.word-list li {
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  transition: color 0.15s;
  letter-spacing: -0.01em;
}

.word-list li.found-word {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.btn-secondary {
  margin-top: 1.5rem;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 1px solid var(--text-secondary);
  transition: opacity 0.2s;
}

.btn-secondary:hover { opacity: 0.6; }

/* Win overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.win-overlay.hidden { display: none; }

.win-box {
  text-align: center;
  padding: 3rem 2rem;
}

.win-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  line-height: 1;
}

.win-box h2 {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
}

.win-box .btn-primary {
  width: auto;
  padding: 0.65rem 2rem;
}

/* Shake animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-5px); }
  40%       { transform: translateX(5px); }
  60%       { transform: translateX(-3px); }
  80%       { transform: translateX(3px); }
}

.grid.shake { animation: shake 0.32s ease; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  h1 { font-size: 2rem; }

  #game-screen.active { padding: 1.5rem 1rem; }

  .game-layout {
    flex-direction: column;
    gap: 1.5rem;
  }

  .sidebar { width: 100%; }

  .word-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0 1.25rem;
  }

  .word-list li { border-bottom: none; }
}
