/* Markdown in assistant replies (markdown.js, md-*). Load order matters: later files override earlier ones. */
/* ==========================================================================
   Rendered replies live in .md-body (assistant messages only; user messages stay plain text).
   - Headings are shifted down visually (# looks like a section title, never bigger than the page title).
   - Tables scroll inside .md-table-wrap; code scrolls inside its own box; the page never scrolls sideways.
   - Colors come from the existing --fg-* tokens, so body.dark follows automatically. No inline styles anywhere.
   ========================================================================== */
.cumi-home .message .md-body { min-width:0; font-size:15px; line-height:1.75; color:var(--fg-text); overflow-wrap:anywhere; }
.cumi-home .message .md-body > :first-child { margin-top:0; }
.cumi-home .message .md-body > :last-child { margin-bottom:0; }
.cumi-home .message .md-body p { margin:0 0 .8em; white-space:normal; }
.cumi-home .message .md-body p.md-plain { white-space:pre-wrap; }
.cumi-home .message .md-body p.md-raw { padding:6px 10px; border-radius:8px; background:var(--fg-soft); font:13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space:normal; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { margin:1.2em 0 .5em; line-height:1.4; letter-spacing:0; color:var(--fg-text); font-weight:650; }
.md-body h1 { font-size:20px; }
.md-body h2 { font-size:18px; }
.md-body h3 { font-size:16px; }
.md-body h4, .md-body h5, .md-body h6 { font-size:15px; }
.md-body ul, .md-body ol { margin:0 0 .8em; padding-left:1.6em; }
.md-body li { margin:.2em 0; }
.md-body li > ul, .md-body li > ol { margin:.2em 0 0; }
.md-body li > p { margin:0 0 .4em; }
.md-body .md-task { display:inline-block; width:1.4em; color:var(--fg-muted); }
.md-body li:has(> .md-task:first-child), .md-body li:has(> p:first-child > .md-task:first-child) { list-style:none; margin-left:-1.2em; }
.md-body blockquote { margin:0 0 .8em; padding:2px 0 2px 14px; border-left:3px solid var(--fg-line); color:var(--fg-muted); }
.md-body hr { margin:1.2em 0; border:0; border-top:1px solid var(--fg-line); }
.md-body strong { font-weight:650; }
.md-body del { color:var(--fg-muted); }

/* Links: always a new tab; external ones carry a visible arrow; removed (unsafe) URLs are plain text. */
.md-body a { color:var(--fg-accent); text-decoration:underline; text-underline-offset:3px; overflow-wrap:anywhere; }
.md-body a.md-ext::after { content:"↗" / "（外部連結）"; display:inline-block; margin-left:2px; font-size:.8em; text-decoration:none; }
.md-body a.md-nolink { color:inherit; text-decoration:none; cursor:text; }

/* Inline code and code blocks (no syntax highlighting in M1). */
.md-body code { padding:1px 5px; border-radius:5px; background:var(--fg-soft); font:.88em/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap:anywhere; }
.md-body .md-code { margin:0 0 .9em; border:1px solid var(--fg-line); border-radius:10px; overflow:hidden; background:var(--fg-surface); }
.md-body .md-code-head { display:flex; align-items:center; justify-content:space-between; gap:8px; min-height:32px; padding:2px 6px 2px 12px; background:var(--fg-soft); color:var(--fg-muted); font-size:12px; line-height:1.4; }
.md-body .md-code-lang { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.md-body .md-copy { flex:none; min-height:26px; padding:0 10px; border:1px solid transparent; border-radius:6px; background:transparent; color:var(--fg-accent); font-size:12px; letter-spacing:0; }
.md-body .md-copy:hover { border-color:var(--fg-line); background:var(--fg-surface); }
.md-body .md-code pre { margin:0; padding:12px 14px; background:transparent; overflow-x:auto; white-space:pre; overflow-wrap:normal; font:13px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.md-body .md-code pre code { padding:0; border-radius:0; background:transparent; font:inherit; white-space:inherit; overflow-wrap:normal; }

/* Tables: scroll sideways inside the wrapper; cells keep a readable minimum width. */
.md-body .md-table-wrap { max-width:100%; margin:0 0 .9em; overflow-x:auto; border:1px solid var(--fg-line); border-radius:10px; }
.md-body .md-table-wrap:focus-visible { outline:2px solid var(--fg-accent); outline-offset:2px; }
.md-body table { width:auto; min-width:100%; margin:0; border-collapse:collapse; font-size:14px; line-height:1.6; text-align:left; }
.md-body th, .md-body td { min-width:8em; max-width:28em; height:auto; padding:8px 12px; border-bottom:1px solid var(--fg-line); vertical-align:top; white-space:normal; overflow-wrap:break-word; }
.md-body th { position:static; background:var(--fg-soft); color:var(--fg-text); font-weight:650; }
.md-body tbody tr:nth-child(even) td { background:color-mix(in srgb, var(--fg-soft) 55%, transparent); }
.md-body tbody tr:hover { background:transparent; }
.md-body tr:last-child td { border-bottom:0; }
/* Short cells (≤ 8 characters) and short numbers never wrap (markdown.js adds md-nowrap); wide tables scroll inside the box instead of
   squeezing CJK columns to one character per line. */
.md-body th.md-nowrap, .md-body td.md-nowrap { white-space:nowrap; }
.md-body td.md-nowrap { font-variant-numeric:tabular-nums; }
.md-body .md-align-left { text-align:left; }
.md-body .md-align-center { text-align:center; }
.md-body .md-align-right { text-align:right; }

/* 複製 Markdown in the message footer uses the footer's text-button look (50-home). */
.md-copy-buffer { position:fixed; top:0; left:0; width:1px; height:1px; padding:0; border:0; opacity:0; pointer-events:none; }
.modal .md-copy-manual { display:block; width:100%; min-height:240px; font:13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width:700px) {
  .cumi-home .message .md-body { font-size:15px; }
  .md-body th, .md-body td { min-width:7em; padding:7px 10px; }
  .md-body .md-code pre { padding:10px 12px; font-size:12.5px; }
}
/* Diagrams (diagram.js): the rendered SVG replaces the code until 「原始碼」 is pressed. */
.md-body .md-code.md-diagram-on pre { display:none; }
.md-body .md-code.md-diagram-on.md-diagram-source pre { display:block; }
.md-body .md-code.md-diagram-on.md-diagram-source img.md-diagram { display:none; }
.md-body img.md-diagram { display:block; max-width:100%; width:auto; height:auto; margin:0 auto; padding:16px; box-sizing:border-box; }
.md-body .md-code.md-diagram-on { background:var(--fg-surface); }
.md-body .md-code-head .md-diagram-toggle { margin-left:auto; }
.md-diagram-renderer { position:absolute; left:-12000px; top:0; width:1120px; height:40px; border:0; visibility:hidden; pointer-events:none; }

