.back-link {
  display: inline-block;
  margin-bottom: 0.6rem;
}

.stat-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.4rem;
  min-width: 180px;
  animation: grid-item-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.stat-tile:nth-child(2) {
  animation-delay: 0.04s;
}

.stat-tile:nth-child(3) {
  animation-delay: 0.08s;
}

.stat-tile:nth-child(4) {
  animation-delay: 0.12s;
}

.stat-tile:nth-child(5) {
  animation-delay: 0.16s;
}

.stat-tile:nth-child(6) {
  animation-delay: 0.2s;
}

/* Compound selector, not just .stat-grid-3x2 — dashboard.css defines its
   own later-loaded .stat-row { display: flex }, which otherwise wins this
   property over a single-class .stat-grid-3x2 rule regardless of source
   order within this file, silently turning the grid back into flex-wrap. */
.stat-row.stat-grid-3x2 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 1rem;
}

.stat-grid-3x2 .stat-tile {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (max-width: 700px) {
  .stat-row.stat-grid-3x2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text-primary);
}

.muted {
  color: var(--text-muted);
}

/* Account page */
.account-card {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.account-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.account-name {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.account-edit-link {
  margin-top: 0.8rem;
  display: inline-block;
  text-decoration: none;
}

.account-stat-row {
  margin-top: 1.5rem;
}

.puzzle-rush-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.offline-puzzle-banner {
  border-color: #f0b429;
  margin-bottom: 0.8rem;
}

.offline-puzzle-banner-title {
  font-weight: 700;
  color: #f0b429;
}

.offline-download-btn {
  margin-bottom: 0.4rem;
}

.offline-download-status {
  font-size: 0.8rem;
  margin-bottom: 1rem;
}

.puzzle-rush-banner:hover {
  border-color: var(--accent);
}

.puzzle-rush-banner-title {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.15rem;
}

.puzzle-rush-banner-score {
  font-size: 1.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  flex-shrink: 0;
}

.puzzle-rush-banner-score .muted {
  display: block;
  font-size: 0.7rem;
  font-weight: normal;
}

.puzzle-rush-try-btn {
  flex-shrink: 0;
  text-decoration: none;
}

.sync-code-card {
  margin-top: 1.5rem;
}

.achievements-card {
  margin-top: 1.5rem;
}

.achievements-card h2 {
  margin-top: 0;
}

.achievements-card h2 .muted {
  font-size: 0.85rem;
  font-weight: normal;
  margin-left: 0.4rem;
}

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.7rem;
}

.achievement-badge {
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  cursor: pointer;
  animation: grid-item-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.achievement-badge:nth-child(2) {
  animation-delay: 0.03s;
}

.achievement-badge:nth-child(3) {
  animation-delay: 0.06s;
}

.achievement-badge:nth-child(4) {
  animation-delay: 0.09s;
}

.achievement-badge:nth-child(5) {
  animation-delay: 0.12s;
}

.achievement-badge:nth-child(6) {
  animation-delay: 0.15s;
}

.achievement-badge:nth-child(7) {
  animation-delay: 0.18s;
}

.achievement-badge:nth-child(8) {
  animation-delay: 0.21s;
}

.achievement-badge.earned {
  background: var(--now-bg, rgba(168, 85, 247, 0.15));
  border-color: var(--accent);
}

.achievement-badge.locked {
  background: var(--surface);
  opacity: 0.5;
}

.achievement-badge-name {
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.achievement-badge.earned .achievement-badge-name {
  color: var(--accent-soft);
}

.achievement-badge-desc {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.achievements-card.compact .achievements-grid {
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.4rem;
}

.achievements-card.compact .achievement-badge {
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
}

.achievements-card.compact .achievement-badge-name {
  font-size: 0.74rem;
  margin-bottom: 0;
}

.achievements-card.compact .achievement-badge-desc {
  display: none;
}

.account-about-card {
  margin-top: 1.5rem;
}

.account-about-card h2 {
  margin-top: 0;
}

.account-about-card a {
  color: var(--accent-soft);
}

/* Settings page */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  max-width: 480px;
}

.settings-card h2 {
  margin-top: 0;
  font-size: 1rem;
  color: var(--text-secondary);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.field:last-child {
  margin-bottom: 0;
}

.field input[type="range"] {
  accent-color: var(--accent);
}

.field-hint {
  font-size: 0.82rem;
  margin-top: 0.5rem;
}

.setting-row {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.setting-row:last-child {
  margin-bottom: 0;
}

.setting-label {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}

.setting-hint {
  font-size: 0.8rem;
  margin-top: 0.1rem;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 0.1rem;
  cursor: pointer;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::before {
  transform: translateX(18px);
  background: #fff;
}

.theme-picker {
  display: flex;
  gap: 0.5rem;
}

.theme-option {
  flex: 1;
  padding: 0.5rem 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}

.theme-option.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-on);
}

.board-swatch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.board-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.board-swatch-purple {
  background: linear-gradient(135deg, #d9d2e0 50%, #4b3a66 50%);
}

.board-swatch-green {
  background: linear-gradient(135deg, #eeeed2 50%, #769656 50%);
}

.board-swatch-blue {
  background: linear-gradient(135deg, #dee3e6 50%, #4b7399 50%);
}

.board-swatch-slate {
  background: linear-gradient(135deg, #e3e3e3 50%, #6b6b6b 50%);
}

.field input[type="text"],
.field input[type="number"],
.field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.danger-zone {
  max-width: 480px;
  margin-top: 1.5rem;
  border-color: var(--danger);
}

.danger-zone h2 {
  margin-top: 0;
  color: var(--danger);
  font-size: 1rem;
}

.danger-zone p {
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.sync-code-block {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 420px;
}

.sync-code-generate {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
}

.sync-generated-code {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sync-code-value {
  font-family: monospace;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  color: var(--accent-soft);
  width: fit-content;
}

.sync-code-divider {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sync-code-redeem {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.sync-code-redeem input {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: monospace;
}

#sync-redeem-status {
  min-height: 1.1rem;
}

/* Openings collection */
.opening-summary-card {
  margin-bottom: 1.5rem;
  max-width: 260px;
}

.opening-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.8rem;
}

.opening-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
  animation: grid-item-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.opening-card:hover {
  background: var(--surface-2);
}

.opening-card:nth-child(2) {
  animation-delay: 0.03s;
}

.opening-card:nth-child(3) {
  animation-delay: 0.06s;
}

.opening-card:nth-child(4) {
  animation-delay: 0.09s;
}

.opening-card:nth-child(5) {
  animation-delay: 0.12s;
}

.opening-card:nth-child(6) {
  animation-delay: 0.15s;
}

.opening-eco {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-soft);
  margin-bottom: 0.2rem;
}

.opening-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.opening-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Your Games */
.games-review-btn,
.games-delete-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.games-delete-btn {
  margin-left: 0.4rem;
  color: var(--danger);
  border-color: var(--danger);
}

/* Puzzles */
.puzzle-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 480px;
}

.puzzle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.15s ease;
  animation: grid-item-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.puzzle-card:nth-child(2) {
  animation-delay: 0.03s;
}

.puzzle-card:nth-child(3) {
  animation-delay: 0.06s;
}

.puzzle-card:nth-child(4) {
  animation-delay: 0.09s;
}

.puzzle-card:nth-child(5) {
  animation-delay: 0.12s;
}

.puzzle-card:nth-child(6) {
  animation-delay: 0.15s;
}

.puzzle-card:hover {
  background: var(--surface-2);
}

.puzzle-card.solved {
  opacity: 0.55;
}

.puzzle-card-title {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 600;
}

.puzzle-card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.due-badge {
  display: inline-block;
  min-width: 84px;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
}

.due-badge.due-now {
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid var(--accent);
  color: var(--accent-soft);
}

.due-badge.due-later {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.puzzle-board-wrap {
  margin-top: 1.5rem;
  max-width: 480px;
}

.puzzle-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  /* vw alone overshoots here — .app-main's own 2rem side padding isn't
     part of the viewport width, so a plain vw fraction overflows this
     page's actual content column on narrow screens. */
  width: min(440px, calc(100vw - 4rem));
  height: min(440px, calc(100vw - 4rem));
  margin: 0 auto;
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.puzzle-feedback {
  font-size: 0.95rem;
  margin-top: 0.8rem;
}

.puzzle-feedback.correct {
  color: #4ade80;
}

.puzzle-feedback.correct.celebrate {
  font-size: 1.15rem;
  font-weight: 700;
  animation: puzzle-solved-pop 0.4s ease;
}

@keyframes puzzle-solved-pop {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }
  60% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

.puzzle-feedback.incorrect {
  color: #f87171;
}

.puzzle-board.shake {
  animation: puzzle-board-shake 0.35s ease;
}

@keyframes puzzle-board-shake {
  0%, 100% {
    transform: translateX(0);
  }
  20%, 60% {
    transform: translateX(-6px);
  }
  40%, 80% {
    transform: translateX(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .puzzle-feedback.correct.celebrate,
  .puzzle-board.shake {
    animation: none;
  }
}

.puzzle-rating-badge {
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--text-muted);
  margin-left: 0.6rem;
}

.puzzle-rating-badge strong {
  color: var(--accent-soft);
  font-weight: 700;
}

.puzzle-rating-delta {
  font-weight: 700;
  margin-left: 0.4rem;
}

.puzzle-rating-delta.up {
  color: #4ade80;
}

.puzzle-rating-delta.down {
  color: #f87171;
}

.puzzle-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.4rem;
}

.puzzle-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.puzzle-timer {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#puzzle-hint-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.puzzle-hint {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--accent-soft);
}
