:root {
  color-scheme: dark light;
  --bg: #0f1115;
  --bg-elevated: #12161d;
  --text: #e6e6e6;
  --text-strong: #f4f5f6;
  --muted: #9aa0a6;
  --muted-strong: #b8bec5;
  --border: #2a2f36;
  --border-strong: #3a424d;
  --surface: #161a20;
  --surface-hover: #1c222a;
  --accent: #8fc7ff;
  --accent-soft: #c4e1ff;
  --focus: #9fd0ff;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light dark;
    --bg: #f7f8fa;
    --bg-elevated: #ffffff;
    --text: #181b20;
    --text-strong: #0f1217;
    --muted: #636a73;
    --muted-strong: #4d5560;
    --border: #dce1e7;
    --border-strong: #c7ced8;
    --surface: #ffffff;
    --surface-hover: #eef3f7;
    --accent: #0f6cae;
    --accent-soft: #084f84;
    --focus: #0f6cae;
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.72;
}

button {
  font: inherit;
}

a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--accent-soft);
  text-decoration-color: currentColor;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-logo {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-name {
  overflow: hidden;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-nav {
  position: relative;
  flex: 0 0 auto;
}

.history-button,
.history-menu button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.history-button {
  min-width: 72px;
  padding: 0 14px;
}

.history-button:hover,
.history-menu button:hover,
.history-menu button:focus-visible {
  background: var(--surface-hover);
}

.history-button:focus-visible,
.history-menu button:focus-visible,
.brand:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.history-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(220px, calc(100vw - 32px));
  max-height: min(360px, calc(100vh - 88px));
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 48px color-mix(in srgb, #000000 32%, transparent);
}

.history-menu button {
  display: block;
  width: 100%;
  padding: 0 12px;
  text-align: left;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}

.history-menu button:last-child {
  border-bottom: 0;
}

.history-menu button[aria-current="true"] {
  font-weight: 700;
}

.page-main {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: clamp(28px, 5vw, 56px) max(18px, env(safe-area-inset-right)) 88px max(18px, env(safe-area-inset-left));
}

.article-date {
  margin: -0.6rem 0 2rem;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.45;
}

.markdown-body {
  overflow-wrap: anywhere;
  color: var(--text);
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body > *:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.7em 0 0.65em;
  color: var(--text-strong);
  line-height: 1.25;
  letter-spacing: 0;
}

.markdown-body h1 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 2.25rem;
  line-height: 1.12;
}

.markdown-body h2 {
  margin-top: 2.8rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--border);
  font-size: 1.5rem;
}

.markdown-body h3 {
  margin-top: 1.8rem;
  font-size: 1.15rem;
}

.markdown-body h4 {
  font-size: 1.05rem;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table,
.markdown-body .table-scroll {
  margin: 0 0 1.15em;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.5em;
}

.markdown-body li + li {
  margin-top: 0.32em;
}

.markdown-body blockquote {
  padding: 0.2em 0 0.2em 1em;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

.markdown-body hr {
  height: 1px;
  margin: 2.4em 0;
  border: 0;
  background: var(--border);
}

.markdown-body strong {
  color: var(--text-strong);
  font-weight: 700;
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.markdown-body :not(pre) > code {
  padding: 0.08em 0.28em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.markdown-body pre {
  overflow-x: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.table-scroll {
  margin: 1.35rem 0 2rem;
  overflow-x: auto;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border);
}

.markdown-body th,
.markdown-body td {
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.markdown-body th:first-child,
.markdown-body td:first-child {
  width: 96px;
}

.markdown-body th {
  color: var(--text-strong);
  font-weight: 700;
}

.markdown-body td {
  color: var(--text);
}

.markdown-body tr:last-child td {
  border-bottom: 0;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.summary-list {
  display: grid;
  gap: 12px;
  margin: 1rem 0 2.1rem;
}

.summary-card {
  display: grid;
  grid-template-columns: minmax(84px, 108px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.summary-label {
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.45;
}

.summary-text {
  color: var(--text);
  line-height: 1.65;
}

.summary-text > *:first-child {
  margin-top: 0;
}

.summary-text > *:last-child {
  margin-bottom: 0;
}

.source-line {
  margin-top: -0.3rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.source-line a {
  color: var(--muted-strong);
}

@media (max-width: 560px) {
  .site-header {
    min-height: 58px;
    gap: 10px;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
  }

  .brand-name {
    font-size: 16px;
  }

  .history-button {
    min-width: 64px;
    padding: 0 10px;
  }

  .page-main {
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .markdown-body h1 {
    font-size: 1.82rem;
  }

  .markdown-body h2 {
    font-size: 1.28rem;
  }

  .summary-card {
    grid-template-columns: minmax(72px, 30%) minmax(0, 1fr);
    gap: 10px;
    padding: 14px;
  }
}

@media (max-width: 640px) {
  .table-scroll {
    overflow: visible;
  }

  .markdown-body table,
  .markdown-body thead,
  .markdown-body tbody,
  .markdown-body tr,
  .markdown-body th,
  .markdown-body td {
    display: block;
    width: 100%;
  }

  .markdown-body th:first-child,
  .markdown-body td:first-child {
    width: 100%;
  }

  .markdown-body table {
    border: 0;
  }

  .markdown-body thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .markdown-body tbody {
    display: grid;
    gap: 12px;
  }

  .markdown-body tr {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
  }

  .markdown-body td {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }

  .markdown-body td.has-data-label {
    display: grid;
    grid-template-columns: minmax(76px, 32%) minmax(0, 1fr);
    gap: 10px;
  }

  .markdown-body td.has-data-label::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.55;
  }

  .markdown-body tr:last-child td,
  .markdown-body td:last-child {
    border-bottom: 0;
  }
}
