/* Shared styles for both Desktop and Mobile */

:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --accent-color: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.4);
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;

    /* Game Element Colors */
    --wall-color: #475569;
    --floor-color: #1e293b;
    --target-color: #64748b;
    --box-color: #f59e0b;
    --box-target-color: #10b981;
    --player-color: #38bdf8;
    --player-on-target-color: #10b981;

    /* Scalable dimensions */
    --board-border: calc(var(--cell-size) / 4);
    --gap: 1.5px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    opacity: 0;
    transition: opacity 0.2s ease;
}

body.ready {
    opacity: 1;
}

/* Unified Hide Utility */
.desktop-only {
    display: none !important;
}

.mobile-only {
    display: none !important;
}

.is-desktop .desktop-only {
    display: block !important;
}

.is-desktop header.desktop-only,
.is-desktop footer.desktop-only {
    display: flex !important;
}

.is-mobile .mobile-only {
    display: block !important;
}

.is-mobile section.mobile-only,
.is-mobile footer.mobile-only {
    display: flex !important;
}

/* Modal and Overlay shared styles (moved from inline where possible) */
.help-scroll {
    text-align: left;
    max-height: 40vh;
    overflow-y: auto;
    padding-right: 10px;
}

h3 {
    color: var(--text-color);
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.branding {
    margin-bottom: 25px;
}

.branding h2 {
    margin-bottom: 5px;
}

.branding .tagline {
    font-size: 0.9rem;
    color: var(--accent-color);
    margin-bottom: 10px;
}

.branding .credits {
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-muted);
}

.branding .game-id {
    font-size: 0.6rem;
    color: var(--accent-color);
    opacity: 0.7;
    /* Slightly more visible */
    font-family: 'Roboto Mono', monospace;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* --- COLLECTION MANAGER --- */
/* --- COLLECTION MANAGER --- */
#settings-modal .overlay-content {
    display: flex;
    flex-direction: column;
    padding: 0;
    /* Let internal containers handle padding */
    height: 90vh;
    /* Fixed height for stability */
    max-height: 90vh;
    width: 90vw;
    max-width: 800px;
    min-width: 310px;
    overflow: hidden;
    /* Body will handle children */
}

.cm-header {
    padding: 20px 20px 10px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.cm-body {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
    /* No nested scrolling */
    scrollbar-gutter: stable;
}

.cm-footer {
    padding: 10px 20px 20px;
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.cm-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cm-modal-header h2 {
    margin-bottom: 0;
}

/* Portrait / Vertical Layout */
.cm-portrait {
    display: flex;
    flex-direction: column;
    padding: 10px 20px;
    gap: 4px;
    height: 100%;
    width: 100%;
    justify-content: flex-start;
    /* Ensure start-aligned */
}

.cm-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    user-select: none;
    flex-shrink: 0;
}

.cm-group-header.open {
    color: var(--accent-color);
    background: rgba(56, 189, 248, 0.08);
}

.cm-group-header.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.cm-group-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 0 1 auto;
    /* Allow growth but prioritize shrink/stability */
    overflow-y: auto;
    padding: 4px 0;
    scrollbar-gutter: stable;
    min-height: 0;
}

/* Landscape / Horizontal Layout */
.cm-landscape {
    flex-direction: row;
    height: 100%;
    width: 100%;
}

.cm-sidebar {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(0, 0, 0, 0.1);
}

.cm-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.cm-sidebar-header h3 {
    margin-bottom: 0;
    font-size: 1rem;
    color: var(--text-color);
}

.cm-sidebar-refresh {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
}

.cm-sidebar-groups {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.cm-sidebar-close {
    margin-top: auto;
    width: 100%;
    flex-shrink: 0;
}

.cm-content-area {
    flex: 1;
    padding: 10px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-gutter: stable;
}

.cm-sidebar-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 6px;
    text-align: left;
    transition: all 0.15s;
    user-select: none;
}

.cm-sidebar-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
}

.cm-sidebar-btn.active {
    background: var(--accent-color);
    color: #020617;
}

.cm-sidebar-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Common Item Components */
.cm-count {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 0.7rem;
    margin-left: 8px;
}

.cm-sidebar-btn.active .cm-count {
    background: rgba(0, 0, 0, 0.2);
}

.cm-item {
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid transparent;
    transition: border-color 0.15s;
    background: rgba(255, 255, 255, 0.03);
    flex-shrink: 0;
    /* No squishing */
}

.cm-item.cm-active {
    border-color: var(--accent-color);
}

.cm-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    cursor: pointer;
}

.cm-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

.cm-chevron {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    width: 30px;
    display: flex;
    justify-content: center;
}

.cm-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.cm-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.cm-cache-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    flex-shrink: 0;
    width: 40px;
    display: flex;
    justify-content: center;
}

.cm-detail {
    padding: 0 12px 12px 40px;
    background: rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cm-description {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.cm-reset-btn {
    align-self: flex-start;
    font-size: 0.75rem;
    padding: 6px 12px;
}

.icon-btn {
    background-color: var(--card-bg);
    color: var(--text-color);
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: var(--accent-color);
    color: #020617;
}

/* Fix for landscape scaling issues */
@media (orientation: landscape) and (max-height: 500px) {
    #settings-modal .overlay-content {
        transform: scale(1);
        /* No scale down */
        height: 95vh;
        max-height: 95vh;
    }
}

.modal-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.primary-btn,
.secondary-btn {
    touch-action: none;
}

/* Ensure buttons in modals are separated from content */
.overlay-content .primary-btn,
.overlay-content .secondary-btn {
    margin-top: 25px;
}

.is-desktop .modal-actions {
    flex-direction: row;
    justify-content: center;
}

.header-actions {
    display: flex;
    gap: 8px;
    margin-left: 20px;
}

/* Z-Index Registry managed at the end of each element block */

#message-overlay,
#about-modal,
#settings-modal {
    z-index: 300 !important;
    /* Top layer */
}

/* --- CORE GAME ELEMENTS --- */
#board {
    display: grid;
    gap: var(--gap, 1px);
    background-color: #020617;
    border: var(--board-border) solid var(--wall-color);
    border-radius: 8px;
    outline: 1px solid rgba(255, 255, 255, 0.08);
    outline-offset: -1px;
    box-shadow:
        0 0 40px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(0, 0, 0, 0.4),
        inset 0 0 25px rgba(0, 0, 0, 0.7),
        inset 0 0 0 1px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease, filter 2.5s ease-out, opacity 2.5s ease-out, box-shadow 2.5s ease-out;
}

#board>div {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 4px;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.wall {
    background-color: var(--wall-color);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.floor {
    background-color: var(--floor-color);
}

.target {
    background-color: rgba(16, 185, 129, 0.20);
}

.target::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    background-color: var(--target-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 5px var(--target-color);
    z-index: 5;
}

/* BOX — visual drawn in ::before so floor cell background shows around the edges */
.box {
    z-index: 10;
}

.box::before {
    content: '';
    position: absolute;
    inset: 0;
    transform: scale(0.85);
    background-color: var(--box-color);
    background-image:
        linear-gradient(45deg, transparent 47%, rgba(0, 0, 0, 0.15) 47%, rgba(0, 0, 0, 0.15) 53%, transparent 53%),
        linear-gradient(-45deg, transparent 47%, rgba(0, 0, 0, 0.15) 47%, rgba(0, 0, 0, 0.15) 53%, transparent 53%);
    border: calc(var(--cell-size) / 40) solid rgba(0, 0, 0, 0.2);
    border-radius: calc(var(--cell-size) / 10);
    box-shadow:
        0 calc(var(--cell-size) / 12) calc(var(--cell-size) / 5) rgba(0, 0, 0, 0.4),
        inset 0 calc(var(--cell-size) / 50) calc(var(--cell-size) / 50) rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

/* Suppress target dot when box is on target */
.box::after {
    display: none;
}

.box.box-on-target::before {
    background-color: var(--box-target-color);
    background-image:
        linear-gradient(45deg, transparent 47%, rgba(255, 255, 255, 0.3) 47%, rgba(255, 255, 255, 0.3) 53%, transparent 53%),
        linear-gradient(-45deg, transparent 47%, rgba(255, 255, 255, 0.3) 47%, rgba(255, 255, 255, 0.3) 53%, transparent 53%);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow:
        0 0 calc(var(--cell-size) / 3) rgba(16, 185, 129, 0.5),
        inset 0 calc(var(--cell-size) / 50) calc(var(--cell-size) / 50) rgba(255, 255, 255, 0.3);
}

/* PLAYER — visual drawn in ::before so floor cell background shows around the edges */
.player {
    z-index: 3;
}

.player::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    /* Iris effect with 3D ambient lighting outer sphere */
    background: radial-gradient(circle at 50% 50%,
            white 0%,
            black 4%,
            black 22%,
            rgba(2, 132, 199, 0.75) 23%,
            var(--player-color) 44%,
            rgba(2, 132, 199, 1) 66%);
    box-shadow: 0 0 15px var(--accent-glow);
    animation: pulse 0.833s infinite ease-in-out;
    pointer-events: none;
}

/* Suppress target dot when player is on target */
.player::after {
    display: none;
}

/* Player on target — green iris eye */
.player.target::before {
    background: radial-gradient(circle at 50% 50%,
            white 0%,
            black 4%,
            black 22%,
            rgba(4, 120, 87, 0.75) 23%,
            var(--player-on-target-color) 44%,
            rgba(4, 120, 87, 1) 66%);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.6);
}

/* Stop player pulse animation when level is finished */
.level-solved .player::before,
.level-celebrating .player::before {
    animation: none;
    transform: scale(0.95);
    box-shadow: 0 0 15px var(--accent-glow);
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(0.8);
        box-shadow: 0 0 10px var(--accent-glow);
    }

    50% {
        transform: scale(0.95);
        box-shadow: 0 0 20px var(--accent-glow);
    }
}

.level-celebrating #board {
    transition: filter 0.2s ease-out, box-shadow 0.2s ease-out;
    filter: brightness(1.3) contrast(1.1);
    box-shadow:
        0 0 80px rgba(16, 185, 129, 0.6),
        0 0 0 1px rgba(0, 0, 0, 0.4),
        inset 0 0 25px rgba(0, 0, 0, 0.7),
        inset 0 0 0 1px rgba(0, 0, 0, 0.5);
    opacity: 1;
}

.level-solved #board {
    filter: grayscale(0.5) contrast(0.8);
    opacity: 0.7;
}

/* Completed Badge (Shared logic) */
#completed-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--box-target-color);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
    pointer-events: none;
    z-index: 105;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#completed-badge.show {
    opacity: 1;
    transform: translateY(0);
}