:root {
    /* Light Theme Defaults */
    --bg-color: #ffffff;
    --sidebar-bg: #f8f9fa;
    --item-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #888888;
    --accent-color: #007aff;
    --border-color: #e9ecef;
    --input-bg: #ffffff;
    --shadow-sm: rgba(0, 0, 0, 0.05);
    --shadow-md: rgba(0, 0, 0, 0.1);
    --header-bg: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] {
    --bg-color: #121212;
    --sidebar-bg: #1e1e1e;
    --item-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --text-muted: #a0a0a0;
    --accent-color: #bb86fc;
    --border-color: #333333;
    --input-bg: #2a2a2a;
    --shadow-sm: rgba(0, 0, 0, 0.3);
    --shadow-md: rgba(0, 0, 0, 0.5);
    --header-bg: rgba(30, 30, 30, 0.85);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-color: #121212;
        --sidebar-bg: #1e1e1e;
        --item-bg: #1e1e1e;
        --text-color: #e0e0e0;
        --text-muted: #a0a0a0;
        --accent-color: #bb86fc;
        --border-color: #333333;
        --input-bg: #2a2a2a;
        --shadow-sm: rgba(0, 0, 0, 0.3);
        --shadow-md: rgba(0, 0, 0, 0.5);
        --header-bg: rgba(30, 30, 30, 0.85);
    }
}

* {
    box-sizing: border-box;
}

body {
    display: flex !important;
    height: 100vh !important;
    margin: 0 !important;
    font-family:
        "Segoe UI",
        system-ui,
        -apple-system,
        sans-serif !important;
    background: var(--bg-color) !important;
    color: var(--text-color) !important;
    overflow: hidden;
}

/* Sidebar */
#sidebar {
    width: 260px !important;
    background: var(--sidebar-bg) !important;
    padding: 24px !important;
    border-right: 1px solid var(--border-color) !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    flex-shrink: 0;
    position: relative;
}

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.brand:hover {
    opacity: 0.8;
}

.brand-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.brand-name {
    font-size: 1.2rem;
    font-weight: 700;
}

#menu {
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
}

.menu-item {
    padding: 10px 14px !important;
    cursor: pointer !important;
    border-radius: 8px !important;
    transition: all 0.2s !important;
    font-weight: 500 !important;
    font-size: 0.95rem !important;
}

.menu-item:hover {
    background: var(--border-color) !important;
}

.menu-item.active {
    background: var(--accent-color) !important;
    color: white !important;
}

h2 {
    font-size: 0.8rem !important;
    text-transform: uppercase !important;
    letter-spacing: 1.2px !important;
    color: var(--text-muted) !important;
    margin-bottom: 6px !important;
    margin-top: 8px !important;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 8px 0;
}

/* Theme Switcher */
#theme-switcher {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.theme-btn {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.6;
}

.theme-btn:hover {
    opacity: 1;
    background: var(--border-color);
}

.theme-btn.active {
    opacity: 1;
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: white;
}

/* Main Content */
#main {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
}

.search-container {
    padding: 24px !important;
    border-bottom: 1px solid var(--border-color) !important;
    flex-shrink: 0;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    box-shadow: 0 1px 10px var(--shadow-sm);
}

.search-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

#search {
    width: 100% !important;
    padding: 10px 36px 10px 12px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    background: var(--input-bg) !important;
    color: var(--text-color) !important;
    font-size: 0.95rem !important;
    outline: none !important;
    transition: border-color 0.2s !important;
}

#search:focus {
    border-color: var(--accent-color) !important;
}

#search-clear {
    position: absolute;
    right: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    display: none;
    align-items: center;
    justify-content: center;
}

#search-clear.show {
    display: flex;
}

#count {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Grid */
#grid {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 24px !important;
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 16px !important;
    align-content: start;
}

.category-header {
    grid-column: 1 / -1;
    font-size: 20px;
    font-weight: 600;
    padding: 10px 0 0;
    margin-top: 10px;
    color: var(--text-color);
}

.emoji-item {
    background: var(--item-bg);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition:
        transform 0.2s cubic-bezier(0.2, 0, 0.2, 1),
        box-shadow 0.2s;
    box-shadow: 0 2px 8px var(--shadow-sm);
    content-visibility: auto;
    contain-intrinsic-size: 140px 160px;
}

.emoji-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow-md);
}

.emoji-item img {
    width: 72px;
    height: 72px;
    opacity: 0;
    transition: opacity 0.3s ease-in;
    object-fit: contain;
}

.emoji-item .name {
    margin-top: 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-color);
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
}

#sentinel {
    grid-column: 1 / -1 !important;
    height: 40px !important;
}

/* Modal */
#modal-overlay {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.7) !important;
    display: none !important;
    justify-content: center !important;
    align-items: center !important;
    z-index: 1000 !important;
}

#modal-overlay.show {
    display: flex !important;
}

#modal-content {
    display: flex;
    background: var(--bg-color);
    padding: 30px;
    text-align: center;
    border-radius: 20px;
    max-width: 90vw;
    max-height: 90vh;
}

#modal-img {
    height: 70vh;
    width: auto;
    max-width: 50vw;
    padding: 32px;
    object-fit: contain;
    display: block;
}

.imginfo {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    padding: 32px;
    background-color: var(--sidebar-bg);
    border-radius: 20px;
    min-width: 240px;
}

.infotext {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

#modal-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
    text-align: start;
}

#modal-code {
    font-size: 14px;
    color: var(--text-muted);
    font-family: "SF Mono", "Monaco", monospace;
    margin-bottom: 24px;
    background-color: var(--bg-color);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    gap: 12px;
    width: 100%;
}

.modal-btn {
    flex: 1;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    outline: none;
}

.modal-btn.primary {
    background: var(--accent-color);
    color: white;
}

.modal-btn.primary:hover {
    opacity: 0.9;
}

#modal-close {
    position: absolute;
    top: 24px;
    right: 24px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Toast & Back to Top */
#toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 24px;
    border-radius: 24px;
    opacity: 0;
    transition: all 0.2s;
    pointer-events: none;
    z-index: 2000;
    font-size: 14px;
    backdrop-filter: blur(4px);
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

#back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 48px;
    height: 48px;
    background: var(--accent-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    border: none;
}

#back-to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(-10px);
}

#back-to-top svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
