:root {
  --accent: #a97800;
  --accent-dark: #765500;
  --link: #08c;
  --text: #333;
  --muted: #666;
  --line: #d6d6d6;
  --soft: #f5f5f5;
  --sidebar-width: 300px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  background: #fff;
  font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.markdown-preview {
  position: relative;
  width: 100%;
  min-height: 100vh;
  padding: 2em max(2em, calc(50% - 457px + 2em));
  transition: left .2s ease, width .2s ease;
}
.markdown-preview::before {
  content: "";
  display: block;
  height: 5px;
  margin: -2em 0 1.6em;
  background: var(--accent);
}

h1, h2, h3, h4, h5, h6 { color: #000; line-height: 1.25; margin: 1.1em 0 16px; }
h1 { padding-bottom: .3em; font-size: 2.25em; }
h2 { padding-bottom: .3em; border-bottom: 1px solid #ececec; font-size: 1.75em; }
h3 { font-size: 1.45em; }
h4 { font-size: 1.2em; }
.markdown-preview h1:not(:first-of-type) { padding-bottom: .3em; border-bottom: 1px solid #ececec; font-size: 1.75em; }
p, ol, ul, pre, blockquote, table { margin-top: 0; margin-bottom: 16px; }
ol, ul { padding-left: 2em; }
a { color: var(--link); text-decoration: none; }
a:hover { color: #00a3f5; text-decoration: underline; }
strong { color: #000; }
.markdown-preview img {
  display: block;
  width: auto;
  max-width: min(100%, 960px);
  height: auto;
  margin: 1.25em auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}
hr { height: 4px; margin: 32px 0; border: 0; background: var(--line); }
blockquote { margin-inline: 0; padding: 8px 15px; color: #555; background: #f0f0f0; border-left: 4px solid var(--accent); }
blockquote > :last-child { margin-bottom: 0; }
code { padding: .15em .35em; color: #111; background: #f0f0f0; border-radius: 3px; font-family: Consolas, "Liberation Mono", Menlo, monospace; font-size: .88em; }
pre { padding: 1em; overflow: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 3px; line-height: 1.45; }
pre code { padding: 0; background: transparent; font-size: .9em; }
table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; }
th, td { padding: 7px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #000; background: #f2f2f2; white-space: nowrap; }
tbody tr:nth-child(even) { background: #fafafa; }
.mermaid { margin: 1.2em 0 2em; padding: 1em; overflow-x: auto; text-align: center; border: 1px solid #e5e5e5; background: #fffdf7; }
.loading, .render-error { margin-top: 3em; padding: 1em; background: var(--soft); border-left: 4px solid var(--accent); }
.render-error { color: #9b1c1c; }
.render-warning { padding: .8em 1em; color: #6b4b00; background: #fff8e1; border-left: 4px solid var(--accent); }

.md-sidebar-toc {
  position: fixed;
  z-index: 80;
  top: 0;
  left: 0;
  display: none;
  width: var(--sidebar-width);
  height: 100vh;
  padding: 22px 14px 50px;
  overflow-y: auto;
  background: #fff;
  box-shadow: 0 0 5px rgba(0,0,0,.2);
  font-size: 14px;
}
body[html-show-sidebar-toc] .md-sidebar-toc { display: block; }
body[html-show-sidebar-toc] .markdown-preview { left: var(--sidebar-width); width: calc(100% - var(--sidebar-width)); padding-inline: max(2em, calc(50% - 457px - var(--sidebar-width) / 2)); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 5px 16px; border-bottom: 1px solid var(--line); }
.sidebar-brand img { width: 38px; height: 38px; }
.sidebar-brand .brand-mark { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; color: #fff; background: var(--accent); border-radius: 7px; font-weight: 700; letter-spacing: -.04em; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand small { color: var(--muted); }
.md-toc { padding: 12px 3px; }
.md-toc a { display: block; padding: 3px 6px; color: #444; border-left: 2px solid transparent; }
.md-toc a:hover, .md-toc a.active { color: var(--accent-dark); background: #fff9e9; border-left-color: var(--accent); text-decoration: none; }
.md-toc .toc-h1, .md-toc .toc-h2 { margin-top: 4px; font-weight: 600; }
.md-toc .toc-h3 { padding-left: 20px; color: #666; font-size: 13px; }
#sidebar-toc-btn, #back-to-top {
  position: fixed;
  z-index: 99;
  bottom: 10px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  cursor: pointer;
  font: 700 25px/1 Arial, sans-serif;
  text-decoration: none;
}
#sidebar-toc-btn { left: 10px; }
#back-to-top { right: 10px; font-size: 20px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#back-to-top.visible { opacity: .8; pointer-events: auto; }
.noscript { position: fixed; inset: auto 1em 1em; z-index: 120; padding: 1em; background: #fff3cd; border: 1px solid #d39e00; }

@media (max-width: 1274px) {
  body[html-show-sidebar-toc] .markdown-preview { padding: 2em; }
}
@media (max-width: 760px) {
  .markdown-preview, body[html-show-sidebar-toc] .markdown-preview { left: 0; width: 100%; padding: 1.3em; }
  .markdown-preview::before { margin: -1.3em 0 1.2em; }
  .md-sidebar-toc { width: min(88vw, var(--sidebar-width)); }
  body[html-show-sidebar-toc]::after { content: ""; position: fixed; z-index: 70; inset: 0; background: rgba(0,0,0,.25); }
  h1 { font-size: 1.85em; }
  h2 { font-size: 1.5em; }
  table { font-size: 14px; }
}
@media print {
  .markdown-preview, body[html-show-sidebar-toc] .markdown-preview { left: 0; width: 100%; padding: 0; }
  .markdown-preview::before, .md-sidebar-toc, #sidebar-toc-btn, #back-to-top { display: none !important; }
  pre, table, .mermaid { break-inside: avoid; }
}
