:root, [data-theme="light"] {
    --code-bg:              #f6f8fa;
    --code-border:          #e2e6ea;
    --callout-bg:           #f0f5ff;
    --callout-border:       rgba(0, 123, 255, 0.3);
    --callout-warn-bg:      #fffbeb;
    --callout-warn-border:  rgba(234, 179, 8, 0.4);
    --callout-danger-bg:    #fff1f1;
    --callout-danger-border: rgba(239, 68, 68, 0.4);
}

[data-theme="dark"] {
    --code-bg:              #161b22;
    --code-border:          #2a2d35;
    --callout-bg:           #0d1a2e;
    --callout-border:       rgba(0, 123, 255, 0.3);
    --callout-warn-bg:      #1a1500;
    --callout-warn-border:  rgba(234, 179, 8, 0.3);
    --callout-danger-bg:    #1a0505;
    --callout-danger-border: rgba(239, 68, 68, 0.3);
}

.panel-right {
    padding: 40px 52px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Back link ── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s;
    margin-bottom: 4px;
}

.back-link:hover { color: var(--blue); }

/* ── Project header ── */
.proj-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 24px;
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.proj-title {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.proj-subtitle {
    font-size: 0.95rem;
    color: var(--muted);
    line-height: 1.5;
}

.proj-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.proj-date {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.05em;
}

.proj-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.proj-preface {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 8px;
}

.proj-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.proj-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.proj-link-btn:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-tint);
}

/* ── Containers ── */
.proj-container {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg);
    transition: border-color 0.18s, box-shadow 0.18s, background 0.25s;
}

.proj-container:hover {
    border-color: var(--card-hover-border);
    box-shadow: 0 4px 18px var(--card-hover-shadow);
}

.proj-container-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    gap: 12px;
}

.proj-container-header h3 {
    font-size: 1rem;
    font-weight: 600;
    border-left: 3px solid var(--blue);
    padding-left: 10px;
    transition: border-color 0.25s;
}

.proj-container-body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.28s cubic-bezier(.22,.68,0,1.1),
                opacity 0.22s ease;
    opacity: 1;
}

.proj-container-body.collapsed {
    grid-template-rows: 0fr;
    opacity: 0;
}

.proj-container-body-inner {
    overflow: hidden;
    padding: 0 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Typography ── */
p {
    color: var(--p-color);
    font-size: 0.9rem;
    line-height: 1.8;
    transition: color 0.25s;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    border-left: 3px solid var(--blue);
    padding-left: 10px;
    margin-top: 4px;
}

.section-heading {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    border-left: 3px solid var(--blue);
    padding-left: 10px;
    margin-top: 4px;
}

.section-subheading {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    padding-left: 10px;
    margin-top: 2px;
}

/* ── Inline code ── */
code.inline {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.82em;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--text);
    transition: background 0.25s, border-color 0.25s;
}

/* ── Code blocks ── */
pre {
    border-radius: 10px;
    border: 1px solid var(--code-border);
    overflow-x: auto;
    font-size: 0.82rem;
    line-height: 1.6;
    transition: border-color 0.25s;
}

pre code.hljs {
    border-radius: 10px;
    background: var(--code-bg) !important;
    padding: 16px 20px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ── Callouts ── */
.callout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--callout-border);
    background: var(--callout-bg);
    font-size: 0.85rem;
    color: var(--p-color);
    line-height: 1.6;
    transition: background 0.25s, border-color 0.25s;
}

.callout i { color: var(--blue); flex-shrink: 0; line-height: 1; font-size: 1rem; }

.callout.callout-warn {
    background: var(--callout-warn-bg);
    border-color: var(--callout-warn-border);
}

.callout.callout-warn i { color: #ca8a04; }

.callout.callout-danger {
    background: var(--callout-danger-bg);
    border-color: var(--callout-danger-border);
}

.callout.callout-danger i { color: #dc2626; }

/* ── Images ── */
.img-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.img-block img {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: block;
    transition: border-color 0.25s;
}

.img-block.img-small img { max-width: 50%; }
.img-block.img-full  img { max-width: 100%; }

.img-caption {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.68rem;
    color: var(--muted);
    letter-spacing: 0.03em;
}

.img-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ── Terminal block ── */
.terminal-block {
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #2a2d35;
}

.terminal-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    background: #21262d;
    border-bottom: 1px solid #2a2d35;
}

.terminal-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.terminal-dot.td-red    { background: #ff5f57; }
.terminal-dot.td-yellow { background: #febc2e; }
.terminal-dot.td-green  { background: #28c840; }

.terminal-body {
    margin: 0;
    padding: 14px 18px;
    background: #0d1117;
    color: #c9d1d9;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    border: none !important;
    border-radius: 0 !important;
    overflow-x: auto;
    white-space: pre;
}

.terminal-body code {
    background: none !important;
    border: none !important;
    padding: 0;
    font-size: inherit;
    color: inherit;
    font-family: inherit;
    border-radius: 0;
}

/* ── Terminal split panes ── */
.terminal-split {
    display: flex;
    flex-direction: row;
}

.terminal-pane {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.terminal-pane + .terminal-pane {
    border-left: 1px solid #2a2d35;
}

.terminal-pane .terminal-body {
    flex: 1;
}

.terminal-title {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.72rem;
    color: #8b949e;
    margin-left: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Terminal text colors ── */
.tc-red     { color: #ff6b6b; }
.tc-green   { color: #6bde7a; }
.tc-yellow  { color: #febc2e; }
.tc-blue    { color: #79c0ff; }
.tc-cyan    { color: #56d4dd; }
.tc-magenta { color: #d2a8ff; }
.tc-orange  { color: #ffa657; }
.tc-white   { color: #f0f6fc; }
.tc-dim     { color: #6e7681; }
.tc-bold    { font-weight: 700; color: inherit; }

/* ── Mermaid diagrams ── */
.mermaid-wrap {
    display: flex;
    justify-content: center;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow-x: auto;
    transition: border-color 0.25s, background 0.25s;
}

.mermaid-wrap pre.mermaid {
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
}

.mermaid-wrap pre.mermaid svg {
    max-width: 100%;
    height: auto;
}

/* ── Details / spoiler ── */
.proj-details {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.18s;
}

.proj-details[open] { border-color: var(--blue); }

.proj-details-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    list-style: none;
    user-select: none;
    transition: background 0.15s;
}

.proj-details-summary::-webkit-details-marker { display: none; }
.proj-details-summary::marker { display: none; }

.proj-details-summary:hover { background: var(--surface); }

.proj-details-summary::before {
    content: '';
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 6px solid var(--muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

details.proj-details[open] .proj-details-summary::before {
    transform: rotate(90deg);
}

.proj-details-body {
    padding: 14px 20px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.25s;
}

/* ── File tree ── */
.filetree {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    background: var(--surface);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.82rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: border-color 0.25s, background 0.25s;
}

.ft-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding-left: calc(var(--depth) * 18px);
    line-height: 1.7;
}

.ft-row i { font-size: 0.88rem; flex-shrink: 0; }
.ft-dir > i  { color: var(--blue); }
.ft-file > i { color: var(--muted); }
.ft-dir  .ft-name { color: var(--text); font-weight: 500; }
.ft-file .ft-name { color: var(--p-color); }

/* ── KaTeX math ── */
.math-block {
    overflow-x: auto;
    padding: 10px 0;
    text-align: center;
    color: var(--text);
}

.math-inline {
    color: var(--text);
}

[data-theme="dark"] .math-block .katex,
[data-theme="dark"] .math-inline .katex {
    color: var(--text);
    --katex-color: var(--text);
}

/* ── Hover tooltips ── */
.tooltip-wrap {
    border-bottom: 1.5px dashed var(--muted);
    cursor: help;
    color: inherit;
}

/* Single shared element appended to <body> by JS */
.tooltip-box {
    position: fixed;
    max-width: 200px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 0.72rem;
    line-height: 1.55;
    padding: 7px 11px;
    border-radius: 7px;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    transition: opacity 0.15s ease, background 0.25s, border-color 0.25s;
    z-index: 1000;
}

/* Border triangle */
.tooltip-box::before {
    content: '';
    position: absolute;
    top: 100%;
    left: var(--caret-left, 50%);
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-top-color: var(--border);
    transition: border-color 0.25s;
}

/* Fill triangle */
.tooltip-box::after {
    content: '';
    position: absolute;
    top: calc(100% - 1.5px);
    left: var(--caret-left, 50%);
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--surface);
    transition: border-color 0.25s;
}

/* ── Responsive ── */
@media (max-width: 700px) {
    .panel-right { padding: 28px 18px; }
    .img-row { grid-template-columns: 1fr; }
    .terminal-split { flex-direction: column; }
    .terminal-pane + .terminal-pane {
        border-left: none;
        border-top: 1px solid #2a2d35;
    }
}
