/* DailyMind Puzzle Club — senior-friendly, offline-first, newsprint aesthetic */

:root {
  --accent: #1E3A5F;
  --accent-hover: #2A4A73;
  --accent-soft: #E8EEF5;
  --accent-ink: #0F2744;
  --bg: #F7F3EB;
  --surface: #FFFEFB;
  --surface-2: #F0EBE3;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D0C6;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08), 0 4px 16px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 8px 30px rgba(28, 25, 23, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --space: 1rem;
  --touch: 48px;
  --max: 920px;
}

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

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.45rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

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

.main-nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.65rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.nav-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.nav-btn.is-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* Main */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  width: 100%;
  flex: 1;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  color: var(--accent-ink);
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
}

/* Masthead — newspaper */
.masthead {
  text-align: center;
  padding: 1.25rem 1rem 1.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 3px double var(--accent);
  border-top: 3px double var(--accent);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.masthead-kicker {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}

.masthead-date {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.masthead-lead {
  margin-top: 0.5rem;
  max-width: 36em;
  margin-left: auto;
  margin-right: auto;
}

/* Panels & cards */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.panel-header h3 {
  margin: 0;
}

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

.danger-panel {
  border-color: #FECACA;
  background: #FFFAFA;
}

/* Stats */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .stat-value {
  display: block;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.stat-card .stat-label {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Filters */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

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

.field label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent-ink);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  width: 100%;
}

.field textarea {
  min-height: 5rem;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-actions,
.form-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.inline-form .grow {
  flex: 1 1 200px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0.55rem 1.15rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  background: var(--surface-2);
  color: var(--text);
}

.btn:hover {
  filter: brightness(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  filter: none;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--accent-ink);
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  filter: none;
}

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

.btn-danger:hover {
  background: #991B1B;
  border-color: #991B1B;
  filter: none;
}

.btn-sm {
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  min-height: 44px;
  padding: 0.35rem 0.6rem;
}

.btn-ghost:hover {
  background: var(--accent-soft);
  filter: none;
}

.icon-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  border: none;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.puzzle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.65rem;
}

.puzzle-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.puzzle-card h3,
.puzzle-card .card-title {
  margin: 0;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.card-meta {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.type-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.type-badge {
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: capitalize;
}

.type-badge.is-crossword { background: #E0E7FF; color: #3730A3; }
.type-badge.is-sudoku { background: #DCFCE7; color: #166534; }
.type-badge.is-wordsearch { background: #FEF3C7; color: #92400E; }
.type-badge.is-logic { background: #FCE7F3; color: #9D174D; }
.type-badge.is-log { background: #E7E5E4; color: #44403C; }

.status-pill {
  background: var(--surface-2);
  color: var(--text-muted);
}

.status-pill.is-completed {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.is-in_progress {
  background: var(--warn-soft);
  color: var(--warn);
}

.result-summary {
  margin: 0 0 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 2rem 1.25rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-title {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-ink);
}

/* Play board */
.play-header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.play-board {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}

.play-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.play-meta h3 {
  margin: 0.25rem 0;
  font-size: 1.25rem;
  color: var(--accent-ink);
}

.play-type-badge {
  margin: 0;
}

.play-meta-line {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.play-surface {
  margin-bottom: 1rem;
}

.play-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.play-feedback {
  min-height: 1.5em;
  margin: 0 0 1rem;
  font-weight: 600;
}

.play-feedback.is-ok {
  color: var(--success);
}

.play-feedback.is-err {
  color: var(--danger);
}

.play-feedback.is-info {
  color: var(--accent);
}

.notes-field {
  margin-top: 0.5rem;
}

/* Sudoku */
.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0;
  max-width: 420px;
  margin: 0 auto;
  border: 3px solid var(--accent);
  background: var(--accent);
}

.sudoku-grid.is-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  max-width: 320px;
}

.sudoku-cell {
  aspect-ratio: 1;
  min-height: 40px;
  border: 1px solid #A8B5C4;
  background: #fff;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 0;
  -moz-appearance: textfield;
}

.sudoku-cell::-webkit-outer-spin-button,
.sudoku-cell::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sudoku-cell.is-given {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 800;
}

.sudoku-cell.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.sudoku-cell.is-ok {
  background: var(--success-soft);
}

/* thick box borders for 9x9 */
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(9n + 1) { border-left: none; }
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(9n) { border-right: none; }
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(-n + 9) { border-top: none; }
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(n + 73) { border-bottom: none; }
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(3n) { border-right: 2px solid var(--accent); }
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(9n) { border-right: none; }
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-grid:not(.is-6) .sudoku-cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--accent);
}

/* Word search */
.ws-layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 700px) {
  .ws-layout {
    grid-template-columns: 1fr minmax(160px, 220px);
    align-items: start;
  }
}

.ws-grid {
  display: grid;
  gap: 3px;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

.ws-cell {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  color: var(--text);
}

.ws-cell.is-selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ws-cell.is-found {
  background: var(--success-soft);
  color: var(--success);
  border-color: #86EFAC;
}

.ws-words {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ws-words li {
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.35rem;
  background: var(--surface-2);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.ws-words li.is-found {
  background: var(--success-soft);
  color: var(--success);
  text-decoration: line-through;
}

.ws-hint {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Crossword */
.cw-layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 720px) {
  .cw-layout {
    grid-template-columns: auto 1fr;
    align-items: start;
  }
}

.cw-grid {
  display: grid;
  gap: 0;
  border: 2px solid var(--accent);
  width: max-content;
  max-width: 100%;
  overflow: auto;
}

.cw-cell {
  width: 44px;
  height: 44px;
  position: relative;
  border: 1px solid #A8B5C4;
  background: #fff;
  padding: 0;
}

.cw-cell.is-block {
  background: var(--accent);
  border-color: var(--accent);
}

.cw-cell input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: uppercase;
  background: transparent;
  padding: 0;
  min-height: 0;
}

.cw-cell input:focus {
  background: var(--accent-soft);
  outline: none;
}

.cw-num {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  pointer-events: none;
}

.cw-clues {
  display: grid;
  gap: 1rem;
}

@media (min-width: 500px) {
  .cw-clues {
    grid-template-columns: 1fr 1fr;
  }
}

.cw-clues h4 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  color: var(--accent);
}

.cw-clues ol {
  margin: 0;
  padding-left: 1.4rem;
}

.cw-clues li {
  margin-bottom: 0.4rem;
}

.cw-clues li.is-done {
  color: var(--success);
}

/* Logic */
.logic-prompt {
  font-size: 1.05rem;
  margin: 0 0 1rem;
  line-height: 1.55;
}

.logic-statements {
  margin: 0 0 1.15rem;
  padding: 0.9rem 1rem 0.9rem 1.5rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
}

.logic-statements li {
  margin-bottom: 0.4rem;
}

.logic-options {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 0.5rem;
}

.logic-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-height: var(--touch);
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.logic-option:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.logic-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.logic-option input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.logic-option.is-correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.logic-option.is-wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Paper log play view */
.log-play-card {
  padding: 1rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.log-play-card p {
  margin: 0 0 0.5rem;
}

/* Insights */
.insights-grid {
  display: grid;
  gap: 1rem;
}

.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}

.insight-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.insight-stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.65rem;
}

.bar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.bar-list li {
  display: grid;
  grid-template-columns: 110px 1fr 2.5rem;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.55rem;
  font-size: 0.95rem;
}

.bar-track {
  height: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
}

.upcoming-list {
  margin: 0;
  padding-left: 1.25rem;
}

.upcoming-list li {
  margin-bottom: 0.4rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 39, 68, 0.45);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(560px, 100%);
  max-height: min(90vh, 800px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-sm {
  width: min(420px, 100%);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent-ink);
}

.modal-body {
  padding: 1.15rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--accent-ink);
  color: #fff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-width: min(90vw, 420px);
  text-align: center;
  font-weight: 600;
}

.toast[hidden] {
  display: none !important;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.25rem 1.25rem 1.75rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  max-width: var(--max);
  margin-inline: auto;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
