/* ── Search + Filter ── */
.games-filter-section {
    background: var(--light-secondary);
    border-bottom: 1px solid var(--light-quaternary);
    padding: 28px 20px 20px;
}

.games-filter-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.games-search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.games-search-icon {
    position: absolute;
    left: 16px;
    color: var(--gray);
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 1;
}

.games-search-input {
    width: 100%;
    padding: 12px 42px 12px 40px;
    border: 2px solid var(--light-quaternary);
    border-radius: 12px;
    background: white;
    font-size: 0.95rem;
    color: var(--dark);
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.games-search-input::placeholder { color: var(--gray); }

.games-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.games-search-clear {
    position: absolute;
    right: 12px;
    width: 24px;
    height: 24px;
    border: none;
    background: var(--light-quaternary);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--gray);
    font-size: 0.7rem;
    transition: background 0.15s ease, color 0.15s ease;
}

.games-search-clear:hover { background: var(--gray); color: white; }

.games-filter-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1.5px solid var(--light-quaternary);
    border-radius: 20px;
    background: white;
    color: var(--gray-dark);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.filter-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-pill.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.filter-pill .pill-count {
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.75;
}

.games-no-results {
    text-align: center;
    color: var(--gray);
    padding: 40px 0;
    font-size: 0.95rem;
}

.games-no-results button {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    font-family: inherit;
    font-size: inherit;
}

/* ── Games Catalog ── */

main {
    background-color: var(--light);
}

.games-catalog {
    padding: 60px 20px 80px;
}

.games-catalog-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Game Card (horizontal) ── */
.gcard {
    position: relative;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    min-height: 96px;
}

.gcard:hover {
    transform: translateX(4px);
    border-color: rgba(37, 99, 235, 0.3);
    box-shadow:
        0 6px 28px rgba(37, 99, 235, 0.1),
        0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Left accent stripe */
.gcard-accent {
    width: 5px;
    align-self: stretch;
    flex-shrink: 0;
    border-radius: 0;
}

/* Icon area */
.gcard-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    margin: 0 0 0 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

/* Body — grid: [text info | play button] */
.gcard-body {
    flex: 1;
    padding: 14px 16px 14px 20px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    column-gap: 20px;
    align-items: center;
    min-width: 0;
}

/* Badges */
.gcard-badges {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.gbadge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 20px;
    line-height: 1;
}

.gbadge.difficulty-1 {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.gbadge.featured {
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.gbadge.new {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.gbadge.difficulty-2 {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.gbadge.difficulty-3 {
    background: rgba(239, 68, 68, 0.08);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.18);
}

.gbadge.difficulty-4 {
    background: rgba(3, 105, 161, 0.1);
    color: #0369a1;
    border: 1px solid rgba(3, 105, 161, 0.2);
}

/* Title & description */
.gcard-title {
    grid-column: 1;
    grid-row: 2;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--dark);
    margin: 0 0 3px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gcard-desc {
    grid-column: 1;
    grid-row: 3;
    font-size: 0.85rem;
    color: var(--gray);
    line-height: 1.5;
    margin: 0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

/* Footer — right side, spans all rows */
.gcard-footer {
    grid-column: 2;
    grid-row: 1 / span 3;
    align-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding-right: 4px;
}

.gcard-dots { display: none; }

/* Play button */
.gcard-play-btn {
    padding: 9px 18px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.28);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
}

.gcard:hover .gcard-play-btn {
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4);
    transform: scale(1.04);
}

/* Binary mini icon */
.binary-mini {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}

.b-dark, .b-light {
    width: 18px;
    height: 18px;
    border-radius: 50%;
}

.b-dark { background: #0f172a; }
.b-light { background: rgba(255,255,255,0.75); border: 2px solid rgba(255,255,255,0.5); }

/* ── "More coming" CTA ── */
.games-cta {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(6, 182, 212, 0.05));
    border-top: 1px solid rgba(37, 99, 235, 0.1);
    padding: 36px 24px;
}

.games-cta-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

.games-cta-icon {
    font-size: 2.2rem;
    color: var(--primary);
    opacity: 0.75;
    flex-shrink: 0;
}

.games-cta-inner h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--dark);
    margin: 0 0 4px;
}

.games-cta-inner p {
    font-size: 0.93rem;
    color: var(--gray);
    margin: 0;
}

.games-cta-inner a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.games-cta-inner a:hover { text-decoration: underline; }

/* ── Responsive ── */
/* ── Card entrance animation ──
   The delay is driven by --stagger, set from JS as
   (visible index × fixed step). This keeps the interval between
   cards uniform no matter which subset a filter shows — nth-child
   delays would leave gaps once cards in between are hidden. */
.gcard {
    animation: cardIn 0.4s cubic-bezier(0.2, 0, 0, 1) both;
    animation-delay: var(--stagger, 0s);
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .gcard { animation: none; }
}

@media (max-width: 640px) {
    .games-catalog { padding: 32px 16px 48px; }
    .gcard-icon { width: 46px; height: 46px; font-size: 1.25rem; margin-left: 14px; }
    .gcard-body { padding: 12px 12px 12px 14px; column-gap: 12px; }
    .gcard-title { font-size: 0.95rem; }
    .gcard-desc { display: none; }
    .gcard-play-btn { padding: 8px 14px; font-size: 0.78rem; }
}

/* ── Premium card hover polish (additive) ── */
.gcard-icon { transition: transform 0.25s ease, box-shadow 0.25s ease; }
.gcard-accent { transition: width 0.25s ease; }
.gcard:hover { transform: translate(4px, -3px); }
.gcard:hover .gcard-icon {
    transform: scale(1.08) rotate(-3deg);
    box-shadow: 0 9px 22px rgba(0, 0, 0, 0.24);
}
.gcard:hover .gcard-accent { width: 7px; }
.gcard:hover .gcard-play-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border-color: transparent;
}


/* ============================================================
   HOW-TO BUTTON on cards + GAME SETUP MODAL
   ============================================================ */

.gcard { cursor: pointer; }

/* Labeled "Rules" pill — stacked with Play Now in the card's right column */
.gcard-howto-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    padding: 8px 15px;
    border-radius: var(--r-pill);
    border: 1px solid var(--hairline-strong);
    background: var(--light);
    color: var(--ink-soft);
    font-size: 0.78rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.gcard-howto-btn i {
    font-size: 0.75rem;
    color: var(--primary);
    transition: color 0.2s ease;
}

.gcard-howto-btn:hover {
    background: rgba(37, 99, 235, 0.07);
    border-color: rgba(37, 99, 235, 0.35);
    color: var(--primary);
    transform: translateY(-1px);
}

/* ── Modal overlay ── */
.gsetup-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 15, 30, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.gsetup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.gsetup {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    background: var(--light);
    border: 1px solid var(--hairline);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    padding: 30px 30px 26px;
    transform: translateY(14px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.gsetup-overlay.active .gsetup { transform: translateY(0) scale(1); }

.gsetup-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--hairline);
    background: var(--light-secondary);
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

/* Same spin-to-red as the Rules and "How to Play" close buttons. */
.gsetup-close:hover {
    background: var(--accent-red, #ef4444);
    border-color: var(--accent-red, #ef4444);
    color: #fff;
    transform: rotate(90deg);
}

.gsetup-head {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding-right: 30px;
}

.gsetup-icon {
    width: 58px;
    height: 58px;
    flex-shrink: 0;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
    background: var(--gradient-primary);
    box-shadow: var(--shadow-md);
}

.gsetup-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.gsetup-desc {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gsetup-section { margin-bottom: 20px; }

.gsetup-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
    margin-bottom: 10px;
}

.gsetup-random {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--r-pill);
    border: 1px solid var(--hairline-strong);
    background: var(--light);
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.gsetup-random:hover { background: var(--dark); border-color: var(--dark); color: #fff; }

.gsetup-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.gsetup-pill {
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid var(--hairline-strong);
    background: var(--light-secondary);
    color: var(--ink-soft);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.gsetup-pill:hover { border-color: var(--primary); color: var(--primary); }

.gsetup-pill.selected {
    background: var(--dark);
    border-color: var(--dark);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.gsetup-numbers {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
}

.gsetup-num {
    aspect-ratio: 1;
    border-radius: 10px;
    border: 1px solid var(--hairline-strong);
    background: var(--light-secondary);
    color: var(--ink-soft);
    font-size: 0.85rem;
    font-weight: 700;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.gsetup-num:hover { border-color: var(--primary); color: var(--primary); }

.gsetup-num.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Already solved by the signed-in user: green tint + corner checkmark.
   Still clickable — it only marks progress, it never locks a puzzle. */
.gsetup-num.done {
    position: relative;
    border-color: rgba(16, 185, 129, 0.55);
    background: rgba(16, 185, 129, 0.10);
    color: #059669;
}

.gsetup-num.done::after {
    content: "✓";
    position: absolute;
    top: -6px;
    right: -6px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #10b981;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
    font-family: inherit;
}

.gsetup-num.done.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Finished with the "Solution" button rather than solved by the player:
   amber tint + corner eye. Same rules as .done otherwise. */
.gsetup-num.revealed {
    position: relative;
    border-color: rgba(245, 158, 11, 0.55);
    background: rgba(245, 158, 11, 0.10);
    color: #b45309;
}

.gsetup-num.revealed::after {
    content: "\f06e";   /* fa-eye */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: -6px;
    right: -6px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #f59e0b;
    color: #fff;
    font-size: 8px;
    line-height: 15px;
    text-align: center;
}

.gsetup-num.revealed.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.gsetup-head-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

/* "How to play" — a friendly chip right under the game description */
.gsetup-howto {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 16px;
    border-radius: var(--r-pill);
    border: 1px solid rgba(37, 99, 235, 0.25);
    background: rgba(37, 99, 235, 0.07);
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.gsetup-howto i { font-size: 0.8rem; }

.gsetup-howto:hover {
    background: rgba(37, 99, 235, 0.13);
    border-color: rgba(37, 99, 235, 0.45);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.16);
}

.gsetup-actions {
    display: flex;
    margin-top: 26px;
}

.gsetup-play {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 14px 18px;
    border-radius: var(--r-pill);
    border: none;
    background: var(--grad-brand);
    color: #fff;
    font-size: 0.98rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow-brand);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease;
}

.gsetup-play:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(37, 99, 235, 0.36); }
.gsetup-play i { font-size: 0.8rem; }

@media (max-width: 520px) {
    .gsetup { padding: 24px 20px 20px; }
    .gsetup-numbers { grid-template-columns: repeat(5, 1fr); }
    .gcard-howto-btn { padding: 8px 12px; font-size: 0.72rem; margin-right: 6px; }
}

/* ============================================================
   RULES MODAL — in-place "How to Play", layered above the setup
   window so closing it returns to where the player was.
   ============================================================ */

.grules-overlay {
    position: fixed;
    inset: 0;
    z-index: 3200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 15, 30, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.grules-overlay.active {
    opacity: 1;
    visibility: visible;
}

.grules {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    display: flex;
    flex-direction: column;
    background: var(--light);
    border: 1px solid var(--hairline);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    padding: 26px 28px 24px;
    transform: translateY(14px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.grules-overlay.active .grules { transform: translateY(0) scale(1); }

.grules-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--hairline);
    background: var(--light-secondary);
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

/* Same playful spin-to-red as the in-game "How to Play" close button. */
.grules-close:hover {
    background: var(--accent-red, #ef4444);
    border-color: var(--accent-red, #ef4444);
    color: #fff;
    transform: rotate(90deg);
}

.grules-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-right: 36px;
}

.grules-badge {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(37, 99, 235, 0.22);
}

.grules-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.grules-body {
    overflow-y: auto;
    padding-right: 6px;
}

.grules-body h3 {
    display: none;   /* the modal header already says "rules" */
}

.grules-body ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.grules-body li {
    position: relative;
    padding: 12px 16px 12px 40px;
    background: var(--light-secondary);
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--ink-soft);
}

.grules-body li::before {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    left: 15px;
    top: 13px;
    font-size: 0.72rem;
    color: var(--accent-green);
}

.grules-body li strong { color: var(--ink); }

.grules-body p {
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--ink-soft);
    margin-bottom: 10px;
}

.grules-loading {
    text-align: center;
    color: var(--muted) !important;
    padding: 22px 0;
}

.grules-loading i { margin-right: 8px; color: var(--primary); }

@media (max-width: 520px) {
    .grules { padding: 22px 18px 18px; }
}