:root{
    --bg:#f3f4f6;
    --surface:#ffffff;
    --text:#1b1b1f;
    --muted:#6f6f73;
    --border:#e3e3e7;
    --accent:#0b57d0;
    --header-padding:24px;
    --search-height:56px;
    --search-radius:28px;
    --card-radius:28px;
    --dialog-radius:28px;
}

@media (prefers-color-scheme:dark){
    :root{
        --bg:#121316;
        --surface:#1d1e22;
        --text:#f5f5f5;
        --muted:#b5b5b8;
        --border:#323338;
        --accent:#a8c7fa;
    }
}

/* RESET */

*{
    box-sizing:border-box;
    -webkit-tap-highlight-color:transparent;
}

html,
body{
    margin:0;
    height:100%;
    overflow:hidden;
    overscroll-behavior-y:contain;
    font-family:Roboto,system-ui,sans-serif;
    background:var(--bg);
    color:var(--text);
}

.app{
    display:flex;
    flex-direction:column;
    height:100%;
    transform:translateY(0);
    transition:transform .24s cubic-bezier(.22,.85,.28,1);
    will-change:transform;
}

/* HEADER */

.app-header{
    position:sticky;
    top:0;
    z-index:1000;
    background:var(--bg);
    padding-top:calc(env(safe-area-inset-top) + 12px);
    padding-bottom:12px;
}

.app-title{
    margin:0;
    padding:0 var(--header-padding);
    font-size:24px;
    font-weight:600;
    line-height:40px;
}

/* SEARCH */

.search{
    padding:8px 16px 0;
}

.search-box{
    display:flex;
    align-items:center;
    height:var(--search-height);
    padding:0 18px;
    background:var(--surface);
    border:1px solid var(--border);
    border-radius:var(--search-radius);
}

.search-icon{
    display:flex;
    justify-content:center;
    align-items:center;
    margin-right:14px;
    color:var(--muted);
}

.material-search{
    position:relative;
    width:18px;
    height:18px;
    border:2px solid currentColor;
    border-radius:50%;
}

.material-search::after{
    content:"";
    position:absolute;
    right:-6px;
    bottom:-3px;
    width:8px;
    height:2px;
    background:currentColor;
    border-radius:2px;
    transform:rotate(45deg);
}

.search-box input{
    flex:1;
    border:none;
    outline:none;
    background:none;
    color:var(--text);
    font-size:17px;
}

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

.clear-icon{
    display:flex;
    justify-content:center;
    align-items:center;
    font-size:18px;
    line-height:1;
    font-family:system-ui,sans-serif;
    padding:0;
    visibility:hidden;
    border:none;
    background:none;
    color:var(--muted);
    cursor:pointer;
}

.clear-icon.visible{
    visibility:visible;
}

/* CONTENT */

#content{
    flex:1;
    overflow-y:auto;
    overflow-x:hidden;
    padding:12px 10px max(18px,env(safe-area-inset-bottom));
}

/* MATERIAL CARDS */

.section{
    margin-bottom:16px;
    background:var(--surface);
    border-radius:var(--card-radius);
    overflow:hidden;
    box-shadow:0 1px 3px rgba(0,0,0,.08);
}

.subsection{
    padding:18px;
}

.divider{
    height:1px;
    margin:0 18px;
    background:var(--border);
}

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

.section-title{
    font-size:15px;
    font-weight:600;
}

.clear-btn{
    border:none;
    background:none;
    color:var(--accent);
    font-size:15px;
    cursor:pointer;
}

/* CATEGORIES */

#categories{
    display:flex;
    flex-direction:column;
    gap:16px;
}

.category-header{
    padding:18px 20px 16px;
    background:var(--surface);
}

.category-header .section-title{
    font-size:17px;
    font-weight:600;
}

/* PAGE CONTAINER */

.page-container{
    display:flex;
    overflow-x:auto;
    overflow-y:hidden;
    scroll-snap-type:x mandatory;
    scrollbar-width:none;
    scroll-behavior: smooth;
    -ms-overflow-style:none;
    -webkit-overflow-scrolling:touch;
}

.page-container::-webkit-scrollbar{
    display:none;
}

.page{
    flex:0 0 100%;
    min-width:100%;
    display:grid;
    grid-template-columns:repeat(5,minmax(0,1fr));
    grid-template-rows:repeat(4,minmax(0,1fr));
    gap:10px;
    padding:18px;
    scroll-snap-align:start;
}

/* GRID */

.grid{
    display:grid;
    grid-template-columns:repeat(5,minmax(0,1fr));
    gap:10px;
    margin-top:14px;
}

/* EMOJI */

.emoji{
    position:relative;
    display:flex;
    justify-content:center;
    align-items:center;
    aspect-ratio:1;
    border-radius:18px;
    background:var(--bg);
    font-size:31px;
    user-select:none;
    touch-action:manipulation;
    transition:
        transform .12s ease,
        background-color .18s ease;
}

.emoji:active{
    transform:scale(.93);
}

.star{
    position:absolute;
    top:4px;
    right:6px;
    color:#f4c542;
    font-size:16px;
}

/* SEARCH */

#searchResults[hidden]{
    display:none;
}

#searchGrid{
    margin-top:14px;
}

/* MATERIAL DIALOG */

.dialog-overlay{
    position:fixed;
    inset:0;
    display:flex;
    justify-content:center;
    align-items:center;
    padding:24px;
    background:rgba(0,0,0,.35);
    backdrop-filter:blur(6px);
    z-index:6000;
}

.dialog{
    width:min(100%,420px);
    padding:24px;
    background:var(--surface);
    border-radius:var(--dialog-radius);
    box-shadow:0 16px 40px rgba(0,0,0,.30);
}

.dialog-title{
    margin-bottom:12px;
    font-size:22px;
    font-weight:600;
}

.dialog-message{
    margin-bottom:28px;
    color:var(--muted);
    line-height:1.5;
}

.dialog-buttons{
    display:flex;
    justify-content:flex-end;
    gap:12px;
}

.dialog-button{
    padding:10px 16px;
    border:none;
    border-radius:999px;
    background:none;
    color:var(--accent);
    font-size:15px;
    font-weight:600;
    cursor:pointer;
}

.dialog-button:hover{
    background:rgba(11,87,208,.08);
}

.dialog-button.confirm{
    background:rgba(11,87,208,.10);
}

/* PULL TO RESET */

.reset-spinner{
    position:fixed;
    top:calc(env(safe-area-inset-top) + 64px);
    left:50%;
    display:flex;
    justify-content:center;
    align-items:center;
    width:48px;
    height:48px;
    transform:translateX(-50%) scale(.5);
    opacity:0;
    pointer-events:none;
    z-index:7000;
    background:var(--surface);
    border-radius:50%;
    box-shadow:0 8px 24px rgba(0,0,0,.22);
    transition:
        opacity .18s ease,
        transform .18s ease;
}

.reset-spinner.show{
    opacity:1;
    transform:translateX(-50%) scale(1);
}

.reset-spinner div{
    width:22px;
    height:22px;
    border:3px solid var(--border);
    border-top-color:var(--accent);
    border-radius:50%;
}

.reset-spinner.loading div{
    animation:spin .8s linear infinite;
}

/* ANIMATIONS */

@keyframes spin{
    to{
        transform:rotate(360deg);
    }
}

/* SHARED TRANSITIONS */

.section,
.search-box,
.emoji,
.dialog{
    transition:
        background-color .20s ease,
        border-color .20s ease,
        color .20s ease;
}

/* HIDDEN */

[hidden]{
    display:none !important;
}

/* PULL TO RESET */

.app.pulling{
    transition:none;
}
