/* ── Design System ───────────────────────────────────────────── */
:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-hover: #1a1a2e;
    --bg-input: #16161f;
    --border: #2a2a3e;
    --text: #e8e8f0;
    --text-dim: #8888a0;
    --text-muted: #555568;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --gradient: linear-gradient(135deg, #6c5ce7, #a29bfe, #74b9ff);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Noto Sans SC', 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
}

.logo-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    background: var(--accent);
    color: white;
    border-radius: 4px;
    letter-spacing: 1px;
}

.nav {
    display: flex;
    gap: 4px;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

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

.nav-btn.active {
    color: var(--accent-light);
    background: rgba(108, 92, 231, 0.15);
}

/* ── Views ───────────────────────────────────────────────── */
.view {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.view.active {
    display: block;
}

/* ── Hero / Search ───────────────────────────────────────── */
.hero {
    text-align: center;
    padding: 80px 0 40px;
}

.hero h1 {
    font-size: 40px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 12px;
}

.gradient-text {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-sub {
    color: var(--text-dim);
    font-size: 16px;
    margin-bottom: 40px;
}

.search-box {
    display: flex;
    align-items: center;
    max-width: 640px;
    margin: 0 auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 4px 4px 4px 20px;
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
    font-size: 18px;
    margin-right: 8px;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 16px;
    padding: 12px 0;
    min-width: 0;
}

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

.search-submit {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.search-submit:hover {
    background: #5a4bd4;
    transform: scale(1.02);
}

.quick-tags {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    align-items: center;
}

.tag-label {
    color: var(--text-muted);
    font-size: 13px;
}

.quick-tag {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
}

.quick-tag:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: rgba(108, 92, 231, 0.1);
}

/* ── Stats Bar ───────────────────────────────────────────── */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 20px 0;
    margin-bottom: 16px;
}

.stats-bar.hidden {
    display: none;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
}

.stat-chip .count {
    color: var(--accent-light);
    font-weight: 600;
}

/* ── Cross Hint ──────────────────────────────────────────── */
.cross-hint {
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.15), rgba(116, 185, 255, 0.1));
    border: 1px solid rgba(108, 92, 231, 0.3);
    border-radius: var(--radius);
    padding: 16px 24px;
    text-align: center;
    font-size: 15px;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

.cross-hint.hidden {
    display: none;
}

/* ── AI Panel ────────────────────────────────────────────── */
.ai-panel {
    margin-bottom: 24px;
}

.ai-panel.hidden {
    display: none;
}

.ai-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: var(--transition);
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.3);
}

.ai-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(108, 92, 231, 0.5);
}

.ai-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.ai-btn.loading .ai-sparkle {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.ai-result {
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.08), rgba(116, 185, 255, 0.05));
    border: 1px solid rgba(108, 92, 231, 0.25);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-top: 16px;
    animation: fadeIn 0.4s ease;
}

.ai-result.hidden {
    display: none;
}

.ai-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(108, 92, 231, 0.2);
    font-weight: 600;
    font-size: 15px;
}

.ai-model {
    font-size: 11px;
    color: var(--accent-light);
    background: rgba(108, 92, 231, 0.15);
    padding: 3px 10px;
    border-radius: 10px;
}

.ai-content {
    font-size: 14px;
    line-height: 1.9;
    color: var(--text);
    white-space: pre-wrap;
}

.ai-content .ai-source {
    color: var(--accent-light);
    font-size: 12px;
    display: block;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ── Subject Tabs ────────────────────────────────────────── */
.subject-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.subject-tabs.hidden {
    display: none;
}

.subject-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.subject-tab:hover {
    border-color: var(--accent);
}

.subject-tab.active {
    background: rgba(108, 92, 231, 0.15);
    border-color: var(--accent);
    color: var(--accent-light);
}

.tab-count {
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Results ─────────────────────────────────────────────── */
.results {
    padding-bottom: 80px;
}

.result-group {
    margin-bottom: 32px;
    animation: fadeIn 0.4s ease;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 600;
}

.group-icon {
    font-size: 22px;
}

.group-count {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 400;
}

.group-bar {
    flex: 1;
    height: 2px;
    border-radius: 1px;
    opacity: 0.3;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}

.result-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.result-title {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.result-snippet {
    font-size: 14px;
    line-height: 1.7;
    overflow: hidden;
    max-height: 4.2em;
    word-break: break-word;
    overflow-wrap: break-word;
}

.result-snippet mark {
    background: rgba(108, 92, 231, 0.3);
    color: var(--accent-light);
    border-radius: 2px;
    padding: 0 2px;
}

.result-text {
    display: none;
    font-size: 14px;
    color: var(--text-dim);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.result-card.expanded .result-text {
    display: block;
}

/* ── Graph ────────────────────────────────────────────────── */
.graph-header {
    text-align: center;
    padding: 40px 0 20px;
}

.graph-header h2 {
    font-size: 28px;
    font-weight: 700;
}

.graph-header p {
    color: var(--text-dim);
    margin-top: 8px;
}

.graph-container {
    width: 100%;
    height: calc(100vh - 200px);
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
}

.graph-container svg {
    width: 100%;
    height: 100%;
}

.graph-node {
    cursor: pointer;
}

.graph-label {
    fill: var(--text);
    font-size: 12px;
    pointer-events: none;
    text-anchor: middle;
}

/* ── About ───────────────────────────────────────────────── */
.about-content {
    max-width: 700px;
    margin: 0 auto;
    padding: 40px 0 80px;
}

.about-content h2 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 32px;
}

.about-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}

.about-card h3 {
    font-size: 18px;
    margin-bottom: 12px;
}

.about-card p {
    color: var(--text-dim);
    margin-bottom: 8px;
}

.about-card a {
    color: var(--accent-light);
    text-decoration: none;
}

.about-card a:hover {
    text-decoration: underline;
}

/* ── Footer ──────────────────────────────────────────────── */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 13px;
    border-top: 1px solid var(--border);
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    .hero h1 {
        font-size: 26px;
    }

    .hero {
        padding: 40px 0 20px;
    }

    .header-inner {
        padding: 0 16px;
    }

    .view {
        padding: 0 16px;
    }

    .search-box {
        border-radius: 12px;
    }
}