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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fafafa;
  color: #1a1a1a;
  min-height: 100vh;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a1a;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.nav-links a {
  color: #555;
  text-decoration: none;
}

.nav-links a:hover {
  color: #1a1a1a;
}

.nav-link-btn {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: inherit;
}

.nav-link-btn:hover {
  color: #1a1a1a;
}

.inline-form {
  display: inline;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.game-header {
  text-align: center;
  margin-bottom: 2rem;
}

.game-header h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.game-header p {
  color: #666;
}

.game-instruction {
  text-align: center;
  color: #666;
  margin-bottom: 2rem;
  transition: opacity 0.3s ease;
}

.game-instruction.fade-out {
  opacity: 0;
}

.game-instruction.fade-in {
  opacity: 1;
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.word-tile {
  padding: 1rem;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  background: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  word-break: break-word;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 75px;
}

.word-tile:hover {
  border-color: #888;
  background: #f5f5f5;
}

.word-tile.selected {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.game-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 24px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: #1a1a1a;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #333;
}

.btn-secondary {
  background: #fff;
  color: #1a1a1a;
  border: 2px solid #d0d0d0;
}

.btn-secondary:hover {
  border-color: #888;
}

.btn-danger {
  background: #dc3545;
  color: #fff;
}

.btn-danger:hover {
  background: #c82333;
}

.mistake-counter {
  text-align: center;
  color: #666;
  font-size: 0.875rem;
}

.solved-groups {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.solved-group {
  padding: 1rem;
  border: 2px solid transparent;
  border-radius: 8px;
  text-align: center;
}

.solved-group { background: #e8e8e8; }

/* ── Style variants ─────────────────────────────────────────────── */

/* Shades: solve-order reflected by progressively darker gray */
#game-area.style-shades .solved-group:nth-child(1) { background: #e8e8e8; color: #1a1a1a; }
#game-area.style-shades .solved-group:nth-child(2) { background: #c8c8c8; color: #1a1a1a; }
#game-area.style-shades .solved-group:nth-child(3) { background: #909090; color: #fff; }
#game-area.style-shades .solved-group:nth-child(4) { background: #505050; color: #fff; }

/* Badges: neutral white cards with ordinal counter in corner */
#game-area.style-badges .solved-groups { counter-reset: group-counter; }
#game-area.style-badges .solved-group {
  background: #fff;
  border-color: #e0e0e0;
  position: relative;
  counter-increment: group-counter;
}
#game-area.style-badges .solved-group::before {
  content: counter(group-counter);
  position: absolute;
  top: 0.4rem;
  right: 0.65rem;
  font-size: 1.5rem;
  font-weight: 800;
  color: #d0d0d0;
  line-height: 1;
}

/* Borders: thick colored left border, white card, non-NYT palette */
#game-area.style-borders .solved-group {
  background: #fff;
  border-left-width: 5px;
  border-radius: 0 8px 8px 0;
}
#game-area.style-borders .solved-group:nth-child(1) { border-left-color: #0ea5e9; }
#game-area.style-borders .solved-group:nth-child(2) { border-left-color: #f97316; }
#game-area.style-borders .solved-group:nth-child(3) { border-left-color: #a855f7; }
#game-area.style-borders .solved-group:nth-child(4) { border-left-color: #10b981; }

/* Patterns: distinct CSS hatching / dot textures */
#game-area.style-patterns .solved-group:nth-child(1) {
  background: repeating-linear-gradient(45deg, #e0e0e0, #e0e0e0 2px, #f5f5f5 2px, #f5f5f5 10px);
}
#game-area.style-patterns .solved-group:nth-child(2) {
  background: repeating-linear-gradient(-45deg, #e0e0e0, #e0e0e0 2px, #f5f5f5 2px, #f5f5f5 10px);
}
#game-area.style-patterns .solved-group:nth-child(3) {
  background: repeating-linear-gradient(90deg, #e0e0e0, #e0e0e0 2px, #f5f5f5 2px, #f5f5f5 10px);
}
#game-area.style-patterns .solved-group:nth-child(4) {
  background: radial-gradient(circle, #c8c8c8 1.5px, #f5f5f5 1.5px) 0 0 / 10px 10px;
}

/* Elevation: increasing box-shadow depth per solve order */
#game-area.style-elevation .solved-group { background: #fff; }
#game-area.style-elevation .solved-group:nth-child(1) { box-shadow: 0 1px 3px rgba(0,0,0,0.10); }
#game-area.style-elevation .solved-group:nth-child(2) { box-shadow: 0 3px 8px rgba(0,0,0,0.15); }
#game-area.style-elevation .solved-group:nth-child(3) { box-shadow: 0 6px 16px rgba(0,0,0,0.20); }
#game-area.style-elevation .solved-group:nth-child(4) { box-shadow: 0 10px 28px rgba(0,0,0,0.28); }

/* ── Floating style picker (dev only) ───────────────────────────── */
#style-picker {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  font-family: inherit;
}

#style-picker-toggle {
  padding: 0.5rem 1rem;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.7;
}

#style-picker-toggle:hover { opacity: 1; }

#style-picker-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 8rem;
}

#style-picker-menu[hidden] { display: none; }

#style-picker-menu button {
  padding: 0.4rem 0.75rem;
  background: none;
  border: none;
  border-radius: 6px;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  color: #333;
}

#style-picker-menu button:hover { background: #f0f0f0; }
#style-picker-menu button.active { background: #1a1a1a; color: #fff; }

.solved-group-connection {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.solved-group-words {
  font-size: 0.875rem;
  text-transform: uppercase;
}

.win-message {
  text-align: center;
  padding: 2rem;
  background: #f0f8e8;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  animation: fadeIn 0.5s ease;
}

.win-message h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.error-message,
.incorrect-message {
  text-align: center;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-weight: 500;
  animation: shake 0.3s ease;
}

.error-message {
  background: #fdecea;
  color: #d32f2f;
}

.incorrect-message {
  background: #fff3e0;
  color: #e65100;
}

.new-game-container {
  text-align: center;
  margin-top: 1rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Auth pages */
.auth-container {
  max-width: 400px;
  margin: 4rem auto;
  text-align: center;
}

.auth-container h1 {
  margin-bottom: 0.5rem;
}

.auth-container p {
  color: #666;
  margin-bottom: 1.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-form label {
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
}

.auth-form input[type="text"] {
  padding: 0.75rem;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  font-size: 1rem;
}

.auth-status {
  font-size: 0.875rem;
  min-height: 1.25rem;
}

.auth-status.error {
  color: #d32f2f;
}

.auth-status.success {
  color: #388e3c;
}

.auth-switch {
  margin-top: 2rem;
  color: #666;
}

.auth-switch a {
  color: #1a1a1a;
  font-weight: 600;
}

/* My Games */
.my-games-container h1 {
  margin-bottom: 1rem;
}

.game-count {
  color: #666;
  font-size: 0.875rem;
  margin: 1rem 0;
}

.limit-notice {
  color: #e65100;
  font-weight: 500;
  margin: 1rem 0;
}

.empty-state {
  color: #999;
  text-align: center;
  padding: 3rem;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.game-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 1.25rem;
}

.game-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}

.game-card-header h3 {
  font-size: 1rem;
}

.game-date {
  font-size: 0.75rem;
  color: #999;
}

.game-card-groups {
  margin-bottom: 1rem;
}

.game-card-group {
  font-size: 0.8rem;
  padding: 0.25rem 0;
  color: #555;
}

.game-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.share-url {
  flex: 1;
}

.share-url label {
  display: block;
  font-size: 0.75rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.share-url input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font-size: 0.75rem;
  background: #f5f5f5;
}

/* Create game form */
.create-container h1 {
  margin-bottom: 0.5rem;
}

.create-container > p {
  color: #666;
  margin-bottom: 1.5rem;
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-field label {
  font-weight: 600;
  font-size: 0.875rem;
}

.form-field input {
  padding: 0.75rem;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  font-size: 0.875rem;
}

.group-fieldset {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
}

.group-fieldset legend {
  font-weight: 700;
  padding: 0 0.5rem;
}

.group-fieldset .form-field + .form-field {
  margin-top: 0.75rem;
}

/* Not found page */
.not-found {
  text-align: center;
  padding: 4rem 0;
}

.not-found h1 {
  margin-bottom: 1rem;
}

.not-found p {
  color: #666;
  margin-bottom: 2rem;
}

/* Error page */
.error-page {
  text-align: center;
  padding: 4rem 0;
}

.error-page h1 {
  margin-bottom: 1rem;
}

.error-page p {
  color: #666;
  margin-bottom: 2rem;
}

/* Privacy badges */
.privacy-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

.privacy-badge.public {
  background-color: #10b981;
  color: white;
}

.privacy-badge.private {
  background-color: #6b7280;
  color: white;
}

.game-card-privacy {
  margin-top: 1rem;
}

/* Browse page */
.browse-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.browse-container h1 {
  margin-bottom: 2rem;
}

.browse-list {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.browse-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.5rem;
  background: white;
  transition: box-shadow 0.2s;
}

.browse-card:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.browse-card-header h3 {
  margin: 0 0 0.75rem 0;
}

.browse-card-header h3 a {
  color: #1f2937;
  text-decoration: none;
}

.browse-card-header h3 a:hover {
  color: #3b82f6;
}

.browse-card-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
  color: #6b7280;
  font-size: 0.875rem;
}

.browse-card-actions {
  margin-top: 1rem;
}

@media (max-width: 480px) {
  .word-tile {
    padding: 0.75rem 0.25rem;
    font-size: 0.75rem;
  }

  .container {
    padding: 1rem 0.5rem;
  }
}
