/* ── Explanation panel (principles of each demo) ─── */

.explain {
    --ex-bg: #161b22;
    --ex-bg-2: #0d1117;
    --ex-line: #30363d;
    --ex-text: #c9d1d9;
    --ex-muted: #8b949e;
    --ex-strong: #e6edf3;
    --ex-accent: #f0883e;
    --ex-js: #e3b341;
    --ex-rust: #f0883e;
    --ex-gpu: #a371f7;

    max-width: 820px;
    margin: 2.5rem auto 3rem auto;
    background: var(--ex-bg);
    border: 1px solid var(--ex-line);
    border-radius: 10px;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--ex-text);
    overflow: hidden;
}

/* Header bar */
.explain summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.5rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: linear-gradient(90deg, rgba(240, 136, 62, 0.12), transparent 70%);
    border-bottom: 1px solid transparent;
}
.explain summary::-webkit-details-marker { display: none; }
.explain[open] summary { border-bottom-color: var(--ex-line); }
@media (hover: hover) {
    .explain summary:hover .explain-title { color: #ffa657; }
}
.explain summary:focus-visible { outline: 2px solid #58a6ff; outline-offset: -2px; }

.explain-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ex-accent);
    letter-spacing: 0.02em;
}

.explain-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--ex-muted);
}
.explain-toggle::before { content: '展开'; }
.explain[open] .explain-toggle::before { content: '收起'; }
.explain-toggle::after {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.2s ease;
}
.explain[open] .explain-toggle::after { transform: rotate(225deg) translateY(-2px); }

.explain > :not(summary) { margin-left: 1.5rem; margin-right: 1.5rem; }

/* Lead paragraph */
.explain-lead {
    margin-top: 1.25rem;
    padding: 0.2rem 0 0.2rem 1rem;
    border-left: 3px solid var(--ex-accent);
    font-size: 0.97rem;
    color: var(--ex-strong);
}

/* Sections */
.explain-sec { margin-top: 1.6rem; }

.explain h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed var(--ex-line);
    font-size: 0.98rem;
    color: var(--ex-strong);
}
.explain-ico { font-size: 1rem; line-height: 1; }

.explain strong { color: var(--ex-strong); }
.explain a { color: #58a6ff; text-decoration: none; }
@media (hover: hover) {
    .explain a:hover { text-decoration: underline; }
}

.explain code {
    padding: 1px 6px;
    border-radius: 4px;
    background: #21262d;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.82rem;
    color: #ffa657;
    white-space: nowrap;
}

/* Formula block */
.explain-formula {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    column-gap: 1.25rem;
    margin: 0 0 1rem;
    padding: 0.85rem 1rem;
    background: var(--ex-bg-2);
    border: 1px solid var(--ex-line);
    border-radius: 8px;
    font-family: 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif;
    font-size: 1.25rem;
    color: var(--ex-strong);
    text-align: center;
    overflow-x: auto;
}
.explain-formula-note {
    font-family: inherit;
    font-size: 0.8rem;
    font-style: normal;
    color: var(--ex-muted);
}
.explain-formula .explain-formula-note { font-family: 'Segoe UI', system-ui, sans-serif; }

/* Term / definition list */
.explain-terms { margin: 0; }
.explain-terms dt {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.8rem;
    font-weight: 600;
    color: var(--ex-strong);
}
.explain-terms dt:first-child { margin-top: 0; }
.explain-terms dt::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ex-accent);
    flex: none;
}
.explain-terms dd {
    margin: 0.15rem 0 0 calc(6px + 0.45rem);
    color: var(--ex-text);
}

.explain-note {
    margin-top: 0.8rem;
    padding: 0.55rem 0.9rem;
    border-radius: 6px;
    background: rgba(56, 139, 253, 0.08);
    border: 1px solid rgba(56, 139, 253, 0.25);
    font-size: 0.85rem;
}

/* Step flow (JS ↔ Rust pipeline) */
.explain-flow {
    list-style: none;
    counter-reset: step;
    margin: 0;
    padding: 0;
}
.explain-flow li {
    position: relative;
    counter-increment: step;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0 0 0.9rem 2.4rem;
}
.explain-flow li:last-child { padding-bottom: 0; }
.explain-flow li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 0.1rem;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    border: 2px solid var(--ex-accent);
    background: var(--ex-bg);
    color: var(--ex-accent);
    font-size: 0.8rem;
    font-weight: 700;
    line-height: calc(1.6rem - 4px);
    text-align: center;
    z-index: 1;
}
.explain-flow li:not(:last-child)::after {
    content: '';
    position: absolute;
    left: calc(0.8rem - 1px);
    top: 1.8rem;
    bottom: 0.1rem;
    width: 2px;
    background: var(--ex-line);
}

.explain-actor {
    flex: none;
    min-width: 3rem;
    margin-top: 0.2rem;
    padding: 0 0.4rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.4rem;
    text-align: center;
    border: 1px solid currentColor;
}
.explain-actor.js   { color: var(--ex-js);   background: rgba(227, 179, 65, 0.1); }
.explain-actor.rust { color: var(--ex-rust); background: rgba(240, 136, 62, 0.1); }
.explain-actor.gpu  { color: var(--ex-gpu);  background: rgba(163, 113, 247, 0.1); }
.explain-terms dt .explain-actor { margin-top: 0; }

/* Performance callout */
.explain-perf {
    padding: 0.9rem 1.1rem 0.6rem;
    border-radius: 8px;
    background: rgba(240, 136, 62, 0.06);
    border: 1px solid rgba(240, 136, 62, 0.25);
}
.explain-perf h3 { border-bottom-color: rgba(240, 136, 62, 0.25); }
.explain-perf ul { padding-left: 1.2rem; }
.explain-perf li { margin-bottom: 0.35rem; }
.explain-perf li::marker { color: var(--ex-accent); }

/* Home page: two pattern cards */
.explain-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.9rem;
}
.explain-card {
    padding: 0.8rem 1rem;
    border-radius: 8px;
    background: var(--ex-bg-2);
    border: 1px solid var(--ex-line);
}
.explain-card h4 {
    margin-bottom: 0.3rem;
    font-size: 0.92rem;
    color: var(--ex-accent);
}
.explain-card p { font-size: 0.85rem; }
.explain-card p:first-of-type { color: var(--ex-muted); font-size: 0.8rem; }

/* Source footer */
.explain-src {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.4rem;
    margin-bottom: 1.2rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--ex-line);
    font-size: 0.8rem;
    color: var(--ex-muted);
}
.explain-src > span:first-child { margin-right: 0.2rem; }
.explain .explain-chip {
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--ex-line);
    background: var(--ex-bg-2);
    color: #79c0ff;
    font-size: 0.76rem;
}
.explain-src-note { color: var(--ex-muted); }
.explain-src-note::before { content: '（'; }
.explain-src-note::after { content: '）'; }

@media (max-width: 600px) {
    .explain { font-size: 0.86rem; }
    .explain summary { padding: 0.8rem 1rem; }
    .explain > :not(summary) { margin-left: 1rem; margin-right: 1rem; }
    .explain-perf { padding: 0.8rem 0.9rem 0.5rem; }
    .explain-flow li { flex-direction: column; gap: 0.2rem; }
    .explain code { white-space: normal; word-break: break-all; }
}

@media (prefers-reduced-motion: reduce) {
    .explain-toggle::after { transition: none; }
}

/* Inline math with Greek letters (monospace fonts make θ look like 0) */
.explain-math {
    padding: 0 4px;
    border-radius: 4px;
    background: #21262d;
    font-family: 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif;
    font-size: 0.95rem;
    color: #ffa657;
    white-space: nowrap;
}
