/* Global Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.theme-dark {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    transition: background 0.5s ease, color 0.3s ease;
    overflow-x: hidden;
}

#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    border-radius: 1rem;
}

.glass-header {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

.theme-dark .glass-header {
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Navigation */
.nav-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.nav-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    transform: translateY(-1px);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Buttons */
.btn {
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all 0.2s;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}

.btn-secondary:hover {
    background: rgba(99, 102, 241, 0.1);
}

/* Inputs */
.input-field {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--glass-border);
    padding: 0.75rem;
    border-radius: 0.5rem;
    width: 100%;
    transition: all 0.2s;
    color: var(--text-main);
}

.theme-dark .input-field {
    background: rgba(0, 0, 0, 0.2);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Game Cards */
.game-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-radius: 1rem;
    padding: 1rem;
    width: 100%;
    max-width: 64rem;
    /* increased from 42rem */
    margin: 0 auto;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

@media (min-width: 768px) {
    .game-card {
        padding: 2rem;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Landing Page */
.landing-hero {
    text-align: center;
    padding: 4rem 1rem;
    animation: fadeIn 0.8s ease-out;
}

.landing-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary) 0%, #ec4899 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1.5rem;
    letter-spacing: -0.02em;
}

.landing-subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto 2.5rem;
    line-height: 1.6;
}

/* --- Leaderboard Carousel --- */
.lb-carousel {
    margin-top: 3rem;
}

.lb-scroll-wrap {
    position: relative;
}

.lb-scroll {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    gap: 1.5rem;
    padding: 0.5rem 1rem 1rem;
    scrollbar-width: none;
}
.lb-scroll::-webkit-scrollbar { display: none; }

.lb-scroll > .leaderboard-card {
    flex: 0 0 calc((100% - 3rem) / 3) !important;
    scroll-snap-align: start;
    min-width: 280px;
}

@media (max-width: 1023px) {
    .lb-scroll > .leaderboard-card {
        flex: 0 0 calc((100% - 1.5rem) / 2) !important;
    }
}
@media (max-width: 639px) {
    .lb-scroll > .leaderboard-card {
        flex: 0 0 85% !important;
        min-width: 0;
    }
    .lb-scroll { gap: 1rem; padding: 0.5rem 0.75rem 1rem; }
}

/* Fade edges to hint more content */
.lb-fade {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3rem;
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.3s;
}
.lb-fade-left {
    left: 0;
    background: linear-gradient(to right, var(--bg-start, #f5f7fa), transparent);
}
.lb-fade-right {
    right: 0;
    background: linear-gradient(to left, var(--bg-start, #f5f7fa), transparent);
}
.lb-fade-hidden { opacity: 0; }

/* Navigation arrows — centered below */
.lb-nav {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.lb-arrow {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text-main);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}
.lb-arrow:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.lb-arrow-hidden {
    opacity: 0.3;
    pointer-events: none;
}

.leaderboard-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    border-radius: 1rem;
    padding: 1.5rem;
}

.leaderboard-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.leaderboard-list {
    list-style: none;
    padding: 0;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.95rem;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.rank-badge {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    margin-right: 0.5rem;
}

/* Specific Game Styles (Fixed) */
.wordle-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    justify-content: center;
}

.wordle-cell {
    width: 50px;
    height: 50px;
    border: 2px solid var(--glass-border);
    transform-style: preserve-3d;
    transition: all 0.3s;
    /* Old-school robust centering */
    display: block !important;
    text-align: center;
    line-height: 46px;
    padding: 0;
    margin: 0;
}

.wordle-cell.correct {
    background: #22c55e;
    border-color: #22c55e;
    color: white;
}

.wordle-cell.misplaced {
    background: #eab308;
    border-color: #eab308;
    color: white;
}

.wordle-cell.incorrect {
    background: #6b7280;
    border-color: #6b7280;
    color: white;
}

.memory-card {
    width: 70px;
    height: 70px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    cursor: pointer;
}

.memory-card.flipped {
    transform: rotateY(180deg);
}

.memory-card .content {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.memory-card .front {
    background: white;
    transform: rotateY(180deg);
}

.memory-card .back {
    background: var(--primary);
    color: white;
    font-size: 1.5rem;
}

#minesweeper-grid {
    display: grid;
    gap: 2px;
    background: #9ca3af;
    padding: 2px;
    border-radius: 4px;
}

.minesweeper-cell {
    width: 30px;
    height: 30px;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
}

.minesweeper-cell.revealed {
    background: #fff;
}

.minesweeper-cell[data-value="1"] {
    color: blue;
}

.minesweeper-cell[data-value="2"] {
    color: green;
}

.minesweeper-cell[data-value="3"] {
    color: red;
}

.minesweeper-cell[data-value="4"] {
    color: darkblue;
}

/* Zip Game Styles */
#zip-board {
    display: inline-block;
    padding: 10px;
    background: #eee;
    border-radius: 8px;
    user-select: none;
}

#zip-grid {
    display: grid;
    gap: 0;
    --size: 7;
    grid-template-columns: repeat(var(--size), 40px);
    grid-template-rows: repeat(var(--size), 40px);
    border: 2px solid #333;
    background: #fff;
}

.zcell {
    position: relative;
    border: 1px solid #ddd;
    box-sizing: border-box;
    /* Ensure border doesn't expand cell */
    cursor: pointer;
}

.zcell.visited {
    background: #e0e7ff;
}

.zcell.anchor {
    background: #c7d2fe;
    font-weight: bold;
}

.knot {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    /* Make text visible on colored bg */
}

/* Fix visibility of numbers inside Zip cells */
.zcell.anchor .knot {
    color: #fff;
    /* White text for dark knot background */
}

.zcell .knot {
    color: transparent;
    /* Hide empty knots */
}

/* Zip segments */
.seg {
    position: absolute;
    background: #4f46e5;
    z-index: 5;
    display: none;
}

.seg.show {
    display: block;
}

/* Adjusted for 40px cell with border-box */
.seg.up {
    top: 0;
    left: 17px;
    width: 4px;
    height: 20px;
}

.seg.down {
    bottom: 0;
    left: 17px;
    width: 4px;
    height: 20px;
}

.seg.left {
    top: 17px;
    left: 0;
    width: 20px;
    height: 4px;
}

.seg.right {
    top: 17px;
    right: 0;
    width: 20px;
    height: 4px;
}


/* Sudoku Component Styles */
#game-sudoku {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --accent: #4f46e5;
    --danger: #ef4444;
    --grid: #9ca3af;
    --grid-bold: #1f2937;
    --select: #bfdbfe;
}

#game-sudoku #board {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1;
    border: 3px solid var(--grid-bold);
    border-radius: 12px;
    overflow: hidden;
    background: white;
    margin: 0 auto
}

#game-sudoku .sgrid {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: repeat(9, minmax(0, 1fr));
}

#game-sudoku .cell {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    /* Force shrinking */
    position: relative;
    border: 1px solid var(--grid);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
    user-select: none;
}

#game-sudoku .cell.given {
    background: #eff6ff;
    color: #000;
    font-weight: 800
}

#game-sudoku .cell.selected {
    background: var(--select)
}

#game-sudoku .cell.same {
    background: #e0e7ff
}

#game-sudoku .cell.peer {
    background: #f1f5f9
}

#game-sudoku .cell.error {
    background: #fee2e2
}

#game-sudoku .cell.conflict {
    color: var(--danger)
}

#game-sudoku .cell.btop {
    border-top: 2px solid var(--grid-bold)
}

#game-sudoku .cell.bleft {
    border-left: 2px solid var(--grid-bold)
}

#game-sudoku .cell.bright {
    border-right: 2px solid var(--grid-bold)
}

#game-sudoku .cell.bbottom {
    border-bottom: 2px solid var(--grid-bold)
}

#game-sudoku .pencil {
    position: absolute;
    inset: 2px;
    font-size: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    opacity: .9
}

#game-sudoku .pencil span {
    font-size: 11px;
    color: #4b5563;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center
}

#game-sudoku #keypad {
    width: 100%;
    max-width: 600px;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
    margin: 0 auto
}

#game-sudoku #keypad button {
    padding: 12px 0;
    border-radius: 10px;
    font-size: 20px;
    font-weight: 700;
    background: white;
    border: 2px solid #d1d5db;
    box-shadow: 0 3px 0 #d1d5db;
    color: #374151;
    transition: transform 0.1s, box-shadow 0.1s;
    touch-action: manipulation;
}

#game-sudoku #keypad button:active {
    transform: translateY(3px);
    box-shadow: none;
}

#game-sudoku #keypad .danger {
    background: #fee2e2;
    border-color: #fca5a5;
    box-shadow: 0 3px 0 #fca5a5;
    color: #b91c1c
}

#game-sudoku #keypad .danger:active {
    box-shadow: none;
}

@media (max-width: 600px) {
    #game-sudoku #keypad {
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
    }

    #game-sudoku .cell {
        font-size: clamp(14px, 5vw, 24px);
    }

    .game-card {
        padding: 1rem;
    }
}

/* Transitions */
.slide-up {
    animation: slideUp 0.3s ease-out forwards;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.fade-in {
    animation: fadeIn 0.2s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}