*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100vh; }

:root {
    --bg: #000000;
    --card: #141414;
    --card-hi: #1e1e1e;
    --ink: #ffffff;
    --ink-soft: #9a9a9a;
    --accent: #e02121;
    --accent-hi: #ff3b3b;
    --accent-soft: rgba(224, 33, 33, .14);
    --line: rgba(255, 255, 255, .12);
    --glow: rgba(224, 33, 33, .30);
    --shadow: 0 16px 44px -14px rgba(0, 0, 0, .8);
}

:root[data-theme="light"] {
    --bg: #ffffff;
    --card: #ffffff;
    --card-hi: #f2f2f2;
    --ink: #000000;
    --ink-soft: #6b6b6b;
    --accent: #d31616;
    --accent-hi: #f02626;
    --accent-soft: rgba(211, 22, 22, .12);
    --line: rgba(0, 0, 0, .14);
    --glow: rgba(211, 22, 22, .22);
    --shadow: 0 14px 40px -16px rgba(0, 0, 0, .28);
}

*:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

body {
    font-family: 'Quicksand', system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    margin: 0;
    overflow-x: hidden;
}

#content.hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.searchbox {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 620px;
    text-align: center;
    animation: pop .6s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes pop {
    from { opacity: 0; transform: scale(.96) translateY(14px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.logo {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    padding: .7rem;
}

.sitename,
.tagline {
    display: none;
}

.bar-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    width: 100%;
    max-width: 620px;
    margin-top: .6rem;
}
.engine {
    flex: 0 0 3rem;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255, 255, 255, .12);
    cursor: pointer;
    transition: background .2s ease, transform .2s ease;
}
.engine:hover { background: rgba(255, 255, 255, .22); transform: translateY(-1px); }
.engine-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    line-height: 0;
}
.engine-letter {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 1.2rem;
    line-height: 1;
    flex: none;
    color: #b01818;
}
.engine-favicon {
    display: block;
    width: 100%;
    height: 100%;
    padding: .4rem;
    object-fit: contain;
    border-radius: 50%;
    background: #f2f2f2;
}

.bar {
    display: flex;
    align-items: center;
    gap: .2rem;
    flex: 1;
    max-width: 560px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, .14);
    border-radius: 999px;
    padding: .45rem .55rem .45rem .4rem;
    box-shadow: 0 16px 44px -14px rgba(0, 0, 0, .5);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.bar:focus-within {
    border-color: #e02121;
    box-shadow: 0 0 0 4px rgba(224, 33, 33, .14), 0 16px 44px -14px rgba(0, 0, 0, .5);
}
.bar .mode-btn {
    flex: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.7rem;
    height: 2.7rem;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #5f5f5f;
    cursor: pointer;
    box-shadow: none;
    transition: background .2s ease, color .2s ease, transform .2s ease;
}
.bar .mode-btn:hover { background: #f2f2f2; color: #b01818; transform: translateY(-1px); }
.bar .mode-btn.active { color: #b01818; }

.bar input[type="search"] {
    flex: 1;
    border: none;
    background: transparent;
    color: #1a1a1a;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    padding: .5rem .4rem;
    outline: none;
    min-width: 0;
    appearance: none;
    -webkit-appearance: none;
}
.bar input[type="search"]::-webkit-search-cancel-button,
.bar input[type="search"]::-webkit-search-decoration,
.bar input[type="search"]::-webkit-search-results-button { -webkit-appearance: none; display: none; }
.bar input[type="search"]::-moz-search-cancel-button { display: none; }
.bar input[type="search"]::placeholder { color: #6b6b6b; font-weight: 500; }

.bar button {
    flex: none;
    width: 2.9rem;
    height: 2.9rem;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(135deg, #e02121, #ff3b3b);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px -8px rgba(224, 33, 33, .5);
    transition: transform .2s ease, filter .2s ease;
}
.bar button:hover { transform: translateY(-2px); filter: brightness(1.08); }

.engine-popup {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    z-index: 20;
    min-width: 220px;
    background: #141414;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 14px;
    padding: .4rem;
    box-shadow: 0 24px 60px -18px rgba(0, 0, 0, .8);
    animation: none;
}
.engine-popup.mode-popup { left: 3.4rem; min-width: 200px; }
.menu-popup {
    top: auto;
    bottom: calc(100% + 10px);
    left: auto;
    right: 0;
}
@keyframes popupIn {
    from { opacity: 0; transform: translateY(-6px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.engine-popup[hidden] { display: none; }
.engine-popup.open { animation: popupIn .18s ease-out; }
.engine-popup .pop-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    padding: .55rem .7rem;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: #fff;
    font-family: 'Quicksand', sans-serif;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background .15s ease;
}
.engine-popup .pop-item:hover { background: rgba(255, 255, 255, .06); }
.engine-popup .pop-item.active { background: #e02121; color: #fff; }
.engine-popup .pop-item.active:hover { background: #f02626; }
.engine-popup .pop-fav {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    object-fit: contain;
    background: #ffffff;
    flex: none;
}
.engine-popup .pop-fav.letter {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 1.15rem;
    color: #b01818;
    background: #ffffff;
}
.engine-popup .pop-fav.icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: #b01818;
}
.engine-popup .pop-fav.icon svg { width: 20px; height: 20px; }
.engine-popup .pop-divider { height: 1px; background: rgba(255, 255, 255, .12); margin: .3rem; }
.engine-popup .pop-manage { color: #9a9a9a; font-size: .82rem; }
.engine-popup .pop-manage:hover { color: #fff; }
.engine-popup .pop-mode {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.2rem;
    height: 2.2rem;
    flex: none;
    border-radius: 50%;
    background: #ffffff;
    color: #b01818;
}
.engine-popup .pop-mode svg { width: 20px; height: 20px; }
.engine-popup .pop-item.active .pop-mode { background: #ffffff; }
.engine-popup .pop-item.active .pop-mode svg { color: #b01818; }

.favorites {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.4rem;
    width: 100%;
    max-width: 600px;
}
.fav {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    width: 86px;
    padding: .8rem .4rem;
    border-radius: 22px;
    text-decoration: none;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.fav:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 20px 44px -16px var(--glow);
}
#content.hero.has-bg .fav { background: rgba(10, 10, 10, .72); backdrop-filter: blur(6px); }
.fav-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-hi));
    box-shadow: 0 6px 16px -6px var(--glow);
}
.fav-name {
    font-size: .72rem;
    font-weight: 600;
    color: var(--ink-soft);
    max-width: 82px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fav:hover .fav-name { color: var(--ink); }
.fav-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 1.3rem;
    height: 1.3rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    line-height: 1;
    font-size: .9rem;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.35);
    opacity: 0;
    transition: opacity .2s;
}
.fav:hover .fav-remove { opacity: 1; }

.bg-controls {
    position: fixed;
    bottom: 1.4rem;
    right: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    z-index: 10;
}
.bg-btn {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: #ffffff;
    color: #000000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .6);
    transition: background .2s, color .2s, transform .2s;
}
:root[data-theme="light"] .bg-btn {
    background: #000000;
    color: #ffffff;
    box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .4);
}
.bg-btn:hover { background: var(--accent); color: #fff; transform: translateY(-2px); }

dialog {
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 1.6rem;
    width: min(92vw, 440px);
    background: var(--card);
    color: var(--ink);
    box-shadow: 0 30px 70px -20px rgba(0,0,0,.7);
}
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(3px); }
.dialog-title {
    margin: 0 0 1.1rem;
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--ink);
}
.dialog-field { display: block; font-size: .8rem; font-weight: 700; margin-bottom: 1rem; color: var(--ink-soft); }
.dialog-field input {
    display: block;
    width: 100%;
    margin-top: .35rem;
    padding: .6rem .8rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    color: var(--ink);
    font-family: inherit;
    font-size: .95rem;
}
.dialog-field input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.dialog-hint { display: block; font-size: .78rem; color: var(--ink-soft); margin-bottom: 1.2rem; }
.dialog-hint code { background: var(--bg); padding: .1rem .4rem; border-radius: 6px; font-weight: 700; color: var(--accent); }
.dialog-error { margin: -0.4rem 0 1rem; font-size: .8rem; font-weight: 700; color: var(--accent); }
.dialog-error[hidden] { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.btn {
    padding: .6rem 1.3rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font-family: inherit;
    font-size: .88rem;
    font-weight: 700;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--accent-hi); opacity: 1; }

.dialog-subtitle {
    margin: 1.5rem 0 .6rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--ink);
}
.custom-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .45rem;
}
.custom-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .55rem .7rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--bg);
    font-size: .9rem;
}
.custom-name { font-weight: 700; color: var(--ink); }
.custom-empty { justify-content: center; opacity: .7; border-style: dashed; }
.custom-remove {
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}
.custom-remove:hover { background: var(--accent-hi); }

@media (max-width: 520px) {
    .sitename { font-size: 2.2rem; }
    .logo { width: 84px; height: 84px; }
    .bg-controls { right: 1rem; bottom: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
