:root {
    /* Design Tokens - Modern Apple-like Palette */
    /* Light Mode */
    --bg-color: #F5F5F7; /* Apple system gray 6/background */
    --sidebar-bg: rgba(255, 255, 255, 0.8); /* Translucent */
    --text-color: #1D1D1F; /* Almost black */
    --text-secondary: #86868B;
    --border-color: rgba(0, 0, 0, 0.1); /* Subtle separator */
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-hover-bg: rgba(255, 255, 255, 0.9);
    --primary-color: #007AFF; /* Apple Blue */
    --primary-hover: #0071E3;
    
    /* Shadows - Diffuse and soft */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.12);
    
    /* Radius */
    --radius-sm: 10px;
    --radius-md: 18px; /* Smooth corners */
    --radius-lg: 24px;
    
    --transition-fast: 0.3s cubic-bezier(0.25, 0.1, 0.25, 1); /* Smooth ease */
    --backdrop-blur: blur(20px);
    --hover-border-color: rgba(0, 0, 0, 0.3); /* Reduced from 0.5 */
}

[data-theme="dark"] {
    /* Dark Mode - Midnight */
    --bg-color: #000000;
    --sidebar-bg: rgba(28, 28, 30, 0.8);
    --text-color: rgba(245, 245, 247, 0.7); /* Reduced brightness further */
    --text-secondary: #86868B;
    --border-color: rgba(255, 255, 255, 0.1);
    --card-bg: rgba(28, 28, 30, 0.5); /* Slightly more transparent */
    --card-hover-bg: rgba(44, 44, 46, 0.55);
    --primary-color: #0A84FF; /* Dark mode blue */
    --primary-hover: #409CFF;
    --hover-border-color: rgba(255, 255, 255, 0.3); /* Reduced from 0.5 */
    /* Shadows - weaker in dark mode? */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar - Glassmorphism */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 32px 24px;
    flex-shrink: 0;
    z-index: 100;
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
}

.logo-img {
    width: 28px;
    height: 28px;
    margin-right: 12px;
    object-fit: contain;
    /* Subtle shadow for logo */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.05));
}

.logo h1 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0;
    color: var(--text-color);
    letter-spacing: -0.01em;
}

.controls {
    display: flex;
    align-items: center;
}

.search-box {
    margin-bottom: 24px;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

.search-box input {
    width: 100%;
    padding: 10px 36px 10px 14px; /* Slightly more compact height */
    border: none; /* Removed border */
    border-radius: 10px; /* iOS style input radius */
    background-color: rgba(118, 118, 128, 0.12); /* Apple system fill */
    color: var(--text-color);
    margin-bottom: 0;
    font-size: 15px; /* Standard iOS/macOS font size */
    transition: all var(--transition-fast);
}

.search-box input:focus {
    outline: none;
    background-color: rgba(118, 118, 128, 0.08);
    box-shadow: 0 0 0 2px var(--primary-color); /* Focus ring */
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(142, 142, 147, 0.5); /* Fill style clear button */
    border: none;
    color: white;
    cursor: pointer;
    font-size: 10px;
    width: 18px;
    height: 18px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0.8;
}

.clear-btn:hover {
    background-color: rgba(142, 142, 147, 0.8);
    opacity: 1;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.site-footer {
    text-align: center;
    font-size: 11px; /* Smaller, cleaner */
    color: var(--text-secondary);
    line-height: 1.4;
    opacity: 0.6;
    font-weight: 500;
}

.site-footer a {
    color: inherit;
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--text-color);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.btn-icon:hover {
    background-color: rgba(0,0,0,0.05);
    transform: scale(1.05); /* Subtle scale instead of translate */
}

.category-nav {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.category-nav::-webkit-scrollbar {
    width: 4px;
}
.category-nav::-webkit-scrollbar-track {
    background: transparent;
}
.category-nav::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}

.category-nav h3 {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    padding-left: 12px;
}

.category-nav ul {
    list-style: none;
}

.category-nav li {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 8px; /* Slightly tighter radius */
    color: var(--text-color);
    margin-bottom: 2px;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.category-nav li.active {
    background-color: rgba(0,0,0,0.03); /* Matches hover state */
    color: var(--text-color);
    font-weight: 600;
}

[data-theme="dark"] .category-nav li.active {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Update hover to be consistent */
.category-nav li:hover {
    background-color: rgba(0,0,0,0.03);
}

[data-theme="dark"] .category-nav li:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    position: relative;
    background-color: var(--bg-color);
}

.icon-grid {
    display: grid;
    /* Maintain PC Grid Logic */
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 20px;
    padding-bottom: 80px;
}

.icon-card {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    /* No border on cards for cleaner look, relying on shadow/bg contrast */
}

.icon-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.1) inset; /* 1px internal border, 10% opacity for "weak" look, or 0.5? User said 50% opacity. */
    /* Wait, user said 1px internal stroke, 50% opacity. */
}

/* Let's refine the hover style */
.icon-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md), inset 0 0 0 1px var(--hover-border-color);
}

.icon-card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
}

.icon-img-wrapper {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    transition: transform var(--transition-fast);
}

.icon-card:hover .icon-img-wrapper {
    transform: scale(1.1);
}

.icon-img-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.1)); /* Better shadow on icons */
}

[data-theme="dark"] .icon-img-wrapper img {
    opacity: 0.8; /* Adjusted from 0.7 to 0.8 (was 0.85 before) */
}

/* Icon Name - Fixed 2-line layout with vertical centering (Preserved) */
.icon-name {
    font-size: 0.75rem;
    line-height: 1.3;
    text-align: center;
    color: var(--text-color);
    font-weight: 500;
    padding: 0 4px;
    width: 100%;
    height: 2.6em; 
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: auto;
}

.icon-name span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    max-height: 100%;
    transform: translateY(2px);
}

/* Utilities */
.hidden {
    display: none !important;
}

.loading, .empty-state {
    text-align: center;
    padding: 60px;
    color: var(--text-secondary);
    font-size: 15px;
    background: transparent; /* Remove box for cleaner look */
    margin-top: 20px;
}

/* Back to Top Button - Apple Style */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 44px; /* Standard touch target */
    height: 44px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-color); /* Icon color matching text */
    border: 1px solid rgba(0,0,0,0.05); /* Subtle border */
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

[data-theme="dark"] .back-to-top {
    background-color: rgba(44, 44, 46, 0.8);
    border-color: rgba(255,255,255,0.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.back-to-top:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    background-color: var(--bg-color); /* Opaque on hover */
}

.back-to-top.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.9);
    display: flex !important;
}

/* Toast - Pill Style */
.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: rgba(30, 30, 30, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    z-index: 1100;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    font-weight: 500;
    font-size: 14px;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.toast:not(.hidden) {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Responsive Design Logic - STRICTLY PRESERVED */

/* PC (>768px) */
@media (min-width: 1025px) {
    .hidden-desktop {
        display: none !important;
    }
    
    /* PC Grid Config */
    .icon-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 20px;
    }
    .icon-card { padding: 20px 12px 12px 12px; } /* Reduced bottom padding */
    .icon-img-wrapper { width: 56px; height: 56px; }
}

/* Tablet Portrait & iPad Portrait (<= 1024px) */
/* Increased breakpoint to include iPad Pro Portrait (1024px) */
@media (max-width: 1024px) {
    .hidden-mobile {
        display: none !important;
    }

    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 12px 16px; /* Slightly tighter on mobile */
        position: sticky;
        top: 0;
        z-index: 100;
        box-shadow: 0 1px 0 rgba(0,0,0,0.05); /* Subtle separator instead of deep shadow */
        background-color: rgba(255, 255, 255, 0.95); /* More opaque on mobile for readability */
    }

    [data-theme="dark"] .sidebar {
        background-color: rgba(28, 28, 30, 0.95);
    }

    .header-row {
        margin-bottom: 12px;
    }
    
    .logo {
        margin-bottom: 0;
    }
    
    .search-row {
        display: flex;
        gap: 12px;
    }

    .mobile-category-wrapper {
        flex: 0 0 100px;
    }

    .category-select {
        width: 100%;
        height: 100%;
        padding: 0 12px;
        border: none;
        border-radius: 10px;
        background-color: rgba(118, 118, 128, 0.12);
        color: var(--text-color);
        font-size: 14px;
        outline: none;
        appearance: none;
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 8px center;
        background-size: 14px;
    }

    .search-box {
        margin-bottom: 0;
        flex: 1;
    }

    .controls {
        margin-bottom: 0;
    }
    
    .btn-icon {
        width: 28px;
        height: 28px;
        padding: 0;
        border: none;
        font-size: 1.1rem;
    }

    .main-content {
        padding: 16px;
    }
    
    /* Tablet Grid: 5-6 columns logic (minmax 90px) */
    .icon-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 12px;
        padding-bottom: 40px;
    }
    
    .icon-card {
        padding: 12px 8px;
        border-radius: 14px; /* Slightly smaller radius for small cards */
    }
    
    .icon-img-wrapper {
        width: 40px;
        height: 40px;
        margin-bottom: 8px;
    }

    /* Mobile Text Sizes (Preserved) */
    .icon-name {
        font-size: 0.7rem; 
        line-height: 1.2;
        height: 2.4em; 
    }
    
    .mobile-footer {
        margin-top: 40px;
        padding-bottom: 20px;
        opacity: 0.5;
        font-size: 11px;
    }
}

/* Mobile Devices (< 480px) */
@media (max-width: 480px) {
    /* Force 4 columns */
    .icon-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .icon-card {
        padding: 8px 4px;
    }
    
    .icon-img-wrapper {
        width: 36px;
        height: 36px;
        margin-bottom: 6px;
    }
    
    .icon-name {
        font-size: 0.6rem;
    }
}

/* Small Foldable Devices (< 360px) */
@media (max-width: 359px) {
    /* Force 3 columns */
    .icon-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
