/* 全站样式。不加载任何外部字体或资源，国内打开不受影响。 */

:root {
  --paper: #f3f5f8;
  --surface: #ffffff;
  --ink: #17223b;
  --ink-2: #566078;
  --rule: #d3d9e3;
  --rule-soft: #e6eaf0;
  --blue: #2348c7;
  --blue-soft: #b9c7f2;
  --marker: #ffe066;
  --marker-ink: #3d3200;
  --red: #c8372d;
  --green: #0e9070;
  --code-bg: #eef1f6;

  --serif: Charter, "Iowan Old Style", "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", STSong, SimSun, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --tok-keyword: #2348c7;
  --tok-string: #1b7a50;
  --tok-number: #a85400;
  --tok-title: #8a2d6b;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10141c;
    --surface: #171c27;
    --ink: #e7ebf3;
    --ink-2: #9aa4b8;
    --rule: #2c3445;
    --rule-soft: #222938;
    --blue: #8aa7ff;
    --blue-soft: #33457f;
    --marker: #f2d24b;
    --marker-ink: #2a2200;
    --red: #e0483f;
    --green: #35b58b;
    --code-bg: #1e2431;
    --tok-keyword: #8aa7ff;
    --tok-string: #6fd0a0;
    --tok-number: #f0a860;
    --tok-title: #e08cc0;
  }
}

.updown-red { --gain: var(--red); --loss: var(--green); }
.updown-green { --gain: var(--green); --loss: var(--red); }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.7;
}

a { color: var(--blue); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 2px; }

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

.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

/* ———— 页头页脚 ———— */

.site-head, main, .site-foot { width: min(100% - 2.5rem, 46rem); margin-inline: auto; }
.site-head, .site-foot { width: min(100% - 2.5rem, 75rem); }
main.wide { width: min(100% - 2.5rem, 75rem); }

.site-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: 1.4rem 0 1.1rem;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; letter-spacing: 0.04em; }
.site-head nav { display: flex; gap: 1.5rem; }
.site-head nav a { color: var(--ink); text-decoration: none; padding-bottom: 0.15rem; border-bottom: 2px solid transparent; }
.site-head nav a:hover { border-bottom-color: var(--rule); }
.site-head nav a[aria-current] { border-bottom-color: var(--ink); }

main { padding: 1.5rem 0 4rem; min-height: 60vh; }

.site-foot {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; align-items: center;
  padding: 1.5rem 0 2.5rem; border-top: 1px solid var(--rule);
  color: var(--ink-2); font-size: 0.875rem;
}
.site-foot a { color: var(--ink-2); }
.site-foot form { margin: 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); text-decoration: underline; text-underline-offset: 0.2em; cursor: pointer; }

/* ———— 通用小件 ———— */

h1, h2, h3 { font-family: var(--serif); line-height: 1.3; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; font-size: 2.1rem; font-weight: 900; letter-spacing: 0.04em; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.btn {
  display: inline-block; padding: 0.45em 1em; border: 1px solid var(--ink); border-radius: 3px;
  background: transparent; color: var(--ink); font: inherit; font-size: 0.93rem; line-height: 1.5;
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--rule-soft); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--surface); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { font-size: 0.85rem; padding: 0.3em 0.75em; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn[disabled] { opacity: 0.5; cursor: default; }

mark.private {
  background: var(--marker); color: var(--marker-ink);
  font: 500 0.72rem/1.6 var(--sans); letter-spacing: 0.05em;
  padding: 0.1em 0.5em; margin-left: 0.6em; border-radius: 2px; vertical-align: middle; white-space: nowrap;
}

.empty { color: var(--ink-2); padding: 1.5rem 0; }
.hint { color: var(--ink-2); font-size: 0.875rem; }
.more { margin-top: 1rem; }
.back { margin-top: 3rem; }
.section-title { font-size: 1.3rem; margin: 2.8rem 0 0.8rem; }

.tags { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; }
.tag {
  font-size: 0.8rem; color: var(--ink-2); text-decoration: none;
  border: 1px solid var(--rule); border-radius: 2px; padding: 0 0.5em; line-height: 1.7;
}
.tag:hover { color: var(--ink); border-color: var(--ink-2); }

/* 盈亏：数字保持正文颜色，方向由小三角和正负号一起表示 */
.pnl { white-space: nowrap; font-variant-numeric: tabular-nums; }
.pnl i { display: inline-block; width: 0; height: 0; margin-right: 0.35em; vertical-align: 0.08em; border: 0.3em solid transparent; }
.pnl.up i { border-bottom: 0.5em solid var(--gain); border-top: 0; }
.pnl.down i { border-top: 0.5em solid var(--loss); border-bottom: 0; }
.pnl.flat i { border: 0; width: 0.6em; height: 2px; background: var(--ink-2); vertical-align: 0.3em; }
.pnl.none { color: var(--ink-2); }

/* ———— 面板（首页、交易页） ———— */

.dash-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem 1.5rem; margin-bottom: 1rem; }
.dash-top .actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.intro { margin: 0; color: var(--ink-2); }

.kpis {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; margin: 0 0 1.25rem;
  background: var(--rule-soft); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden;
}
.kpis.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis div { background: var(--surface); padding: 1.05rem 1.25rem; min-width: 0; }
.kpis div.accent { background: color-mix(in srgb, var(--blue) 8%, var(--surface)); }
.kpis dt { font-size: 0.82rem; color: var(--ink-2); }
.kpis dd { margin: 0.1rem 0 0; font-size: 1.8rem; font-weight: 650; line-height: 1.3; white-space: nowrap; }
.kpis dd.sub { font-size: 0.78rem; font-weight: 400; line-height: 1.5; color: var(--ink-2); white-space: normal; }
.kpis .pnl { font-variant-numeric: normal; }
.kpis .pnl i { font-size: 0.6em; }

.dash { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; align-items: start; }
.dash.stretch { align-items: stretch; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 1.1rem 1.25rem 1.15rem; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.4rem 1rem; }
.panel-head h2 { margin: 0; font-size: 1.15rem; }
.panel-note { margin: 0.15rem 0 0.6rem; font-size: 0.82rem; color: var(--ink-2); }
.panel-note .pnl { color: var(--ink); }
.panel-link { font-size: 0.85rem; }
.panel .empty { padding: 1rem 0 0.4rem; font-size: 0.92rem; }
.panel .more { margin: 0.8rem 0 0; font-size: 0.85rem; }
.panel .chart { margin: 0.7rem 0 0; }
.panel .plot { border: 0; }
.key { display: inline-flex; align-items: center; gap: 0.35em; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin: 0; font-size: 0.8rem; color: var(--ink-2); }

.range { display: inline-flex; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; font-size: 0.82rem; }
.range a { padding: 0.15em 0.85em; color: var(--ink); text-decoration: none; }
.range a + a { border-left: 1px solid var(--rule); }
.range a:hover { background: var(--rule-soft); }
.range a[aria-current] { background: var(--ink); color: var(--paper); }

.rows { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.rows li { border-top: 1px solid var(--rule-soft); }
.rows a { display: block; padding: 0.65rem 0; color: var(--ink); text-decoration: none; }
.rows a:hover .row-main { color: var(--blue); text-decoration: underline; }
.rows a[aria-current] .row-main { font-weight: 700; }
.row-main { display: block; }
.row-main.title { font-family: var(--serif); font-weight: 700; font-size: 1.02rem; line-height: 1.45; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.8rem; margin-top: 0.1rem; font-size: 0.8rem; color: var(--ink-2); }
.row-meta .pnl { color: var(--ink); }
.rows mark.private { margin-left: 0; }
.rows .row-main + mark.private { margin-top: 0.2rem; display: inline-block; }

.note-badge {
  display: inline-block; padding: 0 0.45em; border-radius: 2px; background: var(--blue); color: var(--surface);
  font-size: 0.7rem; line-height: 1.55; white-space: nowrap;
}
td .note-badge { margin-left: 0.6em; vertical-align: middle; }

/* 月历：一格一天，最右一列是每周小计 */
.cal-scroll { overflow-x: auto; margin-top: 0.8rem; }
.cal { display: grid; gap: 6px; grid-template-columns: repeat(6, minmax(0, 1fr)); min-width: 34rem; }
.cal.cols-7 { grid-template-columns: repeat(8, minmax(0, 1fr)); min-width: 44rem; }
.cal-h { font-size: 0.8rem; color: var(--ink-2); }
.cal-cell {
  display: flex; flex-direction: column; min-width: 0; min-height: 5.4rem; padding: 0.5rem 0.6rem;
  border: 1px solid transparent; border-radius: 4px; color: var(--ink); text-decoration: none;
}
a.cal-cell:hover { border-color: var(--ink); text-decoration: none; }
.cal-top { display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; font-size: 0.8rem; color: var(--ink-2); }
.cal-badges { display: inline-flex; gap: 0.25rem; }
.cal-badges mark.private { margin: 0; padding: 0 0.35em; font-size: 0.68rem; line-height: 1.55; }
.cal-main { margin-top: 0.35rem; font-size: 1.08rem; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cal-sub { font-size: 0.76rem; color: var(--ink-2); }
.cal-sub.clip { margin-top: 0.35rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal-cell.up { background: color-mix(in srgb, var(--gain) 11%, var(--surface)); }
.cal-cell.up.big { background: color-mix(in srgb, var(--gain) 25%, var(--surface)); }
.cal-cell.down { background: color-mix(in srgb, var(--loss) 12%, var(--surface)); }
.cal-cell.down.big { background: color-mix(in srgb, var(--loss) 27%, var(--surface)); }
.cal-cell.flat { background: var(--rule-soft); }
.cal-cell.blank { border-color: var(--rule-soft); }
.cal-cell.add .cal-sub { margin-top: auto; color: var(--blue); visibility: hidden; }
.cal-cell.add:hover .cal-sub, .cal-cell.add:focus-visible .cal-sub { visibility: visible; }
.cal-cell.future { border: 1px dashed var(--rule); }
.cal-cell.out { min-height: 0; }
.cal-cell.week { background: var(--code-bg); }
.cal-cell.week.none { background: transparent; border: 1px dashed var(--rule); }
.cal-cell.today .cal-top > span:first-child { color: var(--ink); font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.2em; }

.month-nav { display: flex; align-items: baseline; gap: 1rem; font-size: 0.85rem; }
.month-nav h2 { min-width: 7.5em; text-align: center; }
.muted-link { color: var(--ink-2); opacity: 0.6; }

.entries { list-style: none; margin: 0; padding: 0; }
.entries li { display: grid; grid-template-columns: 8.2em 1fr; gap: 1.2rem; padding: 0.95rem 0; border-top: 1px solid var(--rule); }
.entries li:last-child { border-bottom: 1px solid var(--rule); }
.entries time { color: var(--ink-2); font-size: 0.9rem; font-variant-numeric: tabular-nums; padding-top: 0.15em; }
.entry-title { font-family: var(--serif); font-weight: 700; font-size: 1.12rem; color: var(--ink); text-decoration: none; }
.entry-title:hover { color: var(--blue); text-decoration: underline; }
.entries p { margin: 0.2rem 0 0; color: var(--ink-2); font-size: 0.93rem; }
.entries .tags { margin-top: 0.5rem; }

/* ———— 笔记 ———— */

.tagbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.tagbar a {
  font-size: 0.875rem; color: var(--ink); text-decoration: none;
  border: 1px solid var(--rule); border-radius: 2px; padding: 0.1em 0.7em;
}
.tagbar a small { color: var(--ink-2); margin-left: 0.4em; }
.tagbar a:hover { border-color: var(--ink-2); }
.tagbar a[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.tagbar a[aria-current] small { color: inherit; opacity: 0.7; }

.note-head { margin-bottom: 2.2rem; padding-bottom: 1.2rem; border-bottom: 2px solid var(--ink); }
.note-head h1 { margin: 0 0 0.8rem; font-size: clamp(1.8rem, 5vw, 2.5rem); font-weight: 900; letter-spacing: 0.02em; }
.note-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; align-items: center; color: var(--ink-2); font-size: 0.9rem; }
.note-meta .edit { margin-left: auto; }
.day-lede { margin: 1rem 0 0; font-size: 1.1rem; }

.prose { font-size: 1.06rem; line-height: 1.9; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 2.2em 0 0.7em; }
.prose h1 { font-size: 1.6rem; }
.prose h2 { font-size: 1.4rem; }
.prose h3 { font-size: 1.18rem; }
.prose h4 { font-size: 1.05rem; font-family: var(--sans); }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote, .prose .table-wrap, .prose .math-block { margin: 0 0 1.25em; }
.prose ul, .prose ol { padding-left: 1.6em; }
.prose li + li { margin-top: 0.3em; }
.prose img { max-width: 100%; height: auto; display: block; margin-inline: auto; border: 1px solid var(--rule); }
.prose blockquote { margin-inline: 0; padding: 0.1em 0 0.1em 1.1em; border-left: 3px solid var(--ink); color: var(--ink-2); }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em 0; }
.prose code { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); padding: 0.12em 0.35em; border-radius: 3px; }
.prose pre {
  position: relative; background: var(--code-bg); border-radius: 4px;
  padding: 1em 1.1em; overflow-x: auto; line-height: 1.6; font-size: 0.9rem;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }
.prose pre[data-lang]::before {
  content: attr(data-lang); position: absolute; top: 0.3em; right: 0.7em;
  font: 0.72rem var(--sans); color: var(--ink-2);
}
.math-block { overflow-x: auto; overflow-y: hidden; padding: 0.3em 0; }
.katex { font-size: 1.08em; }

.hljs-comment, .hljs-quote { color: var(--ink-2); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-built_in, .hljs-type { color: var(--tok-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attr { color: var(--tok-string); }
.hljs-number, .hljs-symbol, .hljs-meta { color: var(--tok-number); }
.hljs-title, .hljs-section, .hljs-name, .hljs-deletion { color: var(--tok-title); }

/* ———— 表格 ———— */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.55em 0.9em 0.55em 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
th { font-weight: 500; font-size: 0.82rem; color: var(--ink-2); border-bottom: 1px solid var(--ink); white-space: nowrap; }
th.n, td.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th:last-child, td:last-child { padding-right: 0; }
.prose table { font-size: 0.95rem; }

/* ———— 交易日志 ———— */

.chart { margin: 0 0 2.5rem; }
.chart figcaption { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.2rem 1rem; margin-bottom: 0.4rem; }
.chart h2 { margin: 0; font-size: 1.15rem; }
.chart figcaption p { margin: 0; font-size: 0.82rem; color: var(--ink-2); display: flex; gap: 1rem; }
.sw { display: inline-block; width: 0.75em; height: 0.75em; border-radius: 2px; }
.sw.up { background: var(--gain); }
.sw.down { background: var(--loss); }

.plot { position: relative; background: var(--surface); border: 1px solid var(--rule); }
.plot svg { display: block; width: 100%; height: auto; }
.plot .grid { stroke: var(--rule-soft); stroke-width: 1; }
.plot .zero { stroke: var(--ink-2); stroke-width: 1; }
.plot text { fill: var(--ink-2); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.plot text.end { fill: var(--ink); font-size: 12px; font-weight: 600; }
.plot .line { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .dot { fill: var(--blue); stroke: var(--surface); stroke-width: 2; }
.plot .bar.up { fill: var(--gain); }
.plot .bar.down { fill: var(--loss); }
.plot .cross { stroke: var(--ink-2); stroke-width: 1; }
.plot .hover-band { fill: var(--ink); opacity: 0.06; }
.tip {
  position: absolute; top: 8px; pointer-events: none; z-index: 2;
  background: var(--ink); color: var(--paper); border-radius: 3px;
  padding: 0.4em 0.7em; font-size: 0.8rem; line-height: 1.5; white-space: nowrap;
}
.tip b { display: block; font-weight: 600; }
.tip span { display: block; font-variant-numeric: tabular-nums; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); }
.pager a { text-decoration: none; font-size: 0.9rem; }
.pager a span { color: var(--ink-2); }
.pager a[rel="next"] { text-align: right; }

/* ———— 登录、提示 ———— */

.login { max-width: 23rem; margin: 3rem auto; }
.login h1 { font-size: 1.6rem; margin: 0 0 1.5rem; }
.login label { display: block; font-size: 0.9rem; margin-bottom: 0.3rem; }
.login input {
  width: 100%; padding: 0.6em 0.7em; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--ink-2); border-radius: 3px; margin-bottom: 1rem;
}
.login pre { background: var(--code-bg); padding: 0.8em 1em; overflow-x: auto; border-radius: 4px; font-size: 0.88rem; }
.form-error { color: var(--red); font-size: 0.9rem; margin: 0 0 1rem; }
.message { margin: 4rem 0; }
.message h1 { font-size: 1.8rem; }

/* ———— 小屏 ———— */

@media (max-width: 960px) {
  .dash { grid-template-columns: minmax(0, 1fr); }
  .span-2, .span-3 { grid-column: auto; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis div.accent { grid-column: span 2; }
}

@media (max-width: 760px) {
  .entries li { grid-template-columns: 1fr; gap: 0.2rem; }
  .page-head h1 { font-size: 1.7rem; }
  .site-head nav { gap: 1.1rem; }
}

@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis div.accent { grid-column: span 2; }
  .kpis dd { font-size: 1.45rem; }
  .panel { padding: 1rem 0.9rem; }
}

@media print {
  .site-head nav, .site-foot, .back, .pager, .btn { display: none; }
  body { background: #fff; }
}
