/**
 * [INPUT]: 依赖服务端页面输出的通用语义类名与浏览器系统字体、媒体查询能力
 * [OUTPUT]: 提供阅微页面共享的纸面视觉令牌、动态视口基线、扁平粘性导航、按钮、开关与 Toast
 * [POS]: public 模块的基础视觉层，页面专属样式只能消费其令牌和通用组件
 * [PROTOCOL]: 变更时更新此头部，然后检查 CLAUDE.md
 */

:root {
  color-scheme: light;
  --canvas: #f3f3f0;
  --canvas-deep: #e9e9e5;
  --surface: #ffffff;
  --surface-solid: #ffffff;
  --surface-muted: #f7f7f4;
  --surface-raised: #fbfbf9;
  --ink: #23221f;
  --ink-2: #4f4d47;
  --muted: #74716a;
  --faint: #9a9790;
  --line: rgba(35, 34, 31, 0.12);
  --line-strong: rgba(35, 34, 31, 0.2);
  --accent: #9b3d2a;
  --accent-strong: #7d2f20;
  --accent-soft: #f7e9e4;
  --success: #267a55;
  --success-soft: #eaf7f0;
  --info: #2f6fb0;
  --info-soft: #ebf3fb;
  --warning: #a66b08;
  --warning-soft: #fff5dd;
  --danger: #b33b33;
  --danger-soft: #fff0ef;
  --purple: #7654a0;
  --purple-soft: #f3eef9;
  --shadow-sm: 0 1px 2px rgba(35, 34, 31, 0.045);
  --shadow-md: 0 4px 14px rgba(35, 34, 31, 0.055);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-display: ui-serif, "Songti SC", "STSong", "SimSun", serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button,
a,
select,
label {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid rgba(47, 111, 176, 0.55);
  outline-offset: 3px;
}

/* ── 粘性导航 ──────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 56px;
  padding: 4px 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: rgba(243, 243, 240, 0.96);
  box-shadow: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  min-height: 44px;
  padding: 0 3px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  border-radius: 12px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  box-shadow: none;
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1;
}

.brand-copy {
  display: grid;
  line-height: 1.15;
}

.brand-copy strong {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-copy small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 10px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-link {
  min-height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  border-radius: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: color 160ms var(--ease-out), background-color 160ms var(--ease-out), transform 120ms var(--ease-out);
}

.topbar-link-primary {
  color: #fff;
  background: var(--ink);
}

.topbar-link:active,
.brand:active {
  transform: scale(0.97);
}

/* ── 按钮与开关 ────────────────────────────────── */
.btn {
  min-height: 44px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 680;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: color 160ms var(--ease-out), background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out), transform 120ms var(--ease-out), opacity 160ms var(--ease-out);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  color: var(--faint);
  border-color: var(--line);
  background: var(--surface-muted);
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.78;
}

.btn-primary {
  color: #fff;
  background: var(--ink);
  box-shadow: none;
}

.btn-secondary {
  color: var(--ink-2);
  border-color: var(--line-strong);
  background: var(--surface-solid);
}

.switch {
  width: 40px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  position: relative;
  cursor: pointer;
}

.switch input {
  width: 1px;
  height: 1px;
  position: absolute;
  opacity: 0;
}

.slider {
  width: 40px;
  height: 22px;
  position: relative;
  border-radius: 999px;
  background: #d1d2d5;
  box-shadow: inset 0 0 0 1px rgba(29, 29, 31, 0.07);
  transition: background-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}

.slider::after {
  content: "";
  width: 18px;
  height: 18px;
  position: absolute;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(29, 29, 31, 0.23);
  transition: transform 210ms var(--ease-out);
}

.switch input:checked + .slider {
  background: var(--success);
}

.switch input:checked + .slider::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .slider {
  box-shadow: 0 0 0 2px var(--surface-solid), 0 0 0 5px rgba(47, 111, 176, 0.55);
}

.toggle-label-sm {
  color: var(--muted);
  font-size: 11px;
}

/* ── 操作反馈 ──────────────────────────────────── */
.toast {
  max-width: min(420px, calc(100vw - 32px));
  min-height: 44px;
  padding: 11px 15px;
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(29, 29, 31, 0.9);
  box-shadow: 0 8px 24px rgba(29, 29, 31, 0.18);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  opacity: 0;
  transform: translate(-50%, calc(100% + 48px)) scale(0.98);
  pointer-events: none;
  font-size: 12px;
  transition: opacity 160ms var(--ease-out), transform 220ms var(--ease-out), background-color 160ms var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.toast.ok { background: rgba(38, 122, 85, 0.94); }
.toast.err { background: rgba(179, 59, 51, 0.95); }

@media (hover: hover) and (pointer: fine) {
  .topbar-link:not(.topbar-link-primary):hover {
    color: var(--ink);
    background: rgba(29, 29, 31, 0.055);
  }

  .topbar-link-primary:hover {
    background: #353539;
  }

  .btn-primary:hover:not(:disabled) {
    background: #36363a;
    box-shadow: 0 10px 22px rgba(29, 29, 31, 0.16);
  }

  .btn-secondary:hover:not(:disabled) {
    border-color: rgba(29, 29, 31, 0.26);
    background: #fff;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar,
  .toast {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .topbar {
    background: var(--surface-solid);
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: rgba(29, 29, 31, 0.24);
    --line-strong: rgba(29, 29, 31, 0.42);
    --muted: #55565a;
    --faint: #68696e;
  }

  .topbar {
    border-color: var(--line-strong);
    background: #fff;
  }
}

