* {
    box-sizing: border-box;
}

/* THEMES VIA CSS VARIABLES */
body {
    margin: 0;
    padding: 0;
    font-family: system-ui, sans-serif;
    overflow: hidden;
}

/* Default values (overridden by theme classes) */
:root {
    --bg: #050507;
    --bg-soft: #101114;
    --bg-elevated: #121218;
    --border-subtle: #24242c;
    --text: #eaeaea;
    --text-muted: #a6a6b3;
    --accent: #5865f2;
    --accent-soft: rgba(88,101,242,0.16);
    --accent-strong: #2e7cff;
}

/* Dark Theme */
body.theme-dark {
    --bg: #050507;
    --bg-soft: #101114;
    --bg-elevated: #121218;
    --border-subtle: #24242c;
    --text: #eaeaea;
    --text-muted: #a6a6b3;
    --accent: #5865f2;
    --accent-soft: rgba(88,101,242,0.16);
    --accent-strong: #2e7cff;
}

/* Light Theme */
body.theme-light {
    --bg: #f4f5f8;
    --bg-soft: #ffffff;
    --bg-elevated: #ffffff;
    --border-subtle: #c9c9d2;
    --text: #14141a;
    --text-muted: #55556a;
    --accent: #2563eb;
    --accent-soft: rgba(37,99,235,0.08);
    --accent-strong: #1d4ed8;
}

/* Neon Theme */
body.theme-neon {
    --bg: #05000c;
    --bg-soft: #0a0215;
    --bg-elevated: #110022;
    --border-subtle: #3b1a5f;
    --text: #f7f0ff;
    --text-muted: #b69fd9;
    --accent: #e11d48;
    --accent-soft: rgba(225,29,72,0.18);
    --accent-strong: #f97316;
}

/* LOADING OVERLAY */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top, #111, #000);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    color: #f5f5f5;
}

.loader-ring {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.15);
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

.loader-text {
    font-size: 14px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.8;
}

/* FORCE HIDE LOADING OVERLAY */
#loading-overlay.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}


/* TOP NAV */
#top-nav {
    height: 52px;
    width: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    z-index: 50;
    position: relative;
    color: var(--text);
    animation: navFadeIn 0.4s ease-out;
}

#top-nav .left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#top-nav .right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.theme-btn {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 999px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, color 0.15s ease;
    white-space: nowrap;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent-strong);
}

.primary-btn:hover {
    transform: translateY(-1px);
}

.secondary-btn {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--border-subtle);
}

.secondary-btn:hover {
    transform: translateY(-1px);
}

.ghost-btn {
    background: transparent;
    color: var(--accent-strong);
    border-color: var(--border-subtle);
}

.ghost-btn:hover {
    background: var(--accent-soft);
    transform: translateY(-1px);
}

#theme-switcher {
    display: flex;
    gap: 4px;
}

.theme-btn {
    background: var(--bg-soft);
    color: var(--text-muted);
    border-color: var(--border-subtle);
}

.theme-btn.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-color: var(--accent-strong);
}

/* MAIN LAYOUT */
#game-wrapper {
    display: flex;
    height: calc(100vh - 52px);
    width: 100vw;
    background: radial-gradient(circle at top, var(--bg-soft), var(--bg));
}

/* BOARD AREA */
#board-area {
    flex: 1;
    padding: 12px;
    position: relative;
    animation: boardFadeIn 0.5s ease-out;
}

.hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding-left: 2px;
}

#board-content {
    width: 100%;
    height: calc(100% - 16px);
    background: var(--bg-soft);
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    position: relative;
    overflow: hidden;
    background-image:
        linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
    background-size: 32px 32px, 32px 32px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.5);
    animation: boardPop 0.4s ease-out;
}

/* BOARD ITEMS */
.board-item {
    position: absolute;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: grab;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    user-select: none;
    white-space: nowrap;
    color: var(--text);
    background: linear-gradient(135deg, var(--bg-elevated), var(--bg-soft));
    border: 1px solid var(--border-subtle);
    box-shadow: 0 8px 18px rgba(0,0,0,0.5);
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        background 0.15s ease,
        opacity 0.15s ease;
    animation: itemSpawn 0.25s ease-out;
}

.board-item .emoji {
    font-size: 16px;
}

.board-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.6);
}

.board-item:active {
    cursor: grabbing;
    transform: scale(1.04);
}

/* SIDEBAR */
#sidebar {
    width: 280px;
    height: calc(100vh - 52px);
    background: rgba(0,0,0,0.76);
    backdrop-filter: blur(12px);
    border-left: 1px solid var(--border-subtle);
    position: absolute;
    right: 0;
    top: 52px;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.22,0.61,0.36,1);
    z-index: 20;
    box-shadow: -16px 0 40px rgba(0,0,0,0.85);
    color: var(--text);
}

#sidebar.collapsed {
    transform: translateX(240px);
}

#sidebar-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#sidebar-tabs {
    display: flex;
    gap: 6px;
}

.tab-btn {
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
}

.tab-btn.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-color: var(--accent-strong);
}

/* SIDEBAR TOGGLE */
#toggle-sidebar {
    position: absolute;
    left: -34px;
    top: 14px;
    width: 34px;
    height: 46px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-right: none;
    border-radius: 8px 0 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 30;
    transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

#sidebar.collapsed #toggle-sidebar i {
    transform: rotate(180deg);
}

#toggle-sidebar:hover {
    transform: translateX(-1px);
}

/* SIDEBAR INNER */
.sidebar-inner {
    padding: 14px;
    overflow-y: auto;
    flex: 1;
}

.input {
    width: 100%;
    padding: 7px 9px;
    font-size: 13px;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--border-subtle);
    color: var(--text);
    outline: none;
    margin-bottom: 10px;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.input:focus {
    border-color: var(--accent-strong);
}

/* INVENTORY ITEMS */
#inventory {
    display: flex;
    flex-direction: column;
    gap: 6px;
}


#az-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 10px;
}

.az-pill {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.1s ease, color 0.1s ease;
}

.az-pill.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-color: var(--accent-strong);
}

.az-pill:hover {
    background: var(--accent-soft);
}




/* ==========================================
   CUSTOM SCROLLBAR (GLOBAL)
   Applies to sidebar + page + lists
========================================== */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--accent-strong) var(--bg-elevated);
}

/* Chrome / Edge / Opera */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--bg-elevated);
    border-radius: 8px;
}

*::-webkit-scrollbar-thumb {
    background: var(--accent-strong);
    border-radius: 8px;
    border: 2px solid var(--bg-elevated);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}





.item-entry {
    padding: 6px 8px;
    border-radius: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    user-select: none;
    box-shadow: 0 6px 16px rgba(0,0,0,0.45);
    transition:
        background 0.15s ease,
        transform 0.1s ease,
        box-shadow 0.15s ease;
}

.item-entry:hover {
    background: var(--accent-soft);
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(0,0,0,0.6);
}

.item-entry .emoji {
    font-size: 16px;
}

/* TRASH TAB */
.trash-container {
    padding: 14px;
    margin: 10px;
    border-radius: 10px;
    background: rgba(255,0,0,0.06);
    border: 1px dashed rgba(255,80,80,0.4);
    color: var(--text);
    font-size: 13px;
}

/* LOGIN OVERLAY */
#lock-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top, rgba(0,0,0,0.75), rgba(0,0,0,0.9));
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlayFadeIn 0.25s ease-out;
}

#lock-overlay.hidden {
    display: none;
}

.lock-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    padding: 24px 28px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0,0,0,0.9);
    color: var(--text);
    animation: cardPop 0.25s ease-out;
}

/* HOW TO PLAY OVERLAY */
#howto-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top, rgba(0,0,0,0.8), rgba(0,0,0,0.95));
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
    animation: overlayFadeIn 0.25s ease-out;
}

#howto-overlay.hidden {
    display: none;
}

.howto-card {
    max-width: 520px;
    width: 90%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    padding: 22px 24px 18px 24px;
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(0,0,0,0.85);
    color: var(--text);
    animation: cardPop 0.25s ease-out;
    font-size: 14px;
}

.howto-card h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
}

.howto-card ol {
    padding-left: 18px;
    margin-top: 0;
    margin-bottom: 10px;
}

.howto-card li {
    margin-bottom: 4px;
}

.howto-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

/* MIX FLASH EFFECT */
.mix-flash {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    pointer-events: none;
    opacity: 0;
    mix-blend-mode: screen;
    transform: translate(-50%, -50%) scale(0.3);
}

.mix-flash.success {
    background: radial-gradient(circle, rgba(68, 255, 175, 1), rgba(0,0,0,0));
    animation: mixFlashSuccess 0.35s ease-out forwards;
}

.mix-flash.fail {
    background: radial-gradient(circle, rgba(255, 70, 90, 1), rgba(0,0,0,0));
    animation: mixFlashFail 0.35s ease-out forwards;
}

/* MOBILE LAYOUT */
@media (max-width: 768px) {
    body {
        overflow: auto;
        background: var(--bg);
    }

    #game-wrapper {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 52px);
    }

    #board-area {
        height: 60vh;
        padding: 10px;
    }

    #board-content {
        height: 100%;
    }

    #sidebar {
        position: relative;
        width: 100%;
        height: auto;
        top: 0;
        right: 0;
        box-shadow: 0 -10px 30px rgba(0,0,0,0.8);
        transform: translateX(0) !important;
    }

    #toggle-sidebar {
        display: none;
    }

    .sidebar-inner {
        max-height: 260px;
        overflow-y: auto;
    }

    #inventory {
        max-height: 200px;
        overflow-y: auto;
    }

    .howto-card {
        max-width: 95%;
        font-size: 13px;
    }
}

/* ANIMATIONS */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes navFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes boardFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes boardPop {
    from { transform: scale(0.97); }
    to { transform: scale(1); }
}

@keyframes overlayFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes cardPop {
    from { transform: translateY(6px) scale(0.96); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes itemSpawn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes mixFlashSuccess {
    0% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.3); }
    40% { opacity: 0.9; transform: translate(-50%, -50%) scale(3); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(5); }
}

@keyframes mixFlashFail {
    0% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.3); }
    40% { opacity: 0.9; transform: translate(-50%, -50%) scale(2.5); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(4); }
}

/* Utility */
.hidden {
    display: none;
}
