/* Character Archive: components on top of Tailwind's utilities. */

:root {
    --bg: #0a0a0d;
    --surface: #111117;
    --card: #15151c;
    --raised: #1c1c25;
    --border: #272731;
    --border-strong: #34343f;
    --text: #e7e7ee;
    --muted: #9a9aa8;
    --faint: #6b6b78;
    --accent: #8b5cf6;
    --accent-soft: #a78bfa;
    --accent-text: #ddd6fe;
    --exclude: #f87171;
    --header-height: 4rem;
}

html { scrollbar-gutter: stable; }
body {
    background: var(--bg);
    color: var(--text);
}
[hidden] { display: none !important; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #45454f; }

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

.gradient-text {
    background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 50%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ---- Inputs and buttons ---------------------------------------------- */

.field {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.5rem 0.75rem;
    color: var(--text);
    font-size: 0.875rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field::placeholder { color: var(--faint); }
.field:hover { border-color: var(--border-strong); }
.field:focus {
    outline: none;
    border-color: rgba(139, 92, 246, 0.7);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
.field.is-invalid { border-color: rgba(248, 113, 113, 0.7); }

.search-field {
    font-size: 1rem;
    padding: 0.7rem 0.9rem 0.7rem 2.6rem;
    border-radius: 0.8rem;
    background: var(--surface);
}
textarea.search-field {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
    max-height: 9.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 0.6rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--raised); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn[aria-pressed="true"], .btn[aria-expanded="true"] {
    border-color: rgba(139, 92, 246, 0.6);
    background: rgba(139, 92, 246, 0.16);
    color: var(--accent-text);
}
.btn-primary {
    border-color: transparent;
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    color: #fff;
    font-weight: 600;
}
.btn-primary:hover {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    border-color: transparent;
}
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; border-radius: 0.5rem; }
.btn-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.btn-icon { padding: 0.5rem; }

.link {
    color: var(--accent-soft);
    cursor: pointer;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    text-align: left;
}
.link:hover { color: var(--accent-text); text-decoration: underline; }

/* ---- Sidebar ---------------------------------------------------------- */

.sidebar-section + .sidebar-section {
    border-top: 1px solid var(--border);
    margin-top: 1.1rem;
    padding-top: 1.1rem;
}
.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.55rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.hint { font-size: 0.75rem; color: var(--faint); line-height: 1.4; }
.hint code, .syntax-help code, .query-preview {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    padding: 0 0.3rem;
    color: var(--accent-text);
    font-size: 0.78rem;
    white-space: nowrap;
}
.query-preview { white-space: pre-wrap; }

.source-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.28rem 0.4rem;
    margin: 0 -0.4rem;
    border-radius: 0.45rem;
    font-size: 0.875rem;
    cursor: pointer;
    color: var(--text);
}
.source-row:hover { background: var(--raised); }
.source-row input { accent-color: var(--accent); width: 0.95rem; height: 0.95rem; cursor: pointer; }
.source-row .count { margin-left: auto; color: var(--faint); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* Toggle chips ("Search in") and segmented controls */
.chip {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.chip:hover { border-color: rgba(139, 92, 246, 0.45); color: var(--text); }
.chip[aria-pressed="true"] {
    border-color: rgba(139, 92, 246, 0.6);
    background: rgba(139, 92, 246, 0.18);
    color: var(--accent-text);
}
.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    font-size: 0.78rem;
}
.segmented button {
    padding: 0.22rem 0.65rem;
    color: var(--muted);
    background: var(--bg);
    cursor: pointer;
    border: 0;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: rgba(139, 92, 246, 0.2); color: var(--accent-text); }

/* Tags: selected filters, suggestions, card tags */
.tag {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    border-radius: 999px;
    font-size: 0.75rem;
    line-height: 1.2;
    overflow: hidden;
}
.tag > button, .tag > span {
    padding: 0.22rem 0.55rem;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tag > button:hover { color: var(--accent-text); background: rgba(139, 92, 246, 0.14); }
.tag > button.tag-minus, .tag > button.tag-remove {
    padding-left: 0.4rem;
    padding-right: 0.5rem;
    border-left: 1px solid var(--border);
    flex: none;
}
.tag > button.tag-minus:hover { color: #fecaca; background: rgba(248, 113, 113, 0.16); }
.tag.is-include { border-color: rgba(139, 92, 246, 0.55); background: rgba(139, 92, 246, 0.16); color: var(--accent-text); }
.tag.is-exclude { border-color: rgba(248, 113, 113, 0.5); background: rgba(248, 113, 113, 0.12); color: #fecaca; }
.tag.is-exclude > button:hover { background: rgba(248, 113, 113, 0.2); color: #fff; }
.tag.is-neutral { border-color: var(--border-strong); background: var(--raised); color: var(--text); }
.tag.is-include > button.tag-remove, .tag.is-exclude > button.tag-remove, .tag.is-neutral > button.tag-remove {
    border-left-color: rgba(255, 255, 255, 0.12);
}

/* Autocomplete */
.suggest { position: relative; }
.suggest-list {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: 17rem;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--border-strong);
    border-radius: 0.6rem;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    padding: 0.25rem;
}
.suggest-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 0.4rem;
    font-size: 0.85rem;
    color: var(--text);
}
.suggest-option .pick {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    text-align: left;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
}
.suggest-option .pick .value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-option .pick .count { margin-left: auto; color: var(--faint); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.suggest-option .minus {
    flex: none;
    width: 1.6rem;
    height: 1.6rem;
    margin-right: 0.2rem;
    border-radius: 0.35rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
}
.suggest-option .minus:hover { color: #fecaca; border-color: rgba(248, 113, 113, 0.5); background: rgba(248, 113, 113, 0.14); }
.suggest-option:hover, .suggest-option.is-active { background: var(--raised); }
.suggest-option mark { background: none; color: var(--accent-soft); font-weight: 600; }
.suggest-empty { padding: 0.5rem 0.6rem; font-size: 0.8rem; color: var(--faint); }

/* ---- Advanced query panel -------------------------------------------- */

.syntax-help dt { color: var(--text); }
.syntax-help dd { color: var(--muted); }
.query-preview {
    display: inline-block;
    max-width: 100%;
    padding: 0.2rem 0.5rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---- Results ----------------------------------------------------------- */

.results-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
}
@media (min-width: 640px) {
    .results-grid { gap: 1.25rem; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); }
}

.card {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    animation: rise 0.3s ease-out both;
}
.card:hover, .card:focus-within {
    transform: translateY(-3px);
    border-color: rgba(139, 92, 246, 0.45);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 18px rgba(139, 92, 246, 0.1);
}
.card-open {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    text-align: left;
    cursor: pointer;
}
.card-image {
    position: relative;
    aspect-ratio: 3 / 4;
    background: var(--surface);
    overflow: hidden;
}
.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}
.card:hover .card-image img { transform: scale(1.04); }
.image-missing {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3d3d49;
    font-size: 2.5rem;
    background: var(--surface);
}
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: rgba(10, 10, 13, 0.85);
    border: 1px solid var(--border);
    color: #d4d4dc;
    backdrop-filter: blur(4px);
}
.badge-accent { background: rgba(139, 92, 246, 0.16); border-color: rgba(139, 92, 246, 0.3); color: var(--accent-text); }

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.skeleton {
    background: linear-gradient(90deg, #15151c 25%, #1e1e27 50%, #15151c 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.page-button {
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.6rem;
    border-radius: 0.55rem;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}
.page-button:hover:not(:disabled) { background: var(--raised); border-color: rgba(139, 92, 246, 0.4); }
.page-button:disabled { opacity: 0.35; cursor: not-allowed; }
.page-button[aria-current="page"] {
    background: rgba(139, 92, 246, 0.22);
    border-color: rgba(139, 92, 246, 0.6);
    color: var(--accent-text);
    font-weight: 600;
}

.notice {
    border: 1px solid var(--border-strong);
    background: var(--card);
    border-radius: 0.8rem;
    padding: 0.9rem 1.1rem;
    font-size: 0.9rem;
    color: var(--text);
}
.notice-error { border-color: rgba(248, 113, 113, 0.45); background: rgba(248, 113, 113, 0.08); color: #fecaca; }
.notice-warning { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.07); color: #fde68a; }
.notice code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 0.35rem;
    padding: 0.1rem 0.4rem;
    font-size: 0.82rem;
    user-select: all;
}

/* ---- Card details ----------------------------------------------------- */

.modal-backdrop { animation: fade 0.2s ease-out both; }
.modal-panel { animation: pop 0.22s ease-out both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.detail-section {
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: rgba(10, 10, 13, 0.5);
}
.detail-section > summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #d4d4dc;
    list-style: none;
    user-select: none;
}
.detail-section > summary::-webkit-details-marker { display: none; }
.detail-section > summary::before {
    content: '';
    width: 0.4rem;
    height: 0.4rem;
    border-right: 2px solid var(--accent-soft);
    border-bottom: 2px solid var(--accent-soft);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    flex: none;
}
.detail-section[open] > summary::before { transform: rotate(45deg); }
.detail-section > summary .size { margin-left: auto; font-weight: 400; font-size: 0.75rem; color: var(--faint); }
.detail-text {
    padding: 0 0.85rem 0.85rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #cfcfd8;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.detail-text.is-collapsed {
    max-height: 13rem;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent);
    mask-image: linear-gradient(to bottom, #000 70%, transparent);
}

/* ---- Small screens: the sidebar becomes a drawer ---------------------- */

@media (max-width: 1023px) {
    #sidebar {
        position: fixed;
        z-index: 60;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(21rem, 88vw);
        background: var(--surface);
        border-right: 1px solid var(--border);
        transform: translateX(-102%);
        transition: transform 0.22s ease;
        padding: 1rem;
    }
    #sidebar.is-open { transform: translateX(0); box-shadow: 0 0 60px rgba(0, 0, 0, 0.7); }
}
@media (min-width: 1024px) {
    #sidebar {
        position: sticky;
        top: var(--header-offset, var(--header-height));
        max-height: calc(100vh - var(--header-offset, var(--header-height)));
    }
}

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