/* ═══════════════════════════════════════════════════════════════════
   PUZZLES LISTING PAGE
   ═══════════════════════════════════════════════════════════════════ */

/* ── Page shell ──────────────────────────────────────────────────── */
.puzzle-shell {
    width: min(calc(100% - 32px), var(--max-width));
    margin: 0 auto;
    padding: 20px 0 40px;
}

/* ── Intro section spacing ───────────────────────────────────────── */
.puzzle-intro {
    margin-bottom: 24px;
}

/* ── Heading indent (breathing room from panel left border) ──────── */
.puzzles-page-heading {
    padding-left: 24px;
}

/* ── List section ────────────────────────────────────────────────── */
.puzzle-list-section {
    display: grid;
    gap: 20px;
}

/* ── Daily slot — centered card, constrained width ───────────────── */
.daily-slot {
    display: flex;
    justify-content: center;
}

.daily-slot .puzzle-card.is-daily {
    max-width: 620px;
    width: 100%;
}

/* ── Stats panel shared styles (wld-row, lb-preview) ────────────── */
/* These match chess/styles.css — duplicated here because puzzles pages
   do not load a game-specific stylesheet.                            */
.stats-section-title {
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .08em; color: var(--muted); margin: 14px 0 8px;
}
.wld-row { display: flex; gap: 8px; margin-bottom: 4px; }
.wld-cell {
    flex: 1; background: rgba(255,255,255,.04); border: 1px solid var(--line);
    border-radius: 10px; padding: 8px 6px; text-align: center;
    display: flex; flex-direction: column; gap: 2px;
}
.wld-cell .wld-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.wld-cell .wld-value { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.wld-cell.wld-win  .wld-value { color: #4ade80; }
.wld-cell.wld-loss .wld-value { color: #f87171; }
.wld-cell.wld-draw .wld-value { color: var(--accent-2); }
.stats-signin-note { font-size: .82rem; color: var(--muted); padding: 8px 0; margin: 0; }
.lb-preview-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .82rem;
}
.lb-preview-row:last-child { border-bottom: none; }
.lb-rank { font-weight: 700; width: 20px; color: var(--muted); flex-shrink: 0; }
.lb-rank.gold   { color: #f59e0b; }
.lb-rank.silver { color: #94a3b8; }
.lb-rank.bronze { color: #b45309; }
.lb-name  { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-size: .75rem; color: var(--muted); }
.lb-preview-more  { display: block; text-align: right; font-size: .78rem; color: var(--accent-2); margin-top: 8px; text-decoration: none; }
.lb-preview-more:hover { text-decoration: underline; }
.lb-preview-empty { font-size: .82rem; color: var(--muted); padding: 8px 0; margin: 0; }

/* ── Statistics panel — rules bullet list ────────────────────────── */
.stats-rules-list {
    margin: 0;
    padding: 0 0 0 18px;
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: .84rem;
    line-height: 1.55;
}

/* ── Filter bar ──────────────────────────────────────────────────── */
.puzzle-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-toggle-btn {
    display: flex;
    align-items: center;
    gap: 7px;
}

/* highlight the toggle button itself when any filter is active */
.filter-toggle-btn.is-active {
    border-color: rgba(63,198,202,.5);
    background: rgba(63,198,202,.1);
    color: var(--accent-2);
}

/* teal badge showing count of active filters */
.filter-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 20px;
    background: var(--accent-2);
    color: #04101a;
    font-size: .63rem;
    font-weight: 700;
    line-height: 1;
}

/* ── Expandable filter panel ─────────────────────────────────────── */
.filter-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 28px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.03);
}

.filter-panel[hidden] { display: none !important; }

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-group-label {
    font-size: .67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    white-space: nowrap;
    min-width: 52px;
    flex-shrink: 0;
}

.filter-group-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.filter-group-buttons .ghost-button {
    font-size: .75rem;
    padding: 3px 10px;
}

/* selected filter option — teal highlight */
.filter-group-buttons .ghost-button.is-active {
    border-color: rgba(63,198,202,.5);
    background: rgba(63,198,202,.14);
    color: var(--accent-2);
}

/* "Clear all" sits at the far right of the panel row */
.filter-clear-btn {
    margin-left: auto;
    font-size: .72rem;
    padding: 3px 12px;
    color: var(--muted);
    border-color: rgba(255,255,255,.12);
}

.filter-clear-btn:hover {
    border-color: rgba(227,79,95,.5);
    color: #ff9ba6;
    background: rgba(227,79,95,.08);
    transform: none;
}

/* ── Empty / loading state ───────────────────────────────────────── */
.puzzle-empty {
    color: var(--muted);
    padding: 32px 0;
    text-align: center;
}

/* ── Puzzle grid ─────────────────────────────────────────────────── */
.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
    gap: 14px;
}

/* ── Puzzle card (link) ──────────────────────────────────────────── */
.puzzle-card {
    display: grid;
    grid-template-columns: auto 1fr;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.04);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: border-color .18s, background .18s;
}

.puzzle-card:hover {
    border-color: rgba(63,198,202,.5);
    background: rgba(63,198,202,.05);
}

.puzzle-card.is-daily {
    border-color: rgba(63,198,202,.28);
    background: rgba(63,198,202,.06);
}

.puzzle-card.is-daily:hover {
    border-color: rgba(63,198,202,.6);
    background: rgba(63,198,202,.1);
}

/* ── Card preview column ─────────────────────────────────────────── */
.puzzle-preview {
    padding: 14px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.14);
}

/* ── Mini chess board ────────────────────────────────────────────── */
.mini-chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 108px;
    height: 108px;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.1);
    flex-shrink: 0;
}

.puzzle-card.is-daily .mini-chess-board {
    width: 140px;
    height: 140px;
}

.mini-chess-cell {
    display: flex;
    align-items: center;
    justify-content: center;
}

.mini-chess-cell.light { background: #f0d9b5; }
.mini-chess-cell.dark  { background: #8f6a4e; }

.mini-chess-cell img {
    width: 88%;
    height: 88%;
    object-fit: contain;
    pointer-events: none;
}

/* ── Mini Connect 4 board ────────────────────────────────────────── */
.mini-connect4-board {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    width: 108px;
    height: 93px;
    border-radius: 8px;
    overflow: hidden;
    background: #1a4fd6;
    padding: 4px;
    gap: 3px;
    border: 1px solid rgba(255,255,255,.12);
    flex-shrink: 0;
}

.puzzle-card.is-daily .mini-connect4-board {
    width: 140px;
    height: 120px;
}

.mini-c4-cell {
    border-radius: 50%;
    background: rgba(2,14,48,.96);
}

.mini-c4-cell.red    { background: #e62e24; }
.mini-c4-cell.yellow { background: #ffb703; }

/* ── Card copy column ────────────────────────────────────────────── */
.puzzle-card-copy {
    padding: 14px 16px;
    display: grid;
    gap: 4px;
    align-content: start;
}

.puzzle-card-copy .eyebrow {
    font-size: .7rem;
}

.puzzle-card-copy h2,
.puzzle-card-copy h3 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.3;
}

.puzzle-card.is-daily .puzzle-card-copy h2 {
    font-size: 1.15rem;
}

.puzzle-card-copy p {
    margin: 0;
    color: var(--muted);
    font-size: .83rem;
    line-height: 1.5;
}

/* ── Meta chip row ───────────────────────────────────────────────── */
.puzzle-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
}

.puzzle-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 20px;
    border: 1px solid var(--line);
    font-size: .71rem;
    color: var(--muted);
    white-space: nowrap;
}

/* "Registered users" chip — always teal regardless of sibling order */
.puzzle-chip-locked {
    border-color: rgba(63,198,202,.45);
    color: var(--accent-2);
}

.puzzle-chip-solved {
    border-color: rgba(74,222,128,.4);
    color: #4ade80;
}

/* ── Responsive (listing) ────────────────────────────────────────── */
@media (max-width: 640px) {
    .puzzle-grid {
        grid-template-columns: 1fr;
    }
    .mini-chess-board {
        width: 88px;
        height: 88px;
    }
    .mini-connect4-board {
        width: 88px;
        height: 76px;
    }
    .puzzle-card.is-daily .mini-chess-board {
        width: 108px;
        height: 108px;
    }
    .puzzle-card.is-daily .mini-connect4-board {
        width: 108px;
        height: 93px;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   PUZZLE EDITOR PAGE  (shared stylesheet)
   ═══════════════════════════════════════════════════════════════════ */

.puzzle-admin-shell {
    min-height: 100vh;
    width: min(calc(100% - 32px), var(--max-width));
    margin: 0 auto;
    padding: 20px 0 40px;
}

.puzzle-editor-layout {
    width: 100%;
    margin: 0 auto 56px;
}

.puzzle-editor-board {
    padding: 28px;
}

.editor-heading {
    text-align: left;
    margin-bottom: 22px;
}

.editor-toolbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
    margin: 22px 0;
}

.position-grid {
    display: grid;
    grid-template-columns: minmax(320px, 560px) minmax(280px, 1fr);
    gap: 24px;
    align-items: start;
}

.editor-board-panel {
    display: grid;
    gap: 16px;
}

.editor-board-panel[hidden],
.chess-only[hidden],
.connect4-only[hidden] {
    display: none !important;
}

.editor-chess-board {
    width: 100%;
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    overflow: hidden;
    border-radius: 18px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.editor-square {
    border: 0;
    padding: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
    min-width: 0;
}

.editor-square.light {
    background: #f0d9b5;
}

.editor-square.dark {
    background: #8f6a4e;
}

.editor-square img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    pointer-events: none;
}

.piece-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.palette-item {
    min-width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.06);
    color: inherit;
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 4px 8px;
}

.palette-item.is-selected {
    border-color: rgba(63,198,202,.7);
    background: rgba(63,198,202,.14);
}

.palette-item img {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.editor-config {
    display: grid;
    gap: 16px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255,255,255,.04);
}

.editor-config textarea,
.editor-config input,
.editor-config select,
.editor-toolbar input,
.editor-toolbar select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(4, 10, 20, .45);
    color: inherit;
    padding: 11px 12px;
}

.editor-inline-actions,
.editor-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.castle-box {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    display: grid;
    gap: 8px;
}

.castle-box legend {
    padding: 0 6px;
    color: var(--muted);
}

.castle-box label {
    display: flex;
    gap: 8px;
    color: var(--muted);
}

.puzzle-status {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--muted);
    background: rgba(255,255,255,.04);
}

.puzzle-status.is-success {
    border-color: rgba(63,198,202,.4);
    color: #9df1f2;
}

.puzzle-status.is-warning {
    border-color: rgba(241,201,74,.35);
    color: #f1d777;
}

.puzzle-status.is-error {
    border-color: rgba(227,79,95,.45);
    color: #ff9ba6;
}

.editor-connect4-stage {
    width: 100%;
}

/* Connect 4 board in the editor — exact game styles from connect4/styles.css */
.editor-connect4-board {
    position: relative;
    width: 100%;
    aspect-ratio: 7 / 6;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(6, minmax(0, 1fr));
    gap: 10px;
    padding: 18px;
    border-radius: 28px;
    background: linear-gradient(180deg, #2167ff 0%, #0e42b5 100%);
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 30px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    cursor: pointer;
}

.editor-connect4-board::before {
    content: "";
    position: absolute;
    inset: 10px;
    border-radius: 22px;
    border: 1px solid rgba(255,255,255,0.08);
    pointer-events: none;
}

.editor-connect4-board .connect4-cell {
    position: relative;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(3, 17, 57, 0.94) 0%, rgba(2, 14, 48, 0.97) 65%, rgba(1, 8, 24, 1) 100%);
    box-shadow: inset 0 8px 18px rgba(0, 0, 0, 0.35), inset 0 -4px 12px rgba(255,255,255,0.06);
    overflow: hidden;
    cursor: pointer;
}

.editor-connect4-board .connect4-piece {
    position: absolute;
    inset: 7%;
    border-radius: 50%;
    opacity: 1;
    transform: none;
}

.editor-connect4-board .connect4-piece.is-red {
    background: radial-gradient(circle at 32% 28%, #ffb3ad 0%, #ff655a 28%, #e62e24 60%, #8d0808 100%);
}

.editor-connect4-board .connect4-piece.is-yellow {
    background: radial-gradient(circle at 32% 28%, #fff7a3 0%, #ffe367 28%, #ffb703 60%, #b36a00 100%);
}

.maintenance-panel {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.maintenance-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr);
    gap: 18px;
}

.maintenance-card {
    display: grid;
    gap: 14px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255,255,255,.04);
}

.maintenance-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.maintenance-card h3,
.maintenance-card p {
    margin: 0;
}

.maintenance-card p,
.admin-empty {
    color: var(--muted);
    line-height: 1.6;
}

.admin-puzzle-list {
    display: grid;
    gap: 8px;
    max-height: 280px;
    overflow: auto;
    padding-right: 4px;
}

.admin-puzzle-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255,255,255,.035);
}

.admin-puzzle-row strong {
    display: block;
}

.admin-puzzle-row span {
    display: block;
    color: var(--muted);
    font-size: .84rem;
    line-height: 1.5;
}

.danger-button {
    border-color: rgba(227,79,95,.45);
    color: #ffb3bc;
}

.danger-primary,
.danger-zone .primary-button {
    background: linear-gradient(135deg, #b91c1c, #e34f5f);
    box-shadow: 0 14px 28px rgba(227,79,95,.22);
}

.connect4-mini-disc {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.connect4-mini-disc.red {
    background: #e34f5f;
}

.connect4-mini-disc.yellow {
    background: #f1c94a;
}

@media (max-width: 900px) {
    .puzzle-admin-shell {
        width: min(calc(100% - 24px), var(--max-width));
        padding: 16px 0 32px;
    }

    .editor-toolbar,
    .position-grid,
    .maintenance-grid {
        grid-template-columns: 1fr;
    }

    .maintenance-card-header {
        display: grid;
    }
}
