:root {
  --bg: #0e1116;
  --card: #171b22;
  --text: #edf2fa;
  --muted: #9aa6ba;
  --accent: #7aa2ff;
  --border: #2a323f;
  --header-bg: transparent;
}

body[data-theme='light'] {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1a2433;
  --muted: #6a768c;
  --accent: #406dff;
  --border: #dce3ef;
  --header-bg: rgba(255,255,255,0.7);
}

body[data-theme='light'] .card {
  background: #ffffff;
}

body[data-theme='light'] .post-link {
  color: #1c2f52;
}

body[data-theme='light'] .btn {
  background: #edf3ff;
  color: #1f2a3d;
}

body[data-theme='light'] .markdown-body {
  color: #27344d;
}

body[data-theme='light'] .markdown-body h1,
body[data-theme='light'] .markdown-body h2,
body[data-theme='light'] .markdown-body h3,
body[data-theme='light'] .markdown-body h4 {
  color: #13233d;
}

body[data-theme='light'] .markdown-body blockquote {
  background: #f2f6ff;
  color: #354968;
}

body[data-theme='light'] .markdown-body pre {
  background: #f5f8ff;
}

body[data-theme='light'] .index-panel {
  background: #f7faff;
}

body[data-theme='light'] .index-panel h3 {
  color: #465f87;
}

body[data-theme='light'] .chip {
  background: #eef3ff;
  color: #38527c;
}

body[data-theme='light'] .chip.active {
  background: #2f73ff;
  border-color: #2f73ff;
  color: #fff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 95%, #000 5%), var(--bg));
  color: var(--text);
}
.container { width: min(1100px, 94vw); margin: 0 auto; }
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 22px 0 20px;
  background: var(--header-bg);
}

.header-banner {
  width: 100%;
  max-height: 170px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 14px;
}

.site-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.site-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.site-nav-inline {
  display: flex;
  align-items: center;
  gap: 12px;
}

.site-header h1 { margin: 0 0 8px; }
.site-header p { margin: 0 0 12px; color: var(--muted); }
.site-header nav a {
  color: var(--accent);
  text-decoration: none;
  margin-right: 14px;
}

.site-nav-inline a {
  margin-right: 0;
  font-size: 15px;
}

.theme-toggle-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  vertical-align: middle;
  flex: 0 0 34px;
}

.theme-icon {
  font-size: 18px;
  line-height: 1;
}
.main-layout {
  padding: 22px 0 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

.content-column {
  display: grid;
  gap: 16px;
}

.card {
  background: color-mix(in srgb, var(--card) 90%, black 10%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li { padding: 14px 0 16px; border-bottom: 1px dashed var(--border); }
.post-list li:last-child { border-bottom: none; }
.post-list-featured { margin-bottom: 10px; }
.post-list-featured li { padding: 10px 0; }
.post-link { color: #dce6ff; text-decoration: none; font-size: 22px; line-height: 1.35; font-weight: 700; }
.post-summary {
  color: color-mix(in srgb, var(--text) 78%, var(--muted) 22%);
  font-size: 14px;
  line-height: 1.65;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-meta { color: var(--muted); font-size: 12px; margin-top: 8px; }
.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  background: #17233f;
  color: var(--text);
  cursor: pointer;
}
.hidden { display: none; }
.markdown-body {
  font-size: 17px;
  line-height: 1.95;
  color: #e7edff;
  width: 100%;
  overflow-x: hidden;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.4em 0 0.6em;
  line-height: 1.35;
  color: #f2f6ff;
}

.markdown-body h1 {
  font-size: 32px;
}

.markdown-body h2 {
  font-size: 24px;
  padding-bottom: 0.2em;
  border-bottom: 1px solid rgba(110, 168, 255, 0.25);
}

.markdown-body h3 {
  font-size: 20px;
}

.markdown-body p {
  margin: 0 0 1.05em;
  letter-spacing: 0.15px;
}

.markdown-body ul,
.markdown-body ol {
  line-height: 1.9;
  padding-left: 1.5em;
  margin: 0.5em 0 1em;
}

.markdown-body li {
  margin-bottom: 0.45em;
}

.markdown-body blockquote {
  margin: 1.15em 0;
  padding: 0.75em 1em;
  border-left: 3px solid var(--accent);
  background: #0f1a31;
  color: #d7e4ff;
  border-radius: 8px;
}

.markdown-body pre {
  background: #0c1324;
  border: 1px solid var(--border);
  padding: 14px;
  overflow: auto;
  border-radius: 10px;
  line-height: 1.7;
  margin: 0.9em 0 1.1em;
}

.markdown-body code {
  font-family: Consolas, Menlo, monospace;
}

.markdown-body :not(pre) > code {
  background: rgba(110, 168, 255, 0.16);
  border: 1px solid rgba(110, 168, 255, 0.28);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.9em;
}

.markdown-body a {
  color: #86b6ff;
  text-decoration: none;
  border-bottom: 1px dashed rgba(134, 182, 255, 0.5);
}

.markdown-body a:hover {
  color: #a7cbff;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.8em 0 1.1em;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.md-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: clamp(12px, 0.72vw, 14px);
  line-height: 1.5;
}

.md-table thead th {
  position: sticky;
  top: 0;
  background: #13203a;
  color: #dfe9ff;
  font-weight: 700;
}

.md-table th,
.md-table td {
  border-bottom: 1px solid var(--border);
  padding: clamp(6px, 0.55vw, 9px) clamp(8px, 0.65vw, 12px);
  text-align: left;
  vertical-align: top;
}

.md-table tbody tr:nth-child(2n) {
  background: rgba(134, 182, 255, 0.04);
}

/* 1920x1080 及常见桌面分辨率下的表格列宽约束 */
@media (min-width: 1366px) {
  .md-table th:nth-child(1),
  .md-table td:nth-child(1) { width: 20%; }

  .md-table th:nth-child(2),
  .md-table td:nth-child(2) { width: 8%; }

  .md-table th:nth-child(3),
  .md-table td:nth-child(3) { width: 25%; }

  .md-table th:nth-child(4),
  .md-table td:nth-child(4) { width: 25%; }

  .md-table th:nth-child(5),
  .md-table td:nth-child(5) { width: 10%; }

  .md-table th:nth-child(6),
  .md-table td:nth-child(6) { width: 12%; }
}

/* 超长文本折行，避免把整表撑爆 */
.md-table td,
.md-table th {
  word-break: break-word;
}

.viewer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.viewer-toolbar-left,
.viewer-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewer-toolbar-right {
  margin-left: auto;
  justify-content: flex-end;
}

.slide-embed-wrap {
  display: grid;
}

.slide-embed-iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0a1020;
  overflow: hidden;
  scrollbar-width: none;
}

.slide-embed-iframe::-webkit-scrollbar {
  display: none;
}

.posts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 18px;
  align-items: start;
}

.index-panel {
  position: sticky;
  top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: #0f172b;
}

body.viewing-post .main-layout {
  grid-template-columns: minmax(0, 1fr);
}

body.viewing-post .index-panel {
  display: none;
}

/* 仅在大屏表格场景下收窄阅读区（正常文章保持原比例） */
body.viewing-post .markdown-body .table-wrap {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 1200px) {
  body.viewing-post .markdown-body .table-wrap {
    width: min(66vw, 980px);
  }
}

/* 表格区域可换行，避免横向撑开 */
body.viewing-post .markdown-body .table-wrap .md-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

body.viewing-post .markdown-body .table-wrap .md-table th,
body.viewing-post .markdown-body .table-wrap .md-table td {
  white-space: normal;
  word-break: break-word;
}

/* fallback: even if JS class not applied, hide right panel when viewer is active */
.main-layout:has(#viewer:not(.hidden)) {
  grid-template-columns: minmax(0, 1fr);
}

.main-layout:has(#viewer:not(.hidden)) .index-panel {
  display: none;
}

.index-panel h3 {
  margin: 14px 0 10px;
  font-size: 14px;
  color: #b9c8ef;
}

.filter-title {
  font-size: 16px;
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: #17233f;
  color: #cfe0ff;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

.chip.active {
  border-color: var(--accent);
  background: #22437d;
  color: #fff;
}

.btn-small {
  margin-top: 10px;
  padding: 4px 8px;
  font-size: 12px;
}

.index-panel {
  position: sticky;
  top: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #101a2f;
}

.index-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.index-panel-body {
  margin-top: 8px;
}

.index-panel.collapsed-desktop .index-panel-body {
  display: none;
}

.filter-toggle-btn,
.tag-more-btn {
  margin-top: 0;
}

.index-panel .filter-title {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
}

.index-panel h3 {
  margin: 14px 0 8px;
  font-size: 14px;
  color: #c9d7ff;
}

.btn-small {
  font-size: 12px;
  padding: 4px 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: #162544;
  color: #d7e2ff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip.active {
  border-color: #6ea8ff;
  background: #214a86;
  color: #fff;
}

.month-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #162544;
  color: #d7e2ff;
  padding: 8px 10px;
  font-size: 13px;
}

body[data-theme='light'] .month-select {
  background: #eef3ff;
  color: #38527c;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .site-header {
    padding: 14px 0 12px;
  }

  .site-title-row {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .site-actions {
    margin-left: auto;
    gap: 8px;
    align-items: center;
  }

  .site-nav-inline {
    gap: 8px;
    align-items: center;
    line-height: 1;
  }

  .site-nav-inline a {
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    line-height: 1;
  }

  .site-header h1 {
    margin: 0 0 4px;
    font-size: 22px;
  }

  .site-header p {
    margin: 0;
    font-size: 13px;
  }

  #theme-toggle.theme-toggle-icon {
    width: 30px;
    height: 30px;
    padding: 0;
  }

  .theme-icon {
    font-size: 16px;
  }

  .viewer-toolbar {
    flex-wrap: wrap;
  }

  .viewer-toolbar-right {
    width: 100%;
  }

  /* Mobile filter turns into floating panel: zero document height usage */
  .index-panel {
    position: fixed;
    right: 12px;
    top: auto;
    bottom: calc(14px + env(safe-area-inset-bottom));
    z-index: 9999;
    width: auto;
    order: initial;
    padding: 0;
    border: none;
    background: transparent;
    pointer-events: none;
  }

  .index-panel-head {
    justify-content: flex-end;
    pointer-events: auto;
  }

  .index-panel .filter-title {
    display: none;
  }

  .filter-toggle-btn {
    position: fixed;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    border-radius: 999px;
    padding: 8px 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(6px);
    background: color-mix(in srgb, var(--card) 90%, black 10%);
    border-color: var(--border);
    color: var(--text);
    min-width: 60px;
    font-size: 13px;
    z-index: 10000;
  }

  .index-panel-body {
    position: fixed;
    right: 12px;
    bottom: calc(58px + env(safe-area-inset-bottom));
    width: min(90vw, 360px);
    margin-top: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: color-mix(in srgb, var(--card) 92%, black 8%);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    max-height: 58vh;
    overflow: auto;
    pointer-events: auto;
    z-index: 9998;
  }

  .index-panel.collapsed-mobile .index-panel-body {
    display: none;
  }

  .index-panel:not(.collapsed-mobile) .filter-toggle-btn {
    border-color: var(--accent);
  }

  .chips {
    gap: 6px;
  }

  .chip {
    padding: 4px 9px;
    font-size: 12px;
  }
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  padding: 16px 0 30px;
}

@media (max-width: 980px) {
  .posts-grid {
    grid-template-columns: 1fr;
  }
}
