/* ==========================================================
   fringe.log 共享样式：设计令牌、顶栏、按钮、代码块、搜索面板、页脚
   动效由 <html data-motion="on|off"> 控制；
   配色默认跟随系统，顶栏开关改写 <meta name="color-scheme"> 固定浅色或深色
   ========================================================== */

/* 本地托管字体：只含拉丁字符，中文用系统字体，不向第三方发请求 */
@font-face {
  font-family: "Unbounded";
  src: url("fonts/unbounded-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 900; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 800; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;
  &:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
  &:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }

  --bg: light-dark(#F4F3FA, #10112A);
  --surface: light-dark(#FFFFFF, #181A3B);
  --ink: light-dark(#17163A, #ECEAFF);
  --muted: light-dark(#5E5C86, #A9A6D8);
  --line: light-dark(#DCDAF0, #2E3166);
  --accent: light-dark(#4B3AE6, #A99BFF);
  --accent-soft: light-dark(#EEECFB, #27286A);
  --on-ink: light-dark(#FFFFFF, #10112A);          /* 深色块（--ink 底）上的文字 */
  --on-ink-muted: light-dark(#D9D6FF, #4A4870);
  --code-bg: light-dark(#FBFAFF, #14163A);
  --mark: light-dark(#FFF1B8, #5C4A10);
  --draft-bg: light-dark(#FFF1B8, #4A3D0E);
  --draft-fg: light-dark(#6B4A00, #FFE28A);
  --scroll-thumb: light-dark(#A9A6CF, #4A4E8C);
  --shadow: light-dark(rgb(23 22 58 / .3), rgb(0 0 0 / .55));
  --glow: light-dark(rgb(75 58 230 / .35), rgb(169 155 255 / .28));
  --glass: color-mix(in oklab, var(--bg) 82%, transparent);
  --mint: #8EE8D6;
  --sky: #9FD3FF;
  --lilac: #C3B5FF;
  --pink: #FFB3D4;
  --butter: #FFE28A;
  --holo: linear-gradient(100deg, var(--mint), var(--sky) 25%, var(--lilac) 50%, var(--pink) 75%, var(--butter));
  /* 卡片底色：粉彩混进表面色，深浅主题都适用 */
  --tint-mint: color-mix(in oklab, var(--mint) 18%, var(--surface));
  --tint-sky: color-mix(in oklab, var(--sky) 18%, var(--surface));
  --tint-lilac: color-mix(in oklab, var(--lilac) 20%, var(--surface));
  --tint-pink: color-mix(in oklab, var(--pink) 18%, var(--surface));
  --tint-butter: color-mix(in oklab, var(--butter) 20%, var(--surface));

  --f-display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --f-body: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --gutter: clamp(16px, 4vw, 48px);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --header-h: 62px;

  accent-color: var(--accent);
  scrollbar-color: var(--scroll-thumb) var(--bg);
  scroll-padding-top: calc(var(--header-h) + 16px);
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 1.0625rem/1.75 var(--f-body);
  font-size-adjust: from-font;
  overflow-x: clip;
}
a { color: inherit; }
img, svg { max-width: 100%; }
::selection { background: var(--lilac); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.wrap { width: min(1180px, 100% - 2 * var(--gutter)); margin-inline: auto; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font: 500 .75rem/1 var(--f-mono); padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }

.skip {
  position: fixed; left: 16px; top: 12px; z-index: 50; padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--on-ink); text-decoration: none; translate: 0 -200%;
}
.skip:focus-visible { translate: 0 0; }

/* ---------- 阅读进度条（装饰，渐进增强） ---------- */
.progress { display: none; }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@supports (animation-timeline: scroll()) {
  [data-motion="on"] .progress {
    display: block; position: fixed; inset: 0 0 auto; height: 4px; z-index: 30;
    background: var(--holo); transform-origin: 0 50%;
    animation: grow auto linear;
    animation-timeline: scroll(root);
  }
}

/* ---------- 顶栏与响应式导航 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid color-mix(in oklab, var(--line) 70%, transparent);
}
.header-inner { display: flex; align-items: center; gap: 12px; min-height: var(--header-h); }
.header-inner > * { flex-shrink: 0; white-space: nowrap; }
.brand {
  font: 800 1rem/1 var(--f-display); letter-spacing: -0.02em; text-decoration: none;
  display: inline-flex; align-items: center; gap: 10px; margin-right: auto;
}
.site-nav { display: flex; }
.tool {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .9rem;
  text-decoration: none; transition: border-color .2s;
}
.tool:hover { border-color: var(--accent); }
.menu-button { anchor-name: --menu-button; }
.site-menu {
  list-style: none; margin: 0; padding: 8px;
  position: fixed; inset: auto;
  inset-block-start: calc(var(--header-h) + 6px);
  inset-block-start: anchor(--menu-button bottom);
  inset-inline-end: 1rem; margin-block-start: .5rem;
  inline-size: min(80dvw, 16rem); max-block-size: calc(100dvh - 6rem); overflow: auto;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  box-shadow: 0 20px 50px -20px var(--shadow);
}
.site-menu a {
  display: block; padding: 10px 14px; border-radius: 10px; text-decoration: none; color: var(--muted);
}
.site-menu a:hover { background: var(--accent-soft); color: var(--ink); }
.site-menu a[aria-current="page"] { color: var(--ink); font-weight: 650; }
.site-menu a[aria-current="page"]::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.site-header.is-wide .menu-button { display: none; }
.site-header.is-wide .site-menu {
  position: static; display: flex; gap: clamp(4px, 1.5vw, 14px);
  inline-size: auto; max-block-size: none; overflow: visible;
  margin: 0 8px 0 0; padding: 0; border: 0; background: transparent; box-shadow: none;
}
.site-header.is-wide .site-menu a { padding: 6px 8px; }
.site-header.is-wide .site-menu a:hover { background: transparent; }
.site-header.is-wide .site-menu a[aria-current="page"]::after { display: none; }
.site-header.is-wide .site-menu a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.is-measuring * { transition: none !important; }
[data-motion="on"] .site-header:not(.is-wide) .site-menu {
  transition: opacity .2s, translate .2s var(--ease), display .2s, overlay .2s;
  transition-behavior: allow-discrete;
  &:not(:popover-open) { opacity: 0; translate: 0 -8px; }
  @starting-style { &:popover-open { opacity: 0; translate: 0 -8px; } }
}
#motion .i-play, [data-motion="off"] #motion .i-pause { display: none; }
[data-motion="off"] #motion .i-play { display: block; }

/* 主题开关：只显示“切换到另一种”的那个选项，状态完全由 CSS 判断，不依赖脚本 */
#theme { padding: 0 11px; }
#theme .mlabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#theme .to-light { display: none; }
:root:has(> head > meta[name="color-scheme"][content="dark"]) #theme {
  .to-dark { display: none; }
  .to-light { display: contents; }
}
@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) #theme {
    .to-dark { display: none; }
    .to-light { display: contents; }
  }
}
/* 不支持 popover 的旧浏览器：菜单改由脚本加 .open 显示 */
@supports not selector(:popover-open) {
  .site-header:not(.is-wide) .site-menu:not(.open) { display: none; }
}

@media (max-width: 640px) {
  .header-inner { gap: 6px; }
  .tool .label, .tool kbd { display: none; }
  /* 窄屏只显示图标，文字仍是按钮的可读名称 */
  .tool:has(.mlabel) { padding: 0 11px; }
  .tool .mlabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* ---------- 区块标题 ---------- */
h2 { margin: 0; font: 600 clamp(1.6rem, 3.4vw, 2.4rem)/1.15 var(--f-display); letter-spacing: -0.03em; }
@keyframes lift { from { opacity: 0; translate: 0 32px; } }
@supports ((animation-timeline: view()) and (animation-range: entry)) {
  [data-motion="on"] .lift {
    animation: lift linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 70%;
  }
}

/* ---------- 代码块与复制 ---------- */
pre {
  margin: 0; padding: 20px 22px; overflow-x: auto; font: 400 .9rem/1.7 var(--f-mono);
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 14px;
}
pre code { font: inherit; }
/* 代码块：语言和复制按钮放在顶部一栏，不会盖住代码 */
.code {
  display: flex; flex-direction: column; margin: 28px 0;
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 14px;
}
.code pre { border: 0; border-radius: 0 0 14px 14px; background: transparent; padding-top: 14px; }
.code-bar {
  order: -1; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px 6px 18px; border-bottom: 1px dashed var(--line);
}
/* Shiki 双主题：每个词同时带浅色和深色两种颜色，按当前配色取用 */
.shiki span { color: light-dark(var(--shiki-light), var(--shiki-dark)); font-style: var(--shiki-light-font-style); }
.lang { font: .75rem var(--f-mono); color: var(--muted); }
.copy { position: relative; }
.copy-button {
  min-inline-size: 32px; min-block-size: 32px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px; background: color-mix(in oklab, var(--surface) 92%, transparent);
  transition: border-color .2s;
}
.copy-button:hover { border-color: var(--accent); }
.copy-button .ok { display: none; }
.copy-button[data-copied] .ok { display: block; color: light-dark(#0F7C8C, #6FE3D6); }
.copy-button[data-copied] .idle { display: none; }
.tip {
  position: absolute; right: 0; top: calc(100% + 6px); padding: 4px 8px; border-radius: 6px;
  background: var(--ink); color: var(--on-ink); font-size: .78rem; white-space: nowrap; z-index: 2;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.tip:not(:empty) { opacity: 1; }
.note { margin: 28px 0; padding: 16px 20px; border-radius: 14px; background: linear-gradient(120deg, var(--tint-mint), var(--tint-lilac) 60%, var(--tint-pink)); }
.note p { margin: 0; }
.tag { font: 400 .78rem/1 var(--f-mono); padding: 6px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; text-decoration: none; }
span.draft-tag { background: var(--draft-bg); color: var(--draft-fg); }
a.tag:hover { color: var(--ink); background: var(--accent-soft); }

/* ---------- 筛选按钮 ---------- */
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: .92rem;
  transition: background-color .2s, border-color .2s, color .2s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.chip-n { margin-left: 6px; font: .75rem var(--f-mono); opacity: .7; }

/* ---------- 搜索面板 ---------- */
.palette {
  width: min(620px, 100% - 32px); margin: 12vh auto auto; padding: 0;
  border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--ink);
  box-shadow: 0 30px 80px -20px var(--shadow);
  overscroll-behavior: contain;
}
.palette::backdrop { background: rgb(23 22 58 / .28); backdrop-filter: blur(4px); overflow: hidden; overscroll-behavior: contain; }
[data-motion="on"] {
  .palette, .palette::backdrop {
    transition: opacity .2s, translate .25s var(--ease), display .25s, overlay .25s;
    transition-behavior: allow-discrete;
  }
  .palette:not([open]) { opacity: 0; translate: 0 -12px; }
  .palette:not([open])::backdrop { opacity: 0; }
  @starting-style {
    .palette[open] { opacity: 0; translate: 0 -12px; }
    .palette[open]::backdrop { opacity: 0; }
  }
}
.palette-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.palette input { flex: 1; min-width: 0; border: 0; outline: 0; font: inherit; font-size: 1.1rem; background: transparent; color: var(--ink); }
.palette ul { list-style: none; margin: 0; padding: 8px; max-height: 50vh; overflow: auto; }
.palette li a { display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px; text-decoration: none; }
.palette li a:hover, .palette li a:focus-visible { background: var(--accent-soft); outline-offset: -2px; }
.palette li small { color: var(--muted); }
.palette mark { background: var(--mark); color: inherit; border-radius: 3px; }
.palette .empty { padding: 18px 14px; color: var(--muted); }
.palette-foot { padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; display: flex; gap: 16px; }

/* ---------- 页脚与返回顶部 ---------- */
.site-footer { border-top: 1px solid var(--line); padding-block: 40px 96px; color: var(--muted); font-size: .92rem; background: var(--surface); }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 16px 32px; justify-content: space-between; }
.site-footer nav { display: flex; gap: 20px; }

/* 页面滚动后才出现；不支持滚动状态查询的浏览器由脚本加 .scrolled */
:root { container-type: scroll-state; }
.to-top {
  position: fixed; right: var(--gutter); bottom: 24px; z-index: 15;
  min-inline-size: 44px; min-block-size: 44px; padding: 0; justify-content: center;
  box-shadow: 0 10px 30px -10px var(--glow);
  visibility: hidden; opacity: 0; translate: 0 12px;
  transition: visibility .3s, opacity .3s, translate .3s var(--ease), border-color .2s;
}
.scrolled .to-top { visibility: visible; opacity: 1; translate: 0 0; }
@container scroll-state(scrollable: top) {
  .to-top { visibility: visible; opacity: 1; translate: 0 0; }
}

/* ---------- 页面之间的过渡（脚本在关闭动效时跳过） ---------- */
/* @view-transition 写在每个页面 <head> 的内联样式里，保证新页面一开始就声明 */
::view-transition-group(*) { animation-duration: .45s; animation-timing-function: var(--ease); }
:root:not([data-motion="on"])::view-transition-group(*),
:root:not([data-motion="on"])::view-transition-old(*),
:root:not([data-motion="on"])::view-transition-new(*) { animation: none !important; }
