/* ==========================================================================
   Pages CSS — Puzzle, Dashboard, Blog, Profile, Auth, Leaderboard styles
   ========================================================================== */

/* ---------- Section ---------- */
.section__header {
    margin-bottom: var(--space-6);
}

.section__header h1,
.section__header h2 {
    margin-bottom: 0;
}

.section__header p {
    margin-top: var(--space-2);
    margin-bottom: 0;
}

/* ---------- Prose (long-form content) ---------- */
.prose {
    max-width: 65ch;
    color: var(--color-text);
    line-height: var(--leading-relaxed);
}

.prose h1,
.prose h2,
.prose h3 {
    margin-top: var(--space-8);
    margin-bottom: var(--space-3);
}

.prose h1:first-child,
.prose h2:first-child,
.prose h3:first-child {
    margin-top: 0;
}

.prose p,
.prose ul,
.prose ol {
    margin-bottom: var(--space-4);
}

.prose ul,
.prose ol {
    padding-left: var(--space-5);
}

.prose li {
    margin-bottom: var(--space-2);
}

.prose li:last-child {
    margin-bottom: 0;
}

.prose a {
    color: var(--color-primary-500);
    text-decoration: underline;
    text-decoration-color: var(--color-primary-200);
    text-underline-offset: 2px;
}

.prose a:hover {
    text-decoration-color: currentColor;
}

/* ---------- Table ---------- */
.card__body--no-padding {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table th,
.table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
    white-space: nowrap;
}

.table th {
    background: var(--color-surface-alt);
    color: var(--color-text-secondary);
    font-weight: var(--weight-semibold);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
}

.table tbody tr {
    transition: background var(--duration-fast) var(--ease-out);
}

.table tbody tr:hover {
    background: var(--color-surface-alt);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table--striped tbody tr:nth-child(even) {
    background: var(--color-surface-alt);
}

.table--striped tbody tr:nth-child(even):hover {
    background: var(--color-border-light);
}

/* ---------- Auth Section ---------- */
.auth-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: var(--space-8) 0;
}

/* ---------- Filter Bar ---------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: flex-end;
}
.filter-bar__group { flex: 1 1 180px; min-width: 140px; }
.filter-bar__group--actions { flex: 0 0 auto; display: flex; gap: var(--space-2); }
.filter-bar__range { display: flex; align-items: center; gap: var(--space-2); }

/* ---------- Puzzle Grid ---------- */
.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}
.puzzle-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
}
.puzzle-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}
.puzzle-card__board {
    aspect-ratio: 1;
    background: var(--color-surface-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--color-text-secondary);
    pointer-events: none; /* the whole card is a link; squares shouldn't intercept clicks */
}
/* Fallback placeholder for before JS renders the real preview (see
   chess-engine.js renderPreviewBoards) — hidden once .chess-board is added. */
.puzzle-card__board:not(.chess-board)::after { content: '♟'; }
.puzzle-card__board.chess-board--preview .square {
    cursor: inherit;
}
.puzzle-card__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
}
.puzzle-card__rating { font-weight: 700; font-size: var(--text-lg); }
.puzzle-card__meta {
    display: flex;
    justify-content: space-between;
    padding: 0 var(--space-4) var(--space-3);
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
}

/* ---------- Puzzle Solve Layout ----------
 * The board column is sized to the board itself rather than "whatever is
 * left", so the board never stretches to fill a wide viewport and the pair
 * stays centred as a unit. Both solving pages resolve to the same board size
 * because both defer to --board-size.
 */
.puzzle-layout {
    display: grid;
    grid-template-columns: minmax(0, var(--board-size)) minmax(17rem, 21rem);
    gap: var(--space-6);
    align-items: start;
    justify-content: center;
}
.puzzle-layout--centered {
    grid-template-columns: minmax(0, var(--board-size));
    justify-content: center;
}
.chess-board {
    width: 100%;
    max-width: var(--board-size);
    margin-inline: auto;
    aspect-ratio: 1;
    background: var(--color-surface-alt);
    border-radius: var(--radius-lg);
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--color-text-secondary);
    position: relative;
}
/* Kept for the markup that still carries it — the shared cap already applies. */
.chess-board--large { max-width: var(--board-size); }
.board-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    margin-top: var(--space-3);
}
.puzzle-info__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border-light);
}
.puzzle-info__row:last-child { border-bottom: none; }
.puzzle-info__label { color: var(--color-text-secondary); font-size: var(--text-sm); }
.puzzle-info__value { font-weight: 600; }
.feedback-icon { font-size: 3rem; }
.move-list { font-family: var(--font-mono); font-size: var(--text-sm); }

/* ---------- Theme Grid ---------- */
.theme-group__title {
    font-size: var(--text-lg);
    margin: var(--space-8) 0 var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    letter-spacing: 0.02em;
}
.theme-group__title:first-of-type { margin-top: 0; }
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-4);
}
.theme-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    text-align: center;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.theme-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-primary-500);
}
.theme-card__icon { font-size: 2.5rem; margin-bottom: var(--space-2); }
.theme-card__name { font-weight: 700; margin-bottom: var(--space-1); }
.theme-card__desc { font-size: var(--text-sm); color: var(--color-text-secondary); margin-bottom: var(--space-2); }
.theme-card__count { font-size: var(--text-xs); color: var(--color-text-tertiary); }

/* ---------- Stats Grid ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-4);
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-align: center;
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card__icon { font-size: 1.5rem; margin-bottom: var(--space-1); }
.stat-card__value { font-size: var(--text-2xl); font-weight: 800; color: var(--color-primary-500); }
.stat-card__label { font-size: var(--text-xs); color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-top: var(--space-1); }

/* ---------- Dashboard Grid ---------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-6);
}

/* ---------- Rating Chart (see js/rating-chart.js) ---------- */
#rating-chart {
    display: block;
    width: 100%;
}
.chart-tooltip {
    position: absolute;
    transform: translate(-50%, -140%);
    padding: var(--space-1) var(--space-2);
    background: var(--color-text);
    color: var(--color-text-inverse);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    white-space: nowrap;
    pointer-events: none;
}
.chart-tooltip[hidden] { display: none; }

/* ---------- Quick Actions ---------- */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}
.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    background: var(--color-surface-alt);
    text-decoration: none;
    color: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background 0.2s, transform 0.1s;
}
.quick-action:hover { background: var(--color-border-light); transform: scale(1.02); }
.quick-action__icon { font-size: 1.5rem; }

/* ---------- Profile Header ---------- */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    padding: var(--space-6) 0;
}
.avatar { border-radius: 50%; object-fit: cover; }
.avatar--xl { width: 96px; height: 96px; font-size: 2rem; }
.avatar--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary-500);
    color: #fff;
    font-weight: 700;
}
.profile-header__stats { display: flex; gap: var(--space-4); margin-top: var(--space-2); }
.stat-inline { font-size: var(--text-sm); color: var(--color-text-secondary); }

/* ---------- Achievement ---------- */
.achievement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-3);
}
.achievement-badge {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}
.achievement-badge--unlocked { background: var(--color-surface); }
.achievement-badge--locked { background: var(--color-surface-alt); opacity: 0.6; }
.achievement-badge__icon { font-size: 2rem; flex-shrink: 0; }
.achievement-badge__info { flex: 1; }
.achievement-list { display: flex; flex-wrap: wrap; gap: var(--space-3); }

/* ---------- Progress Bar ---------- */
.progress { background: var(--color-border-light); border-radius: 9999px; overflow: hidden; height: 8px; }
.progress--sm { height: 6px; }
.progress__bar { height: 100%; background: var(--color-primary-500); border-radius: 9999px; transition: width 0.3s; }

/* ---------- Blog Layout ---------- */
.blog-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: var(--space-6);
}
.blog-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-4);
    transition: box-shadow 0.2s;
}
.blog-card:hover { box-shadow: var(--shadow-md); }
.blog-card__image img { width: 100%; height: 200px; object-fit: cover; }
.blog-card__body { padding: var(--space-5); }
.blog-card__meta { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.blog-card__title { font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--space-2); }
.blog-card__title a { text-decoration: none; color: inherit; }
.blog-card__title a:hover { color: var(--color-primary-500); }
.blog-card__excerpt { color: var(--color-text-secondary); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.blog-card__footer { display: flex; justify-content: space-between; align-items: center; }
.blog-post__header { margin-bottom: var(--space-6); }
.blog-post__title { font-size: var(--text-3xl); font-weight: 800; margin-top: var(--space-2); }
.blog-post__meta { color: var(--color-text-secondary); font-size: var(--text-sm); margin-top: var(--space-2); display: flex; gap: var(--space-2); }
.blog-post__image { margin-bottom: var(--space-6); border-radius: var(--radius-lg); overflow: hidden; }
.blog-post__image img { width: 100%; }
.blog-post__content.prose { line-height: 1.8; font-size: var(--text-base); }
.sidebar-list { list-style: none; padding: 0; }
.sidebar-list li { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border-light); }
.sidebar-list li:last-child { border-bottom: none; }

/* ---------- Leaderboard ---------- */
.leaderboard-row--top td { font-weight: 600; }

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-full);
    font-size: 1.1rem;
}

.rank-badge--gold   { background: hsl(45, 90%, 88%); box-shadow: inset 0 0 0 1px hsl(45, 70%, 65%); }
.rank-badge--silver { background: hsl(220, 12%, 90%); box-shadow: inset 0 0 0 1px hsl(220, 10%, 70%); }
.rank-badge--bronze { background: hsl(25, 55%, 88%); box-shadow: inset 0 0 0 1px hsl(25, 45%, 65%); }

[data-theme="dark"] .rank-badge--gold   { background: hsla(45, 90%, 55%, 0.18); box-shadow: inset 0 0 0 1px hsla(45, 70%, 55%, 0.4); }
[data-theme="dark"] .rank-badge--silver { background: hsla(220, 12%, 80%, 0.14); box-shadow: inset 0 0 0 1px hsla(220, 10%, 70%, 0.3); }
[data-theme="dark"] .rank-badge--bronze { background: hsla(25, 55%, 55%, 0.18); box-shadow: inset 0 0 0 1px hsla(25, 45%, 55%, 0.35); }

/* ---------- Tags ---------- */
.tag-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tag {
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    background: var(--color-surface-alt);
    border-radius: 9999px;
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: background 0.2s;
}
.tag:hover { background: var(--color-border-light); }
.tag--sm { padding: 2px var(--space-2); font-size: 0.7rem; }

/* ---------- Empty State ---------- */
.empty-state { text-align: center; padding: var(--space-12) 0; }
.empty-state__icon { font-size: 4rem; margin-bottom: var(--space-3); }
.empty-state__title { font-size: var(--text-xl); font-weight: 700; }
.empty-state__text { color: var(--color-text-secondary); margin-top: var(--space-2); }

/* ---------- Responsive ---------- */

/* The board and its sidebar need ~950px to sit side by side without either
   being squeezed, so they stack well before the general mobile breakpoint.
   Stacked, the board keeps the same height cap and simply centres. */
@media (max-width: 1023px) {
    .puzzle-layout,
    .puzzle-layout--centered {
        grid-template-columns: minmax(0, 1fr);
        max-width: var(--board-size);
        margin-inline: auto;
    }
    .puzzle-layout__sidebar { order: 2; }
}

@media (max-width: 768px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .blog-layout { grid-template-columns: 1fr; }
    .blog-layout__sidebar { order: 2; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .profile-header { flex-direction: column; text-align: center; }
    .profile-header__stats { justify-content: center; }
    .filter-bar { flex-direction: column; }
}
