:root, html[data-theme="light"] {
  --bg: #f6f5fb;
  --panel: #ffffff;
  --text: #1c1a24;
  --muted: #6b6680;
  --border: #e4e0ef;
  --accent: #6d4aff;
  --accent-soft: #efe9ff;
  --sidebar: #f3f0fa;
  --sidebar-text: #2a2640;
  --sidebar-muted: #7a7490;
  --code-bg: #efeaf8;
  --th-bg: #f3f0fa;
  --shadow: 0 10px 28px rgba(40, 30, 70, 0.08);
  --code-font: "Cascadia Code", "Cascadia Mono", Consolas, "Courier New", monospace;
}
html[data-theme="dark"] {
  --bg: #121118;
  --panel: #1b1a22;
  --text: #eceaf4;
  --muted: #9a96ad;
  --border: #2e2c3a;
  --accent: #a78bfa;
  --accent-soft: #2a2440;
  --sidebar: #16151c;
  --sidebar-text: #e8e6f2;
  --sidebar-muted: #8e8aa0;
  --code-bg: #22212c;
  --th-bg: #22212c;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 18px 14px 40px;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar a { color: var(--sidebar-text); text-decoration: none; }
.brand {
  font-weight: 650;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--sidebar-text);
}
.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}
.side-nav { margin-top: 8px; }
.nav-group { margin: 16px 0 8px; font-size: 12px; color: var(--sidebar-muted); letter-spacing: .04em; font-weight: 600; }
.nav-link {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--sidebar-text);
}
.nav-link:hover { background: var(--accent-soft); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.ver-dd { position: relative; margin: 0 0 8px; }
.ver-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.ver-btn:hover { border-color: var(--accent); }
.ver-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ver-pill {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.ver-caret { opacity: .55; }
.ver-menu {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow: auto;
  padding: 6px;
}
.ver-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text) !important;
}
.ver-item:hover, .ver-item.is-on { background: var(--accent-soft); }
.ver-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--border); flex-shrink: 0;
}
.ver-item.is-on .ver-dot { border-color: var(--accent); background: var(--accent); }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar form { flex: 1; max-width: 480px; }
.topbar input[type="search"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}
.topbar-brand {
  display: none;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  text-decoration: none;
  color: var(--text);
  font-weight: 650;
  font-size: 14px;
}
.topbar-brand .brand-logo { width: 28px; height: 28px; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.menu-btn:hover { border-color: var(--accent); color: var(--accent); }
.menu-btn .ico-close { display: none; }
body.nav-open .menu-btn .ico-menu { display: none; }
body.nav-open .menu-btn .ico-close { display: block; }
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(20, 16, 32, 0.42);
}
.accent-dd { position: relative; }
.accent-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.accent-swatch {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent-swatch, var(--accent));
  border: 1px solid rgba(0,0,0,.18);
}
.accent-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  max-height: 360px;
  overflow: auto;
}
.accent-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
}
.accent-item:hover, .accent-item.is-on { background: var(--accent-soft); }
.accent-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15); flex-shrink: 0;
}
.accent-name { letter-spacing: .02em; }
.lang-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  gap: 2px;
}
.lang-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.lang-btn.is-on {
  background: var(--accent-soft);
  color: var(--accent);
}
.theme-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  gap: 2px;
}
.theme-btn {
  width: 32px; height: 32px;
  border: 0; padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-btn.is-on {
  background: var(--accent-soft);
  color: var(--accent);
}

.content { max-width: 820px; padding: 28px 32px 80px; }
.content a { color: var(--accent); }
.content h1 { font-size: 32px; line-height: 1.25; margin: 0 0 12px; }
.content h2 { font-size: 22px; margin: 32px 0 10px; }
.content h3 { font-size: 17px; margin: 22px 0 8px; }
.content p { margin: 10px 0; }
.content ul, .content ol { padding-left: 1.3em; }
.content code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.content pre {
  background: #1e1e22;
  color: #e8e8e4;
  padding: 14px 16px;
  border-radius: 10px;
  overflow: auto;
  font-family: var(--code-font);
}
.content pre code { background: none; color: inherit; padding: 0; }
.code-block {
  margin: 14px 0;
  border-radius: 10px;
  overflow: hidden;
  background: #1e1e22;
  color: #e8e8e4;
  font-size: 13px;
  font-family: var(--code-font);
}
.code-block pre, .code-block code { font-family: var(--code-font); }
.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #2a2a30;
  font-size: 12px;
  color: #9a9aa3;
}
.code-copy {
  border: 0;
  background: transparent;
  color: #d0d0d6;
  cursor: pointer;
  font-size: 12px;
}
.code-copy:hover { color: #fff; }
.code-body { display: flex; overflow: auto; }
.code-body pre {
  margin: 0;
  border-radius: 0;
  background: transparent;
  padding: 10px 12px 14px;
}
.code-nos {
  flex: 0 0 auto;
  min-width: 2.4em;
  text-align: right;
  color: #6a6a74;
  user-select: none;
  padding-right: 10px !important;
  border-right: 1px solid #33333a;
}
.code-body pre + pre { flex: 1; min-width: 0; }
.tok-kw { color: #d67ad4; }
.tok-fn { color: #56c2c8; }
.tok-cmt { color: #8b7aa8; }
.tok-str { color: #98c379; }
.tok-pp { color: #d19a66; }
.tok-num { color: #d19a66; }
.ruidocs-table-wrap { overflow: auto; margin: 14px 0; }
.content table { width: 100%; border-collapse: collapse; font-size: 14px; }
.content th, .content td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.content th { background: var(--th-bg); }
.content img { max-width: 100%; height: auto; border-radius: 8px; margin: 10px 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin: 22px 0; }
.card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
  color: inherit;
}
.card:hover { border-color: var(--accent); }
.card h3 { margin: 0 0 6px; font-size: 16px; color: var(--accent); }
.card p { margin: 0; color: var(--muted); font-size: 13px; }

.ruidocs-video { position: relative; padding-top: 56.25%; margin: 18px 0; border-radius: 10px; overflow: hidden; background: #000; }
.ruidocs-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.flash { padding: 10px 12px; border-radius: 8px; margin: 0 0 16px; }
.flash-ok { background: #e8f6ec; }
.flash-err { background: #fdecea; }

.admin-wrap h1 .ver, .brand .ver {
  font-weight: 400;
  font-size: 14px;
  color: var(--muted);
  margin-left: 8px;
}
.login-box { max-width: 360px; margin: 64px auto; padding: 0 16px 40px; }
.login-box h1 { font-size: 22px; margin: 0 0 16px; }
.login-box label { display: block; margin: 12px 0 6px; font-size: 14px; }
.login-box input[type="text"], .login-box input[type="password"] {
  width: 100%; max-width: 360px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-turnstile { display: flex; justify-content: center; margin: 16px 0 0; }
.login-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.admin-wrap { max-width: 960px; margin: 24px auto; padding: 0 16px 40px; }
.admin-toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.admin-group-filter { font-size: 14px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.admin-group-filter select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff;
}
.admin-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-user { color: var(--muted); font-size: 13px; margin-left: auto; }
.editor-bar .editor-bar-end { margin-left: auto; }
.editor-bar .admin-user { margin-left: 0; white-space: nowrap; }
.admin-wrap table { width: 100%; border-collapse: collapse; background: #fff; }
.admin-wrap th, .admin-wrap td { border: 1px solid var(--border); padding: 8px; font-size: 13px; }
.admin-wrap th.col-order, .admin-wrap td.col-order { width: 72px; text-align: center; }
.admin-wrap input[type="text"], .admin-wrap input[type="password"] {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
}
.admin-wrap input[type="number"] {
  width: 64px; padding: 6px 6px; border: 1px solid var(--border); border-radius: 6px; text-align: center;
}
.admin-wrap .btn { padding: 5px 12px; font-size: 13px; }
.admin-wrap .btn-icon { width: 40px; height: 36px; padding: 0; }
.admin-wrap .btn-icon svg { width: 22px; height: 22px; }
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
}

.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: #444;
}
.btn-icon svg { display: block; }
.btn-publish { background: #e67700; }
.btn-danger { background: #c0392b; }
.col-actions { white-space: nowrap; }
.col-actions .btn { margin-right: 4px; }
.md-tools { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.md-tools button { min-width: 36px; padding: 6px 10px; }
.status-pill {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #eee; color: var(--muted);
}
.status-pill.live { background: #e8f6ec; color: #1b7f3a; }
.status-pill.draft { background: #fff4e0; color: #9a5b00; }
html.editor-html, html.editor-html body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
.editor-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}
.editor-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.editor-bar input[type="text"], .editor-bar select, .editor-bar input[type="number"] {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.editor-bar .grow { flex: 1; min-width: 120px; }
.editor-split {
  flex: 1 1 auto;
  height: 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
}
.editor-pane {
  min-width: 160px;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.editor-pane-left { flex: 0 0 50%; }
.editor-pane-right { flex: 1 1 auto; }
.editor-meta-lang { gap: 12px; }
.editor-meta-lang label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 180px;
  font-size: 12px;
  color: var(--muted);
}
.editor-meta-lang label .grow { flex: 1; }
.md-tools-hint { font-size: 12px; color: var(--muted); margin-left: 8px; }
.md-tools #btnFull { margin-left: auto; }
.md-tools .fs-only { display: none; }
.editor-shell:fullscreen .md-tools .fs-only,
.editor-shell:-webkit-full-screen .md-tools .fs-only,
.editor-shell.is-fs-fake .md-tools .fs-only,
.editor-shell.is-fs .md-tools .fs-only { display: inline-block; }
.editor-shell:fullscreen,
.editor-shell:-webkit-full-screen,
.editor-shell.is-fs-fake {
  width: 100%;
  height: 100%;
  background: #fff;
}
.editor-shell.is-fs-fake {
  position: fixed;
  inset: 0;
  z-index: 80;
  height: 100vh;
}
.editor-shell:fullscreen .editor-chrome,
.editor-shell:-webkit-full-screen .editor-chrome,
.editor-shell.is-fs-fake .editor-chrome,
.editor-shell.is-fs .editor-chrome {
  display: none;
}
.editor-lang-stack {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.editor-lang-block {
  flex: 1 1 50%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
}
.editor-lang-block:last-child { border-bottom: 0; }
.editor-pane h2 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.editor-pane h2 .preview-lang { margin-left: auto; }
.editor-gutter {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 2;
}
.editor-gutter:hover, .editor-gutter.dragging { background: var(--accent); }
.editor-gutter::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  right: -4px;
}
.editor-pane h2 {
  flex: 0 0 auto;
  margin: 0;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #f3f2ec;
}
.editor-pane textarea {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: 100%;
  border: 0;
  resize: none;
  padding: 14px;
  font-family: var(--code-font);
  font-size: 14px;
  line-height: 1.55;
  outline: none;
}
.editor-preview {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px 22px;
  background: var(--bg);
}
.editor-preview.content { max-width: none; padding: 16px 22px; }

@media (max-width: 860px) {
  .layout { display: block; }
  .topbar {
    padding: 10px 12px;
    gap: 14px 10px;
    flex-wrap: wrap;
    align-items: center;
  }
  .topbar-brand {
    display: inline-flex;
    order: 1;
    min-width: 0;
    min-height: 40px;
    padding-right: 48px;
  }
  .topbar-brand span {
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .menu-btn {
    display: inline-flex;
    order: 2;
    margin-left: auto;
    position: fixed;
    top: 10px;
    right: max(12px, env(safe-area-inset-right));
    z-index: 60;
  }
  .topbar form {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
  }
  .topbar-tools {
    order: 4;
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
    gap: 6px;
    position: relative;
  }
  .accent-dd { position: static; }
  .accent-menu {
    right: 0;
    left: auto;
    width: min(240px, calc(100vw - 24px));
    max-height: min(360px, 70vh);
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(300px, 86vw);
    height: 100%;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  body.nav-open { overflow: hidden; }
  body.nav-open .back-to-top { display: none !important; }
  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }
  body.nav-open .nav-backdrop {
    display: block;
  }
  .content { padding: 20px 16px 60px; }
  .content h1 { font-size: 26px; }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 28px;
  z-index: 40;
  width: 44px;
  height: 44px;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(20, 20, 20, 0.18);
  cursor: pointer;
}
.back-to-top.is-on { display: inline-flex; }
.back-to-top:hover { filter: brightness(1.08); }
.back-to-top svg { display: block; }
