/* ================================================
   ENCYCLAUPEDIA — DARK THEME
   ================================================ */

:root {
    --bg:          #0d1117;
    --bg-card:     #161b22;
    --bg-hover:    #1c2128;
    --bg-elevated: #21262d;
    --border:      #21262d;
    --border-2:    #30363d;
    --text:        #e6edf3;
    --text-2:      #8b949e;
    --text-3:      #484f58;

    --accent:       #f0845c;
    --accent-dim:   rgba(240, 132, 92, 0.12);
    --accent-ring:  rgba(240, 132, 92, 0.25);

    /* Category palette */
    --c-claude:     #e07645;
    --c-skills:     #58a6ff;
    --c-local:      #3fb950;
    --c-frameworks: #bc8cff;
    --c-tips:       #e3b341;
    --c-tools:      #f85149;

    --radius:    10px;
    --radius-sm: 6px;

    --header-height: 56px;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ─── HEADER ──────────────────────────────────── */
header {
    position: sticky;
    top: 0;
    z-index: 200;
    min-height: var(--header-height);
    background: rgba(13, 17, 23, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    min-height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
    text-decoration: none;
}

.logo-mark {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.logo-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.logo-sep,
.logo-sub {
    color: var(--text-3);
    font-size: 14px;
}

/* Search */
.search-box {
    flex: 1;
    max-width: 520px;
    min-width: 220px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    width: 14px;
    height: 14px;
    color: var(--text-3);
    pointer-events: none;
}

#search {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    padding: 7px 14px 7px 32px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

#search::placeholder { color: var(--text-3); }

.header-right { margin-left: auto; flex-shrink: 0; }

.stat-pill {
    font-size: 12px;
    color: var(--text-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-2);
    padding: 3px 12px;
    border-radius: 20px;
    white-space: nowrap;
}

/* ─── APP LAYOUT ─────────────────────────────── */
.app-layout {
    display: flex;
    max-width: 1440px;
    margin: 0 auto;
    min-height: calc(100vh - var(--header-height));
}

/* ─── SIDEBAR ────────────────────────────────── */
.sidebar {
    width: 228px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-elevated) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

.sidebar-inner { padding: 18px 10px; }

.sidebar-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-3);
    padding: 0 8px;
    margin-bottom: 6px;
}

#category-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 20px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    color: var(--text-2);
    font-size: 14px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    user-select: none;
}

.nav-item:hover { background: var(--bg-elevated); color: var(--text); }

.nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 500;
}

.nav-icon { font-size: 16px; flex-shrink: 0; line-height: 1; }
.nav-label { flex: 1; white-space: nowrap; }

.nav-count {
    font-size: 11px;
    color: var(--text-3);
    background: var(--bg);
    border: 1px solid var(--border-2);
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

.nav-item.active .nav-count {
    border-color: rgba(240,132,92,0.4);
    color: var(--accent);
}

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

/* Tag filters */
.tag-filter-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 4px;
}

.filter-tag {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 5px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-2);
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.12s;
    user-select: none;
}

.filter-tag:hover { border-color: var(--accent); color: var(--text); }

.filter-tag.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* ─── MAIN CONTENT ───────────────────────────── */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 28px 28px 56px;
}

.content-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.ch-text h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 3px;
    line-height: 1.3;
}

.ch-text p {
    font-size: 13px;
    color: var(--text-2);
}

.results-count {
    font-size: 12px;
    color: var(--text-3);
    white-space: nowrap;
}

/* ─── CARDS GRID ─────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(295px, 1fr));
    gap: 14px;
}

/* ─── CARD ───────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color 0.18s, background 0.18s, transform 0.15s, box-shadow 0.18s;
    animation: cardIn 0.22s ease both;
}

.card:hover {
    border-color: var(--border-2);
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Card top */
.card-top {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.card-emoji {
    font-size: 26px;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 3px;
}

.card-heading { flex: 1; min-width: 0; }

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.35;
    margin-bottom: 5px;
}

/* Category badges */
.cat-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 7px;
    border-radius: 4px;
}

.cat-claude-code  { background: rgba(224,118, 69,.15); color: var(--c-claude); }
.cat-skills       { background: rgba( 88,166,255,.12); color: var(--c-skills); }
.cat-local-ai     { background: rgba( 63,185, 80,.12); color: var(--c-local); }
.cat-frameworks   { background: rgba(188,140,255,.12); color: var(--c-frameworks); }
.cat-tips         { background: rgba(227,179, 65,.12); color: var(--c-tips); }
.cat-tools        { background: rgba(248, 81, 73,.12); color: var(--c-tools); }

/* Description */
.card-desc {
    font-size: 13px;
    color: var(--text-2);
    line-height: 1.6;
    flex: 1;
}

.card-desc strong { color: var(--text); font-weight: 600; }
.card-desc code {
    font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
    font-size: 12px;
    background: var(--bg-elevated);
    padding: 1px 5px;
    border-radius: 3px;
    color: #adbac7;
}

/* Code block */
.card-code-wrap {
    position: relative;
}

.card-code {
    background: #0a0e14;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    padding: 10px 13px;
    font-family: ui-monospace, 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 11.5px;
    color: #adbac7;
    overflow-x: auto;
    white-space: pre;
    line-height: 1.6;
}

.copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-2);
    border-radius: 4px;
    color: var(--text-2);
    font-size: 11px;
    padding: 2px 8px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
}

.card-code-wrap:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); background: var(--border-2); }
.copy-btn.copied { color: var(--c-local); border-color: var(--c-local); }

/* Tags */
.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.tag {
    font-size: 11px;
    color: var(--text-3);
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.12s;
    user-select: none;
}

.tag:hover {
    color: var(--text-2);
    border-color: var(--border-2);
}

/* Card footer */
.card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    margin-top: 2px;
}

.card-link {
    font-size: 12px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: opacity 0.12s;
}

.card-link:hover { opacity: 0.75; text-decoration: underline; }

.card-type {
    font-size: 10px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── EMPTY STATE ────────────────────────────── */
.empty-state {
    grid-column: 1 / -1;
    padding: 72px 24px;
    text-align: center;
}

.empty-icon { font-size: 40px; margin-bottom: 16px; }

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-2);
}

/* ─── FOOTER ─────────────────────────────────── */
footer {
    border-top: 1px solid var(--border);
    padding: 20px;
}

.footer-inner {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-3);
    justify-content: center;
    flex-wrap: wrap;
}

.footer-inner a { color: var(--text-2); text-decoration: none; }
.footer-inner a:hover { color: var(--accent); }
.dot { color: var(--text-3); }

/* ─── RESPONSIVE ─────────────────────────────── */
@media (max-width: 960px) {
    :root { --header-height: 52px; }

    .header-inner {
        padding: 0 14px;
        gap: 12px;
    }

    .search-box { max-width: none; }

    .app-layout { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-inner { padding: 10px 12px; }

    #category-nav {
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: visible;
        gap: 6px;
        padding-bottom: 0;
        margin-bottom: 6px;
    }

    #category-nav::-webkit-scrollbar { display: none; }

    .nav-item {
        flex: 0 0 auto;
        width: auto;
        padding: 7px 10px;
    }
    .nav-count { display: none; }
    .sidebar-divider, .tag-filter-list,
    .sidebar-label:last-of-type { display: none; }

    .main-content { padding: 20px 16px 48px; }
    .cards-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
}

@media (max-width: 760px) {
    :root { --header-height: 94px; }

    header { position: sticky; }

    .header-inner {
        align-items: center;
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px 10px;
    }

    .logo {
        flex: 1;
        min-width: 0;
    }

    .logo-name {
        font-size: 15px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .search-box {
        order: 3;
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
    }

    #search {
        font-size: 13px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .header-right {
        margin-left: 0;
    }

    .main-content {
        padding: 16px 12px 42px;
    }

    .content-header {
        margin-bottom: 16px;
        gap: 8px;
    }

    .ch-text h1 {
        font-size: 18px;
    }

    .ch-text p {
        font-size: 12px;
    }

    .card {
        padding: 14px;
    }

    .card-top {
        gap: 10px;
    }

    .card-emoji {
        font-size: 22px;
    }

    .card-code {
        font-size: 11px;
        padding: 9px 11px;
    }

    .card-foot {
        gap: 8px;
    }

    .footer-inner {
        gap: 8px;
        font-size: 12px;
    }
}

@media (max-width: 580px) {
    .logo-sep, .logo-sub { display: none; }
    .header-right { display: none; }
    :root { --header-height: 92px; }

    .header-inner {
        padding-left: 10px;
        padding-right: 10px;
    }

    .logo-mark {
        width: 22px;
        height: 22px;
    }

    .logo-name {
        font-size: 14px;
    }

    .cards-grid { grid-template-columns: 1fr; }
    .content-header { align-items: flex-start; }

    .card-title {
        font-size: 13px;
    }

    .card-desc {
        font-size: 12px;
    }

    .empty-state {
        padding: 52px 14px;
    }
}

/* ─── SCROLLBAR (Webkit) ─────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }
