/* Word Weaver — friendly, readable, high contrast */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --yellow: #ca8a04;
  --green: #15803d;
  --blue: #1d4ed8;
  --purple: #7c3aed;
  --red: #ea580c;
  --border: #94a3b8;
  --font: "Nunito", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.4;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 2px solid var(--surface-alt);
}

h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin: 0 0 0.25rem 0;
  letter-spacing: 0.02em;
}

.site-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.site-logo {
  display: block;
  vertical-align: middle;
  flex-shrink: 0;
}

.tagline {
  color: var(--muted);
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.controls select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  cursor: pointer;
}

.controls select:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

button {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.15);
}

button:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: var(--surface-alt);
}

.settings-wrap {
  position: relative;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  min-width: 40px;
}

.settings-icon {
  display: block;
}

.settings-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 10rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  overflow: hidden;
}

.settings-dropdown[hidden] {
  display: none;
}

.settings-dropdown-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.settings-dropdown-item:hover {
  background: var(--surface-alt);
}

#strikes-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1.25rem;
  min-height: 48px;
  flex-wrap: wrap;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.strikes-bar-group {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.strikes-label,
.score-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 3.5rem;
}

#strikes-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

#score-value {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  min-width: 2ch;
  text-align: left;
}

.strike-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s, box-shadow 0.2s;
}

.strike-dot.used {
  background: var(--red);
  box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.35);
}

#solved-groups {
  display: none;
}

/* Wrapped completed group: title inline with cells, compact row */
#solved-groups-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.solved-group-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  border-radius: 12px;
  padding: 0.4rem 0.75rem 0.5rem;
  border: 2px solid;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.solved-group-wrap.yellow { border-color: #eab308; background: #fefce8; }
.solved-group-wrap.green  { border-color: #22c55e; background: #f0fdf4; }
.solved-group-wrap.blue  { border-color: #3b82f6; background: #eff6ff; }
.solved-group-wrap.purple { border-color: #8b5cf6; background: #f5f3ff; }

.solved-group-title {
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  min-width: 5rem;
}

.solved-group-wrap.yellow .solved-group-title { color: #854d0e; }
.solved-group-wrap.green .solved-group-title  { color: #166534; }
.solved-group-wrap.blue .solved-group-title   { color: #1e40af; }
.solved-group-wrap.purple .solved-group-title { color: #5b21b6; }

.solved-group-cells {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.solved-group-cells .cell {
  aspect-ratio: 2.5;
  font-size: clamp(0.75rem, 2.5vw, 0.9rem);
  padding: 0.25rem 0.35rem;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.solved-group-cells .cell-defn-trigger {
  display: none;
}

/* Mobile: stack category title above the 4 words so the row isn’t too long */
@media (max-width: 600px) {
  #grid-wrap {
    min-width: 0;
  }
  .solved-group-wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    overflow: hidden;
  }
  .solved-group-title {
    min-width: 0;
    text-align: center;
    font-size: 0.8rem;
  }
  .solved-group-cells {
    min-width: 0;
  }
  /* Scale text on small screens; allow wrapping only at spaces (e.g. "Wonder Woman") */
  #grid .cell {
    container-type: inline-size;
  }
  #grid .cell .cell-word {
    font-size: min(0.85rem, 14cqw);
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
  }
}

#grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  min-width: 0;
}

.cell {
  position: relative;
  aspect-ratio: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
  font-weight: 700;
  font-size: clamp(0.85rem, 3vw, 1rem);
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
  color: var(--text);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
  min-width: 0;
}

.cell:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.cell-word {
  display: block;
  width: 100%;
  min-width: 0;
  text-align: center;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.2;
  padding: 0 0.5rem;
}

.cell-defn-trigger {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 1.25em;
  height: 1.25em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: help;
  line-height: 1;
  opacity: 0.9;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.cell-defn-trigger:hover {
  opacity: 1;
  color: var(--text);
  background: var(--surface);
  border-color: var(--muted);
}

.definition-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 300px;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.45;
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.08);
  pointer-events: auto;
  display: none;
  left: 0;
  top: 0;
}

.definition-tooltip[aria-hidden="false"] {
  display: block;
}

.definition-tooltip .definition-word {
  font-weight: 700;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  display: block;
}

.definition-tooltip .definition-text {
  display: block;
}

.cell:hover:not(.solved):not(.selected) {
  border-color: var(--muted);
  background: var(--surface-alt);
  transform: scale(1.02);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

.cell.selected {
  border-color: var(--red);
  background: #ffedd5;
  color: var(--red);
}

.cell.wrong-guess {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: var(--text);
}

.cell.solved {
  cursor: default;
  border-color: transparent;
  color: #0f172a;
}

.cell.solved.yellow { background: #fef9c3; border: 1px solid #fde047; }
.cell.solved.green  { background: #dcfce7; border: 1px solid #86efac; }
.cell.solved.blue   { background: #dbeafe; border: 1px solid #93c5fd; }
.cell.solved.purple { background: #ede9fe; border: 1px solid #c4b5fd; }

#grid-wrap .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

#submit {
  margin-right: 0.5rem;
  padding: 0.55rem 1.25rem;
  font-size: 1rem;
}

.message {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  min-height: 2.25rem;
  line-height: 1.4;
}

.message.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.message.error {
  background: #ffedd5;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.message.info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.error-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.error-actions[hidden] {
  display: none;
}

.reveal-area {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
}

.reveal-area h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  color: var(--muted);
}

.reveal-area .reveal-group {
  margin-bottom: 0.75rem;
}

.reveal-area .reveal-group:last-child {
  margin-bottom: 0;
}

.reveal-area .reveal-group strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.reveal-area .reveal-words {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.reveal-area .reveal-words span {
  background: var(--surface-alt);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--text);
}

#grid:empty + #submit,
#grid:empty + #submit + #deselect {
  display: none;
}

.actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* How to play modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-title {
  margin: 0;
  padding: 1.25rem 1.5rem 0.5rem;
  font-size: 1.35rem;
  font-weight: 800;
}

.modal-body {
  padding: 0.5rem 1.5rem 1rem;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal-body h3 {
  margin: 1rem 0 0.4rem;
  font-size: 1rem;
  color: var(--muted);
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body p,
.modal-body ul {
  margin: 0 0 0.6rem;
}

.modal-body ul {
  padding-left: 1.25rem;
}

.modal-body li {
  margin-bottom: 0.35rem;
}

.modal-close {
  margin: 0 1.5rem 1.25rem;
  align-self: flex-start;
}

/* Kid-friendly modal overrides */
.modal-content--kids {
  max-width:  min(420px, 92vw);
  max-height: 88vh;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.modal-title--kids {
  font-size: 1.5rem;
  padding: 1.5rem 1.5rem 0.25rem;
  letter-spacing: 0.02em;
}

.modal-body--kids {
  padding: 0.75rem 1.5rem 1.25rem;
  font-size: 1.05rem;
  line-height: 1.65;
}

.modal-body--kids .modal-section {
  margin-bottom: 1.25rem;
}

.modal-body--kids .modal-section:last-of-type {
  margin-bottom: 0;
}

.modal-body--kids .modal-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.6rem 0;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--surface-alt);
}

.modal-body--kids .modal-step {
  margin: 0 0 0.75rem 0;
}

.modal-body--kids .modal-step:last-of-type {
  margin-bottom: 0;
}

.modal-body--kids .modal-list {
  margin: 0.4rem 0 0.75rem 1.5rem;
  padding: 0;
  list-style: none;
}

.modal-body--kids .modal-list li {
  margin-bottom: 0.35rem;
  padding-left: 0.25rem;
}

.modal-body--kids .modal-list li::before {
  content: "• ";
  color: var(--blue);
  font-weight: 700;
}

.modal-close--kids {
  margin: 0 1.5rem 1.5rem;
  padding: 0.6rem 1.5rem;
  font-size: 1.05rem;
  border-radius: 12px;
  align-self: center;
}

/* Print puzzle: hidden on screen, shown when printing */
.print-puzzle {
  display: none;
}

@media print {
  body {
    margin: 0;
    padding: 0;
  }
  body * {
    display: none !important;
  }
  body .container {
    display: block !important;
  }
  body .container > * {
    display: none !important;
  }
  body .container > .print-puzzle {
    display: block !important;
  }
  body .print-puzzle .print-puzzle-title,
  body .print-puzzle .print-puzzle-cell {
    display: block !important;
  }
  body .print-puzzle {
    position: static;
    width: 100%;
    padding: 1.5rem;
    font-family: var(--font);
    color: #000;
    background: #fff;
    page-break-after: avoid;
  }
  body .print-puzzle .print-puzzle-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    max-width: 400px;
    margin-top: 1rem;
  }
  body .print-puzzle .print-puzzle-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0 0 0.5rem 0;
  }
  body .print-puzzle .print-puzzle-cell {
    padding: 0.5rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.95rem;
    border: 2px solid #333;
  }
}

/* Confetti container: fixed overlay, pointer-events none */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  display: none;
}

.confetti-container.active {
  display: block;
}

.confetti-particle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 1px;
  left: 50%;
  top: 50%;
  animation: confetti-fall 2.5s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--cf-x), var(--cf-y)) rotate(720deg);
    opacity: 0;
  }
}
