/* ============================================================
   知遥 · 个人主页 — 居中式个人名片
   令牌 → 基础 → 拼图纹理 → 名片 → 卡片 → 页脚 → 响应式
   ------------------------------------------------------------
   设计取向：居中对齐的单列名片 + 拼图纹理底 + 图标行 + 链接卡片。
   深浅色跟随系统，右上角图标可手动切换。
   ============================================================ */

/* ---------- 1. 设计令牌 ---------- */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-hover: #fcfcfb;

  --ink: #1b1c1e;
  --ink-2: #5c5e63;
  --ink-3: #8d8f95;

  --rule: rgba(27, 28, 30, 0.11);
  --rule-strong: rgba(27, 28, 30, 0.20);
  --pattern: rgba(27, 28, 30, 0.10);

  --accent: #2f4a6d;
  --accent-tint: rgba(47, 74, 109, 0.09);

  /* 名字高亮：参考图用的是黄色荧光笔，这里保留同一角色但更克制 */
  --hl: rgba(255, 214, 92, 0.55);
  --hl-dark: rgba(255, 214, 92, 0.28);

  --online: #22c55e;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", "Songti SC",
    "Source Han Serif SC", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono",
    Consolas, "Liberation Mono", monospace;

  /* 间距 4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --s8: 4rem;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 999px;

  --shadow-sm: 0 1px 2px rgba(27, 28, 30, 0.04);
  --shadow-md: 0 4px 14px -6px rgba(27, 28, 30, 0.16);
  --shadow-lg: 0 10px 28px -12px rgba(27, 28, 30, 0.24);

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur: 180ms;
  --dur-fast: 130ms;

  --z-pattern: 0;
  --z-content: 1;
  --z-sticky: 40;

  --shell: 780px;
  --tile: 62px;
}

[data-theme="dark"] {
  --bg: #131316;
  --surface: #1b1c20;
  --surface-hover: #22232a;

  --ink: #ececee;
  --ink-2: #a7a8ae;
  --ink-3: #7c7e85;

  --rule: rgba(236, 236, 238, 0.13);
  --rule-strong: rgba(236, 236, 238, 0.24);
  --pattern: rgba(236, 236, 238, 0.10);

  --accent: #9fb8d8;
  --accent-tint: rgba(159, 184, 216, 0.12);
  --hl: var(--hl-dark);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px -6px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 12px 32px -12px rgba(0, 0, 0, 0.7);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131316;
    --surface: #1b1c20;
    --surface-hover: #22232a;

    --ink: #ececee;
    --ink-2: #a7a8ae;
    --ink-3: #7c7e85;

    --rule: rgba(236, 236, 238, 0.13);
    --rule-strong: rgba(236, 236, 238, 0.24);
    --pattern: rgba(236, 236, 238, 0.10);

    --accent: #9fb8d8;
    --accent-tint: rgba(159, 184, 216, 0.12);
    --hl: var(--hl-dark);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px -6px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 12px 32px -12px rgba(0, 0, 0, 0.7);

    color-scheme: dark;
  }
}

/* ---------- 2. 基础 ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.75;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

h1, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }
img { display: block; max-width: 100%; }

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              background-color var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

.tnum { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

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

.skip {
  position: fixed;
  top: var(--s3);
  left: 50%;
  z-index: var(--z-sticky);
  padding: 0.5rem 0.9rem;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.85rem;
  transform: translate(-50%, -200%);
}
.skip:focus-visible { transform: translate(-50%, 0); }

/* 文字下划线：hover 时实心 */
.ul {
  background-image: linear-gradient(var(--rule-strong), var(--rule-strong));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 1px;
  transition: background-size var(--dur) var(--ease),
              background-image var(--dur) var(--ease),
              color var(--dur) var(--ease);
}
.ul:hover {
  color: var(--accent);
  background-image: linear-gradient(var(--accent), var(--accent));
}

/* ---------- 3. 拼图纹理底 ---------- */
/* 内联 SVG 平铺，无外部请求；深浅色各用一份（纹理色不同） */
.puzzle {
  position: fixed;
  inset: 0;
  z-index: var(--z-pattern);
  pointer-events: none;
  background-repeat: repeat;
  background-size: var(--tile) var(--tile);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='62' height='62' viewBox='0 0 62 62'><path d='M2 2h48v14c-1.6-2.4-3.4-3.6-5.4-3.6-3.4 0-5.6 2.6-5.6 5.6s2.2 5.6 5.6 5.6c2 0 3.8-1.2 5.4-3.6v29H2V21.3c1.6 2.4 3.4 3.6 5.4 3.6 3.4 0 5.6-2.6 5.6-5.6S10.8 13.7 7.4 13.7c-2 0-3.8 1.2-5.4 3.6z' fill='none' stroke='rgba(27,28,30,0.10)' stroke-width='1'/></svg>");
}
[data-theme="dark"] .puzzle {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='62' height='62' viewBox='0 0 62 62'><path d='M2 2h48v14c-1.6-2.4-3.4-3.6-5.4-3.6-3.4 0-5.6 2.6-5.6 5.6s2.2 5.6 5.6 5.6c2 0 3.8-1.2 5.4-3.6v29H2V21.3c1.6 2.4 3.4 3.6 5.4 3.6 3.4 0 5.6-2.6 5.6-5.6S10.8 13.7 7.4 13.7c-2 0-3.8 1.2-5.4 3.6z' fill='none' stroke='rgba(236,236,238,0.10)' stroke-width='1'/></svg>");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .puzzle {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='62' height='62' viewBox='0 0 62 62'><path d='M2 2h48v14c-1.6-2.4-3.4-3.6-5.4-3.6-3.4 0-5.6 2.6-5.6 5.6s2.2 5.6 5.6 5.6c2 0 3.8-1.2 5.4-3.6v29H2V21.3c1.6 2.4 3.4 3.6 5.4 3.6 3.4 0 5.6-2.6 5.6-5.6S10.8 13.7 7.4 13.7c-2 0-3.8 1.2-5.4 3.6z' fill='none' stroke='rgba(236,236,238,0.10)' stroke-width='1'/></svg>");
  }
}

/* 四周渐隐，让纹理自然淡出、中心内容更清晰 */
body.page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-pattern);
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, transparent 48%, var(--bg) 100%);
}

/* ---------- 4. 舞台与名片 ---------- */
.stage {
  position: relative;
  z-index: var(--z-content);
  max-width: var(--shell);
  margin: 0 auto;
  padding: clamp(3.5rem, 11vh, 7rem) var(--s5) var(--s6);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 9rem);
}

.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}

/* 头像 */
.profile__avatar {
  position: relative;
  width: 128px;
  height: 128px;
  margin-bottom: var(--s5);
}

.profile__avatar img,
.profile__avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-md);
  background: var(--surface);
}

.profile__avatar-fallback {
  display: grid;
  place-items: center;
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-tint);
}

/* 在线状态点：白圈分隔，像参考图那样压在头像右下 */
.profile__dot {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--online);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
}

/* 名字 */
.profile__name {
  font-size: clamp(1.9rem, 6.4vw, 2.7rem);
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.01em;
}

.profile__greet {
  font-family: var(--font-sans);
  font-weight: 700;
}

/* 荧光笔高亮：用背景渐变而不是渐变文字，文字始终是实色 */
.profile__name-text {
  background: linear-gradient(transparent 58%, var(--hl) 58%, var(--hl) 94%, transparent 94%);
  padding: 0 0.12em;
}

/* 签名 */
.profile__quote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.1em;
  margin-top: var(--s4);
  max-width: 34rem;
  min-height: 2.4em;
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1.8;
}

.quote__mark {
  font-family: var(--font-serif);
  font-size: 1.5em;
  line-height: 1;
  color: var(--ink-3);
  opacity: 0.6;
  flex: none;
}

.quote__text { text-wrap: pretty; }

.quote__caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  background: var(--accent);
  opacity: 0.85;
  animation: caret-blink 1.1s steps(2, start) infinite;
  flex: none;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* 图标行 */
.socials {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s5);
  margin-top: var(--s5);
}

.social {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  color: var(--ink-2);
  transition: color var(--dur) var(--ease),
              background-color var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.social:hover {
  color: var(--ink);
  background: var(--accent-tint);
  transform: translateY(-2px);
}
.social:active { transform: translateY(0); }
.social .icon { width: 21px; height: 21px; }

.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#themeToggle .icon--moon { display: none; }
[data-theme="dark"] #themeToggle .icon--sun { display: none; }
[data-theme="dark"] #themeToggle .icon--moon { display: block; }

/* ---------- 5. 链接卡片 ---------- */
.cards {
  width: 100%;
  margin-top: clamp(2.5rem, 7vh, 3.75rem);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s3);
}

.card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 74px;
  padding: var(--s4);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--ink-2);
  font-size: 0.98rem;
  transition: transform var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              background-color var(--dur) var(--ease),
              color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--rule-strong);
  background: var(--surface-hover);
  color: var(--ink);
  box-shadow: var(--shadow-md);
}
.card:active { transform: translateY(0); }

.card__icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--ink-3);
  transition: color var(--dur) var(--ease);
}
.card:hover .card__icon { color: var(--accent); }

.card__label { font-weight: 500; }

/* ---------- 6. 停留时长（数字向上跳动的计时器） ---------- */
.dwell {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: clamp(2.5rem, 7vh, 4rem);
  color: var(--ink-3);
  font-size: 0.86rem;
  line-height: 1;
  /* 数字进出时会上下越界，这里裁掉，保证不影响周围排版 */
  overflow: hidden;
}
.dwell__label { line-height: 1.5; }
.dwell__icon {
  width: 15px;
  height: 15px;
  flex: none;
}
/* 实心圆 + 背景色指针：指针看起来像是从圆里抠出来的 */
.dwell__icon-face { fill: var(--ink-2); }
.dwell__icon-hands {
  fill: none;
  stroke: var(--bg);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  /* 数字卡片较高，必须禁止换行，否则窄屏下会叠成两行 */
  flex-wrap: nowrap;
  white-space: nowrap;
}

.timer__sep {
  flex: none;
  margin: 0 0.3rem;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-weight: 700;
  opacity: 0.75;
}

/* ---- 一位数字：旧数字向上移出、新数字自下弹入 ----
   两个图层叠在同一格，靠位移制造「向上跳」的观感。
   数字格自带裁切，旧数字不会溢出到格子外面残留。 */
.flip {
  position: relative;
  display: block;
  flex: none;                      /* 在 flex 容器里不许被压缩或换行 */
  width: 0.8em;
  height: 1.5em;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  /* 关键：裁掉格子外的部分，否则离开的旧数字会留在上方 */
  overflow: hidden;
}

.flip__layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
  backface-visibility: hidden;
}

/* 新数字盖在旧数字上面，并且自带底色 ——
   否则两层同时实心可见会糊成双影（4 和 5 叠在一起读不出数） */
.flip__in {
  transform: translateY(0);
  z-index: 2;
  background: var(--bg);
}

/* 正在离开的旧数字：平时藏在下方，且在底层 */
.flip__out {
  transform: translateY(100%);
  z-index: 1;
}

/* 旧数字加速向上移出，并快速淡出，不给双影留时间 */
.flip.is-flipping .flip__out {
  animation: digit-out 340ms cubic-bezier(0.34, 0, 0.7, 1) both;
}

/* 新数字自下弹入，末尾过冲再回弹 —— 弹簧手感 */
.flip.is-flipping .flip__in {
  animation: digit-in 560ms cubic-bezier(0.34, 1.56, 0.44, 1) both;
}

@keyframes digit-out {
  0%   { transform: translateY(0);     opacity: 1; }
  40%  { opacity: 0.35; }
  100% { transform: translateY(-110%); opacity: 0; }
}

@keyframes digit-in {
  0%   { transform: translateY(105%); }
  /* 过冲到目标位置之上，再回落到 0 */
  62%  { transform: translateY(-16%); }
  82%  { transform: translateY(5%); }
  100% { transform: translateY(0); }
}

/* ---------- 7. 页脚 ---------- */
.foot {
  position: relative;
  z-index: var(--z-content);
  max-width: var(--shell);
  margin: 0 auto;
  padding: var(--s5) var(--s5) var(--s7);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}
.foot__row {
  font-size: 0.84rem;
  color: var(--ink-2);
}
.foot__row--muted { color: var(--ink-3); font-size: 0.78rem; }
.foot__made { font-style: italic; }
.foot__sep { color: var(--ink-3); margin: 0 0.15rem; }
.foot__admin { opacity: 0.75; }
.foot__admin:hover { opacity: 1; }

/* ---------- 8. 入场动效 ---------- */
/* 只作用于首屏元素，内容永远不依赖动画才可见 */
@media (prefers-reduced-motion: no-preference) {
  .profile__avatar,
  .profile__name,
  .profile__quote,
  .socials,
  .cards,
  .dwell {
    animation: rise 480ms var(--ease) both;
  }
  .profile__name { animation-delay: 60ms; }
  .profile__quote { animation-delay: 110ms; }
  .socials { animation-delay: 160ms; }
  .cards { animation-delay: 210ms; }
  .dwell { animation-delay: 260ms; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 9. 响应式 ---------- */
@media (max-width: 640px) {
  .stage {
    padding-top: clamp(2.75rem, 9vh, 4rem);
    padding-left: var(--s4);
    padding-right: var(--s4);
    min-height: auto;
  }
  .foot { padding-left: var(--s4); padding-right: var(--s4); }

  .profile__avatar { width: 104px; height: 104px; }
  .profile__avatar-fallback { font-size: 2.3rem; }
  .profile__dot { width: 19px; height: 19px; }

  /* 手机上两列，卡片略矮，一屏能看全 */
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
  .card { min-height: 64px; padding: var(--s3) var(--s4); font-size: 0.92rem; }
  .card__icon { width: 18px; height: 18px; }

  .socials { gap: var(--s3); }
  .dwell { margin-top: var(--s6); padding-top: 0; }
}

/* 极窄屏仍保持两列：单列会把卡片挤出首屏，反而不如紧凑两列好用 */
@media (max-width: 380px) {
  .cards { gap: var(--s2); }
  .card {
    min-height: 58px;
    padding: var(--s2) var(--s3);
    gap: 0.4rem;
    font-size: 0.88rem;
    border-radius: var(--r-md);
  }
  .card__icon { width: 16px; height: 16px; }
  .profile__quote { font-size: 0.94rem; }
}

/* 横屏手机 / 矮窗口：收紧纵向节奏，避免卡片被挤出屏幕 */
@media (max-height: 620px) {
  .stage { padding-top: var(--s6); min-height: auto; }
  .profile__avatar { width: 88px; height: 88px; margin-bottom: var(--s4); }
  .cards { margin-top: var(--s5); }
  .dwell { padding-top: var(--s5); }
}

/* ---------- 10. 偏好与打印 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .quote__caret { display: none; }
  /* 减少动效时数字直接切换，不做跳动 */
  .flip.is-flipping .flip__out,
  .flip.is-flipping .flip__in { animation: none !important; }
  .flip__out { transform: translateY(100%); opacity: 0; }
  .flip__in { transform: translateY(0); }
}

@media print {
  .puzzle, body.page::before, .dwell, .foot__admin, #themeToggle { display: none; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
