/* ==========================================================================
   base.css · reset + 基础排版 + 关键帧 + 工具类 + 应用骨架
   来源：outputs/02-design-tokens.md §2.3
   硬约束：无横向滚动 / 100dvh / 触摸目标 ≥44px / 输入框 16px
   ========================================================================== */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--lh-body);
  font-weight: var(--fw-regular);
  letter-spacing: var(--tracking-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;                 /* §2.3-3 禁止横向滚动 */
}

p, li { line-height: var(--lh-body); }
li { line-height: var(--lh-list); }

h1, h2, h3, h4 {
  margin: 0;
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  color: var(--color-text-primary);
}

a { color: var(--color-link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

button { font-family: inherit; font-size: inherit; cursor: pointer; }

img { display: block; max-width: 100%; }

::selection { background: var(--color-accent-tint); color: var(--color-text-primary); }

/* 统一焦点：仅键盘可见（accent 白名单 ①） */
:focus { outline: none; }
:focus-visible { box-shadow: var(--ring-focus); }

/* 长内容断行（§2.3-3） */
.msg-body, .resume-text { word-break: break-word; overflow-wrap: anywhere; }
pre, code { overflow-x: auto; }

/* 视图切换 */
[hidden] { display: none !important; }

/* 图标：统一线性 1.5px stroke / 16–18px / currentColor（§3 通用规则） */
.icon {
  width: 18px; height: 18px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }

/* ---------- 排印工具类 ---------- */
.u-serif      { font-family: var(--font-serif); }                  /* 仅大标题 */
.u-wordmark   { font-size: var(--text-2xl); font-weight: var(--fw-semibold);
                letter-spacing: var(--tracking-tighter); line-height: var(--lh-tight); }
.u-h-section  { font-size: var(--text-xl); font-weight: var(--fw-semibold);
                letter-spacing: var(--tracking-tighter); line-height: var(--lh-tight); }
.u-h-card     { font-size: var(--text-lg); font-weight: var(--fw-medium);
                letter-spacing: var(--tracking-tight); line-height: var(--lh-tight); }
.u-meta       { font-size: var(--text-xs); font-weight: var(--fw-regular);
                color: var(--color-text-tertiary-aa); line-height: var(--lh-snug); }
.u-label-caps { font-size: var(--text-2xs); font-weight: var(--fw-medium);
                letter-spacing: var(--tracking-wide); text-transform: uppercase;
                color: var(--color-text-tertiary-aa); }
.u-en        { font-family: var(--font-en); }
.u-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;
}

/* ---------- 关键帧 ---------- */
@keyframes fade-up   { from { opacity: 0; transform: translateY(4px); }
                       to   { opacity: 1; transform: none; } }
@keyframes fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes panel-in  { from { opacity: 0; transform: translateY(8px); }
                       to   { opacity: 1; transform: none; } }
@keyframes sheet-in  { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes caret     { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes dot-bounce{ 0%, 60%, 100% { transform: translateY(0); }
                       30%          { transform: translateY(-3px); } }
@keyframes pulse-soft{ 0%, 100% { opacity: 1; } 50% { opacity: .6; } }

.u-enter       { animation: fade-up var(--dur-base) var(--ease-out) both; }
.u-enter-fast  { animation: fade-up 160ms var(--ease-out) both; }
.u-enter-panel { animation: panel-in var(--dur-panel) var(--ease-out) both; }

/* 流式打字光标（§2.3） */
.caret {
  display: inline-block; width: 2px; height: 1em;
  margin-left: 2px; vertical-align: -0.15em;
  background: var(--color-text-primary);
  animation: caret 1s step-end infinite;
}

/* 思考指示三点（§3.15） */
.dots { display: inline-flex; gap: var(--space-4); align-items: center; }
.dots i {
  width: 6px; height: 6px; border-radius: var(--radius-full);
  background: var(--color-gray-7);
  animation: dot-bounce 1.2s var(--ease-standard) infinite;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .30s; }

/* 骨架屏（纯色 + 呼吸，不使用渐变） */
.skeleton { background: var(--color-skeleton); border-radius: var(--radius-sm);
            animation: pulse-soft 1.2s var(--ease-standard) infinite; }

/* ---------- 无障碍：减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- 打印 ---------- */
@media print {
  body { background: var(--color-gray-0); }
  .no-print { display: none !important; }
}

/* ==========================================================================
   应用骨架（App Shell）
   ≥1024 双栏：侧栏 + 对话；≤1023 单栏 + 抽屉 / Bottom Sheet
   ========================================================================== */

/* 移动端键盘弹起时由 JS 写入 --vvh（§2.3-2） */
.app-shell {
  height: 100vh;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  overflow: hidden;
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;            /* 关键：让子元素可独立滚动 */
  width: 100%;
  max-width: var(--layout-max);
  margin: 0 auto;
}

/* 桌面：侧栏与对话区各自独立滚动（§2.3-6） */
.resume-panel {
  width: var(--sidebar-w);
  flex: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg);
}

.chat-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-bg);
}

/* 对话滚动容器（§2.3-1） */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.chat-inner {
  width: 100%;
  max-width: var(--chat-max);
  margin: 0 auto;
  padding: var(--space-24) var(--space-32) var(--space-24);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* ---------- 遮罩 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .32);
  z-index: var(--z-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}
.backdrop.is-open { opacity: 1; pointer-events: auto; }

/* ---------- 无滚动条工具类 ---------- */
.u-noscrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.u-noscrollbar::-webkit-scrollbar { display: none; }

/* 细滚动条（桌面侧栏） */
@media (hover: hover) {
  .resume-panel::-webkit-scrollbar { width: 8px; }
  .resume-panel::-webkit-scrollbar-thumb {
    background: var(--color-gray-4); border-radius: var(--radius-full);
    border: 2px solid var(--color-bg);
  }
  .resume-panel::-webkit-scrollbar-track { background: transparent; }
}

/* ==========================================================================
   背景装饰层 · 仅前台（body[data-bg="decor"]，后台不加载，保持工具感）
   蓝白主色不变：全部为 accent 的低透明度衍生物，装饰层不承载信息
   ========================================================================== */
body[data-bg="decor"]::before,
body[data-bg="decor"]::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* 柔光：右上靛蓝主光晕 + 左下呼应 + 中央极淡托底 */
body[data-bg="decor"]::before {
  background:
    radial-gradient(920px 620px at 86% -8%, rgba(61, 91, 217, .13), transparent 62%),
    radial-gradient(720px 520px at -8% 108%, rgba(61, 91, 217, .09), transparent 60%),
    radial-gradient(560px 420px at 50% 42%, rgba(61, 91, 217, .045), transparent 70%);
  animation: bg-drift 26s var(--ease-standard) infinite alternate;
}

/* 细网格：44px 方格，中心可见、边缘淡出，营造"工程蓝图"底纹 */
body[data-bg="decor"]::after {
  background-image:
    linear-gradient(rgba(61, 91, 217, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 91, 217, .06) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 92% 82% at 50% 38%, #000 28%, transparent 76%);
  mask-image: radial-gradient(ellipse 92% 82% at 50% 38%, #000 28%, transparent 76%);
  opacity: .55;
}

@keyframes bg-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-14px, 10px, 0) scale(1.02); }
}

/* --------------------------------------------------------------------------
   线框地球：内联 SVG，无外部资源。
   与「首页」状态联动——未开始对话时完整呈现（那是引导页的主视觉），
   一旦开聊就淡到几乎不可见，把注意力交还给问答内容，也避免干扰长文阅读。
   -------------------------------------------------------------------------- */
.bg-globe {
  position: fixed;
  right: -4vw;
  bottom: -14vh;
  width: min(60vw, 680px);
  aspect-ratio: 1 / 1;
  z-index: -1;
  pointer-events: none;
  color: var(--color-accent);
  opacity: .6;
  transition: opacity .7s var(--ease-standard, ease),
              transform .7s var(--ease-standard, ease);
}

/* 地球整体压得很淡：线宽 < 1px、透明度分层，只做底纹不抢内容 */
.bg-globe svg { width: 100%; height: 100%; display: block; overflow: visible; }
.bg-globe [data-globe="outline"] { stroke: currentColor; stroke-width: 1; fill: none; opacity: .42; }
.bg-globe [data-globe="grid"]    { stroke: currentColor; stroke-width: .7; fill: none; opacity: .26; }
.bg-globe [data-globe="equator"] { stroke: currentColor; stroke-width: 1; fill: none; opacity: .42; }
.bg-globe [data-globe="orbit"]   { stroke: currentColor; stroke-width: .8; fill: none; opacity: .26;
                                   stroke-dasharray: 5 9; }

/* 极缓慢的呼吸 + 轨道环自转；幅度刻意做小，避免页面"一直在动" */
.bg-globe svg { animation: globe-breathe 24s ease-in-out infinite alternate; }
.bg-globe [data-globe="orbit"] { transform-origin: 200px 200px; animation: globe-orbit 90s linear infinite; }

@keyframes globe-breathe {
  from { transform: scale(1); }
  to   { transform: scale(1.025); }
}
@keyframes globe-orbit {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* 开聊后：淡出并略微下沉，让对话区干净 */
body[data-chat="on"] .bg-globe { opacity: .14; transform: translateY(3%) scale(.98); }

/* 小屏只保留一点点轮廓，避免和消息气泡打架 */
@media (max-width: 1023px) {
  .bg-globe { width: 84vw; right: -22vw; bottom: -8vh; opacity: .34; }
  body[data-chat="on"] .bg-globe { opacity: .1; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-bg="decor"]::before { animation: none; }
  .bg-globe svg,
  .bg-globe [data-globe="orbit"] { animation: none; }
}

/* 口令门：原为纯色铺底，改为透出装饰层，并在卡片后加一圈柔光 */
body[data-bg="decor"] .gate { background: transparent; }
body[data-bg="decor"] .gate-card {
  position: relative;
  box-shadow: var(--shadow-float), 0 0 0 1px rgba(61, 91, 217, .06),
              0 24px 80px -24px rgba(61, 91, 217, .18);
}
body[data-bg="decor"] .gate::before {
  content: "";
  position: absolute;
  width: 560px; height: 560px;
  left: 50%; top: 50%;
  transform: translate(-50%, -54%);
  border-radius: 50%;
  background: radial-gradient(circle,
              rgba(61, 91, 217, .10) 0%,
              rgba(61, 91, 217, .05) 42%,
              transparent 68%);
  pointer-events: none;
}

/* 主区域：透出装饰层；简历侧栏做半透明白，保证文字可读性 */
body[data-bg="decor"] .app-shell,
body[data-bg="decor"] .chat-area { background: transparent; }
body[data-bg="decor"] .resume-panel { background: rgba(255, 255, 255, .55); }
@supports (backdrop-filter: blur(8px)) {
  body[data-bg="decor"] .resume-panel {
    background: rgba(255, 255, 255, .42);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
}
