/* ============================================================
   MdGenr — 瑞士国际主义排版风 / 浅色超宽
   设计隐喻：Markdown 是结构化排版。瑞士网格 + 巨型编号
   + 红黑双色 + 大写字距标签。编辑器即排版车间。
   字体：Archivo Black（巨型展示）+ Sora（正文）
        + Fragment Mono（编辑器等宽）。
   ============================================================ */

:root {
  --paper: #f7f6f2;
  --paper-2: #eeede7;
  --card: #fffefb;
  --card-2: #f1f0ea;

  --ink: #16181d;             /* 瑞士墨黑 */
  --ink-soft: #4d525c;
  --ink-faint: #9aa0aa;

  --red: #d92b1c;             /* 瑞士红 */
  --red-deep: #b02012;
  --red-soft: rgba(217, 43, 28, .07);
  --red-line: rgba(217, 43, 28, .3);

  --line: #dedcd3;
  --line-2: #c9c6ba;

  --max-width: 1640px;
  --mono: "Fragment Mono", "SF Mono", Consolas, monospace;
  --sans: "Sora", "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  --display: "Archivo Black", "Sora", sans-serif;

  --shadow-sm: 0 1px 2px rgba(22, 24, 29, .05), 0 4px 12px rgba(22, 24, 29, .05);
  --shadow-md: 0 2px 6px rgba(22, 24, 29, .06), 0 18px 44px rgba(22, 24, 29, .1);
}

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

body {
  font-family: var(--sans);
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.6;
  background:
    radial-gradient(900px 400px at 100% 0%, rgba(217, 43, 28, .04), transparent 55%),
    var(--paper);
  min-height: 100vh;
}

::selection { background: var(--red); color: #fff; }

.wrap { max-width: var(--max-width); margin: 0 auto; padding: 0 26px; }

/* ============ 头部 ============ */
.site-head {
  background: rgba(247, 246, 242, .94);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--ink);
  position: sticky;
  top: 0;
  z-index: 50;
}
.head-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 26px;
  display: flex;
  align-items: center;
  gap: 26px;
  min-height: 62px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}
.brand-icon { width: 38px; height: 38px; display: block; }
.brand-text { font-family: var(--display); font-size: 20px; letter-spacing: .01em; white-space: nowrap; }
.brand-text em {
  font-style: normal; font-family: var(--sans); font-size: 11.5px; font-weight: 500;
  color: var(--ink-soft); letter-spacing: .1em; text-transform: uppercase; margin-left: 8px;
}
.head-nav { margin-left: auto; display: flex; gap: 22px; align-items: center; }
.head-nav a {
  text-decoration: none; color: var(--ink-soft); font-size: 13px; font-weight: 500;
  letter-spacing: .04em; text-transform: uppercase;
  padding: 6px 2px; border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.head-nav a:hover { color: var(--red); border-color: var(--red); }

.menu-btn {
  display: none; margin-left: auto;
  width: 42px; height: 42px;
  border: 2px solid var(--ink); border-radius: 8px;
  background: var(--card); cursor: pointer;
  flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.menu-btn span { display: block; width: 17px; height: 2px; background: var(--ink); }

/* ============ Hero（极简一行） ============ */
.hero { padding: 22px 0 4px; display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap; }
.hero h1 {
  font-family: var(--display);
  font-size: clamp(22px, 2.6vw, 30px);
  letter-spacing: -.005em;
  line-height: 1.1;
  text-transform: uppercase;
}
.hero h1 .accent { color: var(--red); }
.hero .hero-no {
  font-family: var(--mono); font-size: 12px; color: var(--ink-faint); letter-spacing: .14em;
}

/* ============ 工具区 ============ */
.desk { padding: 16px 0 10px; }

.desk-grid {
  display: grid;
  grid-template-columns: 220px 1fr 1fr;
  gap: 14px;
  align-items: stretch;
}

/* ---------- TOC 侧栏 ---------- */
.toc-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--red);
  border-radius: 4px;
  padding: 14px 12px;
  min-height: 560px;
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}
.toc-label {
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .24em;
  color: var(--ink); margin: 2px 4px 12px;
  display: flex; align-items: center; gap: 8px;
}
.toc-label .no {
  color: var(--red); font-size: 13px;
}
.toc-list { display: flex; flex-direction: column; gap: 1px; }
.toc-link {
  display: block; text-decoration: none;
  color: var(--ink-soft); font-size: 12.5px; line-height: 1.45;
  padding: 5px 8px; border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  transition: all .12s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-link:hover { color: var(--ink); background: var(--card-2); }
.toc-link.active { color: var(--red); border-left-color: var(--red); background: var(--red-soft); font-weight: 600; }
.toc-l1 { font-weight: 600; color: var(--ink); }
.toc-l2 { padding-left: 18px; }
.toc-l3 { padding-left: 30px; font-size: 12px; }
.toc-l4, .toc-l5, .toc-l6 { padding-left: 40px; font-size: 11.5px; color: var(--ink-faint); }
.toc-empty {
  color: var(--ink-faint); font-size: 12px; font-family: var(--mono);
  padding: 4px 8px; list-style: none;
}

/* ---------- 编辑/预览双栏 ---------- */
.pane {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 560px;
  max-height: calc(100vh - 210px);
}
.pane-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
  flex-wrap: wrap;
}
.pane-tag {
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .2em; color: var(--ink);
  display: inline-flex; align-items: baseline; gap: 6px;
}
.pane-tag .no { color: var(--red); font-size: 12px; }
.pane-tools { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.tool-btn {
  appearance: none;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--ink-soft); background: var(--card);
  border: 1px solid var(--line-2); border-radius: 5px;
  padding: 4px 8px; min-height: 30px; cursor: pointer;
  transition: all .12s;
}
.tool-btn:hover { color: var(--red); border-color: var(--red); }
.tool-btn.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

#editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: none; outline: none;
  background: var(--card);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.85;
  padding: 16px 18px;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  overflow-y: auto;
}
#editor:focus { background: #fff; }

#preview {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 40px;
  background: var(--card);
}

/* ---------- 预览排版（瑞士文档风） ---------- */
#preview h1, #preview h2, #preview h3, #preview h4, #preview h5, #preview h6 {
  font-family: var(--sans); font-weight: 700; line-height: 1.25;
  margin: 1.5em 0 .5em; color: var(--ink);
}
#preview h1 { font-size: 1.7em; border-bottom: 2.5px solid var(--red); padding-bottom: .3em; text-transform: none; }
#preview h2 { font-size: 1.35em; border-bottom: 1.5px solid var(--line-2); padding-bottom: .22em; }
#preview h3 { font-size: 1.15em; }
#preview h4 { font-size: 1em; }
#preview p { margin: .7em 0; }
#preview a { color: #2244cc; text-decoration: none; border-bottom: 1.5px solid rgba(34, 68, 204, .35); }
#preview a:hover { color: var(--red); border-bottom-color: var(--red); }
#preview code {
  font-family: var(--mono); font-size: .86em;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 3px; padding: .08em .35em;
}
#preview pre {
  background: #1c1f26; border-radius: 6px;
  padding: 14px 16px; overflow-x: auto; line-height: 1.65;
  margin: 1em 0;
}
#preview pre code { background: none; border: none; padding: 0; color: #e8e6df; font-size: .84em; }
#preview blockquote {
  margin: 1.1em 0; padding: .1em 1.1em;
  border-left: 4px solid var(--red); background: var(--red-soft); color: var(--ink-soft);
}
#preview table { border-collapse: collapse; width: 100%; margin: 1.3em 0; font-size: .92em; }
#preview th, #preview td { border: 1px solid var(--line-2); padding: 7px 11px; text-align: left; }
#preview th { background: var(--card-2); font-weight: 700; font-size: .85em; text-transform: uppercase; letter-spacing: .05em; }
#preview tr:nth-child(even) td { background: var(--paper); }
#preview img { max-width: 100%; border-radius: 4px; }
#preview hr { border: none; border-top: 2px solid var(--red); margin: 2.2em 0; }
#preview ul, #preview ol { padding-left: 1.5em; margin: .6em 0; }
#preview li { margin: .25em 0; }
#preview .task-list-item { list-style: none; margin-left: -1.3em; }
#preview input[type=checkbox] { margin-right: .5em; accent-color: var(--red); }
#preview del { color: var(--ink-faint); }
#preview .mermaid { margin: 1.2em 0; text-align: center; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 14px; }

/* ---------- hljs 瑞士浅色主题 ---------- */
.hljs { color: #e8e6df; }
.hljs-comment, .hljs-quote { color: #7d8590; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-meta { color: #ff8f80; }
.hljs-string, .hljs-attr { color: #ffd479; }
.hljs-number, .hljs-literal { color: #8ce0b0; }
.hljs-title, .hljs-name, .hljs-function .hljs-title { color: #9ecbff; }
.hljs-built_in, .hljs-type { color: #c9a6ff; }
.hljs-params { color: #e8e6df; }
.hljs-variable, .hljs-template-variable { color: #ffb3a6; }

/* ---------- 底部操作条 ---------- */
.desk-foot {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 16px;
}
.stat-bar {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); letter-spacing: .04em;
}
.save-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--line-2); display: inline-block;
  transition: background .2s, box-shadow .2s;
  vertical-align: middle; margin-right: 2px;
}
.save-dot.on { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.save-label { font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .14em; }
.export-group { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.btn-export {
  appearance: none;
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: 5px;
  padding: 8px 16px; min-height: 40px; cursor: pointer;
  letter-spacing: .02em;
  transition: all .13s;
}
.btn-export:hover { background: var(--ink); color: var(--paper); }
.btn-export.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-export.primary:hover { background: var(--red-deep); border-color: var(--red-deep); }

/* ---------- 恢复横条 ---------- */
.restore-bar {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--ink); color: var(--paper);
  border-radius: 6px;
  padding: 12px 18px;
  box-shadow: var(--shadow-md);
  max-width: min(92vw, 640px);
}
.restore-bar[hidden] { display: none; }
.restore-bar .rb-text { font-size: 13.5px; }
.restore-bar .restore-time { font-family: var(--mono); color: #ffd479; }
.restore-bar button {
  appearance: none; font-family: var(--sans); font-size: 12.5px; font-weight: 700;
  border-radius: 4px; padding: 7px 14px; min-height: 36px; cursor: pointer;
  transition: all .13s;
}
.btn-restore { background: var(--red); color: #fff; border: none; }
.btn-restore:hover { background: var(--red-deep); }
.btn-discard { background: transparent; color: var(--paper); border: 1.5px solid rgba(247, 246, 242, .4); }
.btn-discard:hover { border-color: var(--paper); }

/* ============ 文档区 ============ */
.doc { padding: 46px 0 10px; }
.doc-sec { margin-top: 40px; }
.doc h2 {
  font-family: var(--display); font-size: 24px; margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: .005em;
}
.doc h2 .sec-no { color: var(--red); margin-right: 10px; }
.doc .lead { color: var(--ink-soft); font-size: 14.5px; max-width: 720px; margin-bottom: 20px; }
.doc-rule { height: 4px; width: 56px; margin: 10px 0 12px; background: var(--red); }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.info-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 4px;
  padding: 18px; box-shadow: var(--shadow-sm);
}
.info-card .ic-no { font-family: var(--display); font-size: 26px; color: var(--red); line-height: 1; }
.info-card h3 { font-size: 15.5px; font-weight: 700; margin: 10px 0 6px; }
.info-card p { font-size: 13.5px; color: var(--ink-soft); }

.cheat-table {
  width: 100%; border-collapse: collapse;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 4px; overflow: hidden; box-shadow: var(--shadow-sm);
  font-size: 14px;
}
.cheat-table th {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink); text-align: left; padding: 10px 14px;
  background: var(--card-2); border-bottom: 2px solid var(--ink);
}
.cheat-table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cheat-table tr:last-child td { border-bottom: none; }
.cheat-table code {
  font-family: var(--mono); font-size: 12.5px; color: var(--red-deep);
  background: var(--red-soft); border-radius: 3px; padding: 2px 7px; white-space: nowrap;
}
.cheat-table td:last-child { color: var(--ink-soft); font-size: 13.5px; }

.faq-list { display: flex; flex-direction: column; gap: 10px; }
details.faq {
  background: var(--card); border: 1px solid var(--line); border-radius: 4px;
}
details.faq summary {
  list-style: none; cursor: pointer; padding: 14px 16px;
  font-weight: 600; font-size: 14.5px;
  display: flex; align-items: center; gap: 12px;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::before {
  content: 'Q'; font-family: var(--display); color: var(--red); font-size: 15px; flex-shrink: 0;
}
details.faq summary::after {
  content: '+'; margin-left: auto; font-family: var(--mono); color: var(--ink-faint);
  font-size: 17px; transition: transform .18s;
}
details.faq[open] summary::after { transform: rotate(45deg); }
details.faq .faq-a { padding: 0 16px 14px 43px; color: var(--ink-soft); font-size: 13.5px; }
details.faq .faq-a code {
  font-family: var(--mono); font-size: 12px; background: var(--paper-2);
  border-radius: 3px; padding: 1px 6px;
}

/* ============ 页脚 ============ */
.site-foot { margin-top: 64px; border-top: 2px solid var(--ink); background: var(--paper-2); }
.foot-inner {
  max-width: var(--max-width); margin: 0 auto;
  padding: 30px 26px 26px;
  display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 28px;
}
.foot-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.foot-brand img { width: 28px; height: 28px; }
.foot-brand span { font-family: var(--display); font-size: 17px; }
.site-foot p { font-size: 12.5px; color: var(--ink-soft); max-width: 380px; }
.foot-col h4 {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink); margin-bottom: 10px;
}
.foot-col a {
  display: block; text-decoration: none; color: var(--ink-soft);
  font-size: 13px; padding: 3px 0; transition: color .13s;
}
.foot-col a:hover { color: var(--red); }
.foot-base {
  border-top: 1px solid var(--line-2); padding: 12px 26px; text-align: center;
  font-size: 11.5px; color: var(--ink-faint); font-family: var(--mono);
}

/* ============ 移动端（7.8 规范） ============ */
@media (max-width: 1280px) {
  .desk-grid { grid-template-columns: 190px 1fr 1fr; }
}
@media (max-width: 1080px) {
  .desk-grid { grid-template-columns: 1fr 1fr; }
  .toc-panel { display: none; } /* 平板双栏优先 */
}
@media (max-width: 760px) {
  .wrap, .head-inner { padding-left: 14px; padding-right: 14px; }
  .head-inner { flex-wrap: wrap; min-height: 0; padding-top: 10px; padding-bottom: 10px; row-gap: 8px; }
  .brand-text { font-size: 17px; }
  .brand-text em { display: none; }

  .menu-btn { display: flex; }
  .head-inner:has(.menu-btn) .head-nav {
    display: none; order: 3; width: 100%;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--card); border: 1px solid var(--line);
    border-radius: 6px; padding: 8px; margin-top: 4px;
  }
  .head-inner:has(.menu-btn) .head-nav.open { display: flex; }
  .head-inner:has(.menu-btn) .head-nav a {
    padding: 11px 12px; border-bottom: none; border-radius: 4px;
    font-size: 13.5px; min-height: 44px; display: flex; align-items: center;
  }
  .head-inner:has(.menu-btn) .head-nav a:hover { background: var(--red-soft); }
  .head-inner:not(:has(.menu-btn)) .head-nav {
    display: flex; flex-wrap: wrap; gap: 8px 16px; margin-left: 0; width: 100%; order: 3;
  }
  .head-inner:not(:has(.menu-btn)) .head-nav a { font-size: 12px; }

  .hero { padding-top: 16px; }
  .hero h1 { font-size: 20px; }

  .desk-grid { grid-template-columns: 1fr; gap: 12px; }
  .pane, .toc-panel { min-height: 320px; max-height: none; }
  .pane-tools { margin-left: 0; width: 100%; }
  #editor { font-size: 13px; line-height: 1.7; padding: 12px 12px; }
  #preview { padding: 14px 14px 28px; }
  .export-group { margin-left: 0; width: 100%; }
  .btn-export { flex: 1; justify-content: center; padding: 10px 8px; }
  .grid-3 { grid-template-columns: 1fr; }
  .cheat-table { display: block; overflow-x: auto; }
  .foot-inner { grid-template-columns: 1fr; gap: 20px; }
  .restore-bar { left: 10px; right: 10px; transform: none; bottom: 12px; padding: 10px 12px; }
}

@media (hover: none) {
  .tool-btn { min-height: 36px; }
}
@media (max-width: 400px) {
  .btn-export { font-size: 12px; }
}
