/* Common Styles for Puzzle Games (Number Cages, Sudoku, Kakuro, etc.) */

/* Root Variables for Game Specific Colors */
:root {
    /* Difficulty Colors */
    --diff-color-1: #FDD835;
    --diff-color-2: #FFB300;
    --diff-color-3: #FB8C00;
    --diff-color-4: #EF6C00;
}

/* Main Container */
.puzzle-game-container {
    display: flex;
    flex-direction: column;
    padding: 15px;
    height: auto;
    width: 100%;
    box-sizing: border-box;
    align-items: center;
    /* Default center for many */
}

@media (min-width: 1150px) {
    .puzzle-game-container {
        align-items: center;
        padding: 30px 15px;
        height: calc(100vh - 53px);
    }
}

.puzzles-header {
    text-align: center;
    width: 100%;
}

.puzzles-header p {
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

/* Selection Screen */
.selection-screen {
    max-width: 900px;
    width: 100%;
    text-align: center;
}

.hidden-screen {
    display: none !important;
}

#game-view.selection-screen,
.game-view-container {
    max-width: 900px;
    /* Allow wider layout for game */
    display: none;
    /* Initially hidden */
}

/* Selection Groups */
.selection-group {
    margin-bottom: 30px;
}

.selection-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 25px;
    width: 100%;
}

.btn-circle-back {
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-circle-back:hover {
    background: var(--bg-tertiary);
    color: var(--primary-color);
    transform: scale(1.05);
}

.selection-controls .btn-primary {
    flex: 1;
    max-width: max-content;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selection-group h3 {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin: 10px 0;
    font-weight: 400;
}

/* Options Grid */
.options-grid {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

/* Shared Option Styles */
.option-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 2px solid var(--text-primary);
    border-radius: 12px;
    transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    font-weight: 400;
    user-select: none;
    margin-bottom: 5px;
    font-size: var(--font-sm);
}

.option-btn:hover {
    background: var(--bg-primary);
    opacity: 0.8;
}

.option-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

/* Number/Size Options (Square-ish) */
.option-number-btn {
    width: 50px;
    height: 50px;
}

/* Text Options (Rectangular/Pill) */
.option-text-btn {
    width: auto;
    padding: 4px 16px;
    min-width: 100px;
    text-transform: capitalize;
}

/* Custom Toggle Button */
.custom-toggle-container {
    margin: 10px 0 20px;
    text-align: center;
}

.toggle-custom-btn {
    background: transparent;
    border: none;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s;
    font-size: var(--font-sm);
    color: var(--primary-color);
    font-weight: 400;
}

.toggle-custom-btn:hover {
    color: var(--text-primary);
}

/* Game Header & Info */
.game-icon-header img {
    width: 90px;
    height: 90px;
    object-fit: contain;
    border-radius: 16px;
    border: 2px solid var(--text-primary);
}

.game-title-large {
    font-family: serif;
    font-size: 32px;
    color: var(--text-primary);
    margin: 5px 0 0 0;
    font-weight: 700;
}

.game-description {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 16px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* Game Layout */
.game-layout-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    width: 100%;
    border-radius: 8px;
}

@media (min-width: 1150px) {
    .game-layout-container {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 15px;
        border: 1px solid var(--border-color);
        padding: 15px;
    }
}

.game-sidebar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: 100%;
    /* Fallback */
    width: -webkit-fill-available;
}

@media (min-width: 1150px) {
    .game-sidebar {
        margin: 20px;
    }
}

/* Game Info Bar */
.game-info-bar {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    /* Default but often overridden inline */
    margin-bottom: 10px;
    max-width: 900px;
    align-items: center;
}

.game-timer {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-primary);
    padding: 4px 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.solution-btn {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-primary);
    padding: 6px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.solution-btn:hover {
    background: var(--bg-secondary);
    color: var(--primary-color);
}

/* Game Grid Generic */
.puzzle-grid-wrapper {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    position: relative;
}

.puzzle-grid {
    display: grid;
    gap: 0;
    background: var(--bg-primary);
    overflow: hidden;
    width: 500px;
    max-width: 100%;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    position: relative;
    border: none;
}

.grid-svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.puzzle-cell {
    aspect-ratio: 1 / 1;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
    z-index: 1;
    font-weight: 600;
    color: var(--text-primary);
    border: none;
}

.puzzle-cell:hover:not(.selected):not(.fixed) {
    background: var(--bg-secondary);
}

.puzzle-cell.selected {
    background: var(--primary-color) !important;
    color: #fff !important;
    font-weight: 800;
    z-index: 10;
    outline: 2px solid rgba(255, 107, 107, 0.5);
    outline-offset: -2px;
}

.puzzle-cell.fixed {
    background: var(--bg-secondary);
    color: var(--primary-color);
    cursor: default;
    font-weight: 500;
    z-index: 2;
}

.puzzle-cell.filled {
    font-weight: 500;
}

/* Tools & Controls */
.game-tools {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 350px;
    margin-bottom: 15px;
}

.tool-btn {
    flex: 1;
    padding: 8px;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:hover {
    background: var(--bg-secondary);
}

.tool-btn:active,
.tool-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
}

/* Number Pad */
.num-pad {
    margin-top: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 350px;
}

.num-btn {
    padding: 15px;
    height: auto;
    font-size: var(--font-lg);
    font-weight: 500;
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.num-btn:hover {
    background: var(--bg-secondary);
}

.num-btn.delete-btn {
    color: var(--error-color);
    border-color: var(--error-color);
}

/* Game Controls (Submit/New) */
.game-controls {
    display: flex;
    gap: 15px;
    width: 100%;
    max-width: 350px;
    margin-top: 25px;
}

.game-controls>button {
    flex: 1;
    justify-content: center;
}

/* Cell Notes */
.cell-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 2px;
}

.note-num {
    font-size: clamp(8px, 4cqi, 12px);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-family: monospace;
    font-weight: 700;
}

.note-1 {
    grid-area: 1 / 1;
}

.note-2 {
    grid-area: 1 / 2;
}

.note-3 {
    grid-area: 1 / 3;
}

.note-4 {
    grid-area: 2 / 1;
}

.note-5 {
    grid-area: 2 / 2;
}

.note-6 {
    grid-area: 2 / 3;
}

.note-7 {
    grid-area: 3 / 1;
}

.note-8 {
    grid-area: 3 / 2;
}

.note-9 {
    grid-area: 3 / 3;
}

/* Result Sheet Common */
.result-stats {
    display: flex;
    justify-content: space-around;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 15px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: var(--font-xs);
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 700;
    font-size: var(--font-sm);
    color: var(--text-primary);
}

.result-image-wrapper {
    position: relative;
    margin: 20px 0;
    border-radius: 12px;
    overflow: hidden;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.result-snapshot {
    height: 100%;
    object-fit: contain;
    opacity: 0.8;
    transition: opacity 0.3s;
}

.share-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(var(--primary-rgb), 0.4);
    transition: transform 0.2s;
}

.share-play-btn:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

/* Skeleton Loader */
.skeleton-loader {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-primary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-weight: 400;
}

.skeleton-loader span {
    font-size: var(--font-sm);
    letter-spacing: 0.5px;
    animation: pulse 1.5s ease-in-out infinite;
    position: relative;
    z-index: 2;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Mobile Responsive */
@media (max-width: 900px) {
    .game-layout-container {
        flex-direction: column !important;
        align-items: center;
        gap: 20px;
    }

    .game-sidebar {
        width: 100% !important;
        max-width: 500px;
        /* Limit width on tablet/mobile */
        margin: 0 !important;
        order: 2;
        /* Ensure sidebar is below grid on mobile */
    }

    .puzzle-grid-wrapper {
        order: 1;
        /* Grid always first */
        margin-bottom: 20px;
    }

    .game-controls {
        width: 100%;
        flex-direction: row;
        /* Keep buttons side-by-side if possible */
        justify-content: space-between;
    }

    .puzzle-grid {
        /* Generic mobile fallback */
        width: calc(100vw - 30px);
        max-width: 400px;
    }
}