/* =========================================================
   3x3 GRID PATH BUILDER GAME STYLES
   Exact layout & theme matching the reference design
   ========================================================= */

.gpb-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    animation: fadeInUp 0.5s ease-out;
}

.gpb-header {
    text-align: center;
    width: 100%;
    margin-bottom: 1.25rem;
}

.gpb-header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-main, #0f172a);
    letter-spacing: -0.02em;
}

body.theme-dark .gpb-header h1,
.dark-theme .gpb-header h1 {
    color: #f8fafc;
}

.gpb-header .subtitle {
    color: var(--text-muted, #475569);
    font-size: 0.95rem;
    max-width: 680px;
    margin: 0 auto;
    line-height: 1.55;
}

/* Level Selection Tabs */
.gpb-level-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    width: 100%;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.gpb-lvl-btn {
    background: #ffffff;
    color: #000000;
    border: 2px solid #000000;
    border-radius: 4px;
    padding: 0.55rem 1.1rem;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1 1 auto;
    max-width: 150px;
    text-align: center;
}

.gpb-lvl-btn:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
}

.gpb-lvl-btn.active {
    background: #000000;
    color: #ffffff;
    border-color: #000000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Status / Stats Bar */
.gpb-status-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--glass-bg, rgba(255, 255, 255, 0.9));
    border: 1px solid var(--glass-border, #cbd5e1);
    border-radius: 10px;
    padding: 0.65rem 1.25rem;
    margin-bottom: 1.25rem;
    backdrop-filter: blur(8px);
}

.gpb-status-group {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.gpb-stat-item {
    font-size: 0.92rem;
    color: var(--text-muted, #64748b);
}

.gpb-stat-item strong {
    color: var(--text-main, #0f172a);
    font-size: 1.05rem;
    margin-left: 0.25rem;
}

.gpb-badge-block {
    background: #fef3c7;
    color: #b45309;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    border: 1px solid #fde68a;
    font-size: 0.85rem;
    font-weight: 700;
}

/* Board Outer Area (Fixed Row Alignment) */
.gpb-board-area {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

/* Fixed stationary markers aligned with row */
.gpb-marker {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    user-select: none;
    transform: translateY(-50%);
    transition: top 0.25s ease;
    z-index: 5;
}

.gpb-marker.start {
    left: -58px;
}

.gpb-marker.end {
    right: -58px;
}

.gpb-marker-label {
    display: none; /* hidden to match clean screenshot look */
}

/* Board Card */
.gpb-board-card {
    background: #ffffff;
    border: 4px solid #000000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    position: relative;
    display: inline-block;
    padding: 0;
}

/* Grids */
.gpb-grid {
    display: grid;
    background: #000000;
    gap: 1px;
    user-select: none;
}

.gpb-grid-6x6 {
    grid-template-columns: repeat(6, 48px);
    grid-template-rows: repeat(6, 48px);
}

.gpb-grid-9x9 {
    grid-template-columns: repeat(9, 36px);
    grid-template-rows: repeat(9, 36px);
}

/* Cells */
.gpb-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    transition: transform 0.1s ease, filter 0.15s ease;
}

/* 1. White Inactive Cell */
.gpb-cell.cell-white {
    background: #ffffff;
    color: #000000;
    border: 1px solid #94a3b8;
}

/* 2. Black Active Path Cell */
.gpb-cell.cell-black {
    background: #000000;
    color: #ffffff;
    border: 1px solid #1e293b;
}

/* Arrow inside cell */
.gpb-arrow {
    display: inline-block;
    font-size: 1.55rem;
    font-weight: 800;
    color: #ffffff;
    line-height: 1;
    user-select: none;
}

.gpb-grid-9x9 .gpb-arrow {
    font-size: 1.2rem;
}

/* Track Dot (•) */
.gpb-dot {
    display: inline-block;
    font-size: 1.8rem;
    color: #ffffff;
    line-height: 1;
    user-select: none;
}

.gpb-grid-9x9 .gpb-dot {
    font-size: 1.4rem;
}

/* 3x3 Subgrid Outer Dividers */
.gpb-cell[data-col="3"],
.gpb-cell[data-col="6"] {
    border-left: 2px solid #000000;
}

.gpb-cell[data-row="3"],
.gpb-cell[data-row="6"] {
    border-top: 2px solid #000000;
}

/* SELECTED 3x3 BLOCK - Red Outline (Exact match to reference screenshots) */
.gpb-cell.block-selected {
    box-shadow: inset 0 0 0 2px #ef4444 !important;
    border-color: #ef4444 !important;
    z-index: 2;
}

.gpb-cell:hover {
    filter: brightness(1.1);
}

/* Block Info Line Below Grid (Exact match: Block (1, 1) · Rotated: 0° · Layout: 1/6) */
.gpb-block-info {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main, #0f172a);
    text-align: center;
    margin-bottom: 1.25rem;
    letter-spacing: 0.02em;
}

/* Path validation animation states */
.gpb-cell.path-flow-valid {
    background: #16a34a !important;
    border-color: #22c55e !important;
    box-shadow: inset 0 0 0 2px #4ade80 !important;
    animation: flowPulse 0.35s ease-out;
}

.gpb-cell.path-flow-valid .gpb-arrow,
.gpb-cell.path-flow-valid .gpb-dot {
    color: #ffffff !important;
    filter: drop-shadow(0 0 8px #86efac);
}

.gpb-cell.path-flow-break {
    background: #dc2626 !important;
    border-color: #f87171 !important;
    animation: shakeError 0.5s ease-in-out;
}

.gpb-cell.path-flow-break .gpb-arrow,
.gpb-cell.path-flow-break .gpb-dot {
    color: #ffffff !important;
    filter: drop-shadow(0 0 8px #fca5a5);
}

/* Action Controls Row */
.gpb-actions-row {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.gpb-btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.7rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1 1 140px;
}

.gpb-btn-action:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-rotate {
    background: #0284c7;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

.btn-rotate:hover:not(:disabled) {
    background: #0369a1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.btn-change-layout {
    background: #f59e0b;
    color: #000000;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-change-layout:hover:not(:disabled) {
    background: #d97706;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.btn-validate {
    background: #16a34a;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
}

.btn-validate:hover:not(:disabled) {
    background: #15803d;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.4);
}

.btn-reset {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.btn-reset:hover {
    background: #e2e8f0;
    transform: translateY(-2px);
}

/* Rules / Instructions Card */
.gpb-rules-card {
    background: var(--glass-bg, rgba(255, 255, 255, 0.9));
    border: 1px solid var(--glass-border, #cbd5e1);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    width: 100%;
    margin-bottom: 2rem;
    backdrop-filter: blur(8px);
    text-align: left;
}

.gpb-rules-card h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.65rem;
    color: var(--text-main, #0f172a);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.gpb-rules-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.gpb-rules-card li {
    font-size: 0.88rem;
    color: var(--text-muted, #475569);
    line-height: 1.5;
    position: relative;
    padding-left: 1.25rem;
}

.gpb-rules-card li::before {
    content: "•";
    color: #ef4444;
    font-size: 1.2rem;
    position: absolute;
    left: 0.15rem;
    top: -0.15rem;
}

.gpb-rules-card strong {
    color: var(--text-main, #0f172a);
}

/* Success / Completion Overlay */
.gpb-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.gpb-modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.gpb-modal-card {
    background: #ffffff;
    border: 2px solid #000000;
    border-radius: 16px;
    padding: 2.25rem;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    transform: scale(0.92);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gpb-modal-overlay.show .gpb-modal-card {
    transform: scale(1);
}

.gpb-modal-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.gpb-modal-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 0.35rem;
}

.gpb-modal-subtitle {
    color: #64748b;
    font-size: 0.92rem;
    margin-bottom: 1.25rem;
}

/* Stars */
.gpb-stars-row {
    font-size: 2.2rem;
    color: #cbd5e1;
    margin-bottom: 1.25rem;
    letter-spacing: 0.25rem;
}

.gpb-stars-row .active-star {
    color: #f59e0b;
    filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.6));
    display: inline-block;
}

.gpb-modal-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.gpb-modal-stat-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.85rem;
}

.gpb-modal-stat-val {
    font-size: 1.6rem;
    font-weight: 800;
    color: #0284c7;
}

.gpb-modal-stat-val.efficiency {
    color: #16a34a;
}

.gpb-modal-stat-label {
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.2rem;
}

.gpb-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.gpb-modal-actions .btn-next-lvl {
    width: 100%;
    padding: 0.85rem;
    background: #000000;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gpb-modal-actions .btn-next-lvl:hover {
    background: #1e293b;
    transform: translateY(-1px);
}

.gpb-modal-actions .btn-replay {
    width: 100%;
    padding: 0.65rem;
    background: transparent;
    color: #64748b;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.gpb-modal-actions .btn-replay:hover {
    color: #0f172a;
    background: #f1f5f9;
}

/* Keyframes */
@keyframes flowPulse {
    0% { transform: scale(0.92); opacity: 0.6; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes shakeError {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* Responsive */
@media (max-width: 640px) {
    .gpb-grid-6x6 {
        grid-template-columns: repeat(6, 40px);
        grid-template-rows: repeat(6, 40px);
    }
    
    .gpb-grid-9x9 {
        grid-template-columns: repeat(9, 28px);
        grid-template-rows: repeat(9, 28px);
    }

    .gpb-grid-9x9 .gpb-arrow {
        font-size: 0.95rem;
    }

    .gpb-marker {
        font-size: 1.6rem;
    }

    .gpb-marker.start {
        left: -40px;
    }

    .gpb-marker.end {
        right: -40px;
    }

    .gpb-btn-action {
        flex: 1 1 45%;
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }
}
