/* ============================================================
   base.css — 字体 / 令牌 / 主题 / 重置 / 工具类 / 关键帧
   ============================================================ */

/* ---------- 显示字体：得意黑（SIL OFL 开源） ---------- */
@font-face {
  font-family: "Smiley Sans";
  src: url("../fonts/SmileySans-Oblique.ttf.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- 设计令牌 ---------- */
:root {
  /* 基础色（余烬主题为默认，其他主题在下方覆写） */
  --bg: #0b0a08;
  --bg2: #12100c;
  --panel: #0e0d0a;
  --panel-2: #14120d;
  --paper: #f4efe6;
  --dim: #8f887d;
  --faint: rgba(244, 239, 230, 0.08);
  --faint-2: rgba(244, 239, 230, 0.14);
  --acc: #ff5a1f;
  --acc-2: #ffb347;
  --acc-soft: rgba(255, 90, 31, 0.16);
  --acc-glow: rgba(255, 90, 31, 0.35);
  --ok: #5cff8a;
  --term-green: #7dff9a;
  --term-dim: #4d6b55;

  /* 字体 */
  --disp: "Smiley Sans", "MiSans", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  --sans: "MiSans", "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;

  /* 动效 */
  --ease: cubic-bezier(0.22, 0.9, 0.24, 1);
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-1: 0.25s;
  --dur-2: 0.5s;
  --dur-3: 0.9s;

  /* 布局 */
  --wrap: 1240px;
  --pad: clamp(18px, 4vw, 48px);
  --radius: 18px;
  --radius-s: 10px;

  /* 层级 */
  --z-bg: 0;
  --z-content: 2;
  --z-dotnav: 62;
  --z-nav: 70;
  --z-progress: 80;
  --z-case: 85;
  --z-cursor: 90;
  --z-palette: 94;
  --z-toast: 96;
  --z-flash: 99;
  --z-boot: 100;
}

/* ---------- 主题：冰蓝 ---------- */
body[data-theme="ice"] {
  --bg: #060a10;
  --bg2: #0a1018;
  --panel: #0a0f16;
  --panel-2: #0e141d;
  --paper: #eaf2f8;
  --dim: #7d8a96;
  --faint: rgba(234, 242, 248, 0.08);
  --faint-2: rgba(234, 242, 248, 0.14);
  --acc: #35a6ff;
  --acc-2: #8fd8ff;
  --acc-soft: rgba(53, 166, 255, 0.16);
  --acc-glow: rgba(53, 166, 255, 0.35);
}

/* ---------- 主题：终端绿 ---------- */
body[data-theme="matrix"] {
  --bg: #050806;
  --bg2: #081009;
  --panel: #070c08;
  --panel-2: #0a120b;
  --paper: #e8f5ea;
  --dim: #7a8f7e;
  --faint: rgba(232, 245, 234, 0.08);
  --faint-2: rgba(232, 245, 234, 0.14);
  --acc: #38ef7d;
  --acc-2: #b8ffcf;
  --acc-soft: rgba(56, 239, 125, 0.14);
  --acc-glow: rgba(56, 239, 125, 0.3);
}

/* ---------- 重置 ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  background: var(--bg);
}

body {
  font-family: var(--sans);
  color: var(--paper);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.6;
  transition: background 0.6s ease;
}

body.pre-boot {
  overflow: hidden;
}

body.lock {
  overflow: hidden;
}

::selection {
  background: var(--acc);
  color: #fff;
}

a {
  color: inherit;
  text-decoration: none;
}

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

img,
canvas,
svg,
video {
  display: block;
  max-width: 100%;
}

input {
  font-family: inherit;
  color: inherit;
}

/* 滚动条（Chromium） */
::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--faint-2);
  border-radius: 8px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--acc);
}

/* 焦点可见性（键盘党） */
:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 3px;
  border-radius: 4px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- 布局工具类 ---------- */
.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding-left: var(--pad);
  padding-right: var(--pad);
}

.hide {
  display: none !important;
}

.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;
}

/* ---------- 全局装饰层 ---------- */
#grain {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  opacity: 0.05;
  pointer-events: none;
  z-index: 60;
  animation: grain-shift 1.2s steps(3) infinite;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 59;
  background: radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.42) 100%);
}

#crtBg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-bg);
  pointer-events: none;
}

/* 真流体层：网格之上、内容之下，墨丝在字底下游 */
#fluidBg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

body[data-theme="paper"] #fluidBg {
  opacity: 0.55;
  mix-blend-mode: multiply;
}

/* Konami 彩蛋：CRT 故障闪（0.9s 摘除） */
body.glitch main,
body.glitch #nav,
body.glitch footer {
  animation: crt-glitch 0.9s steps(2) both;
}

@keyframes crt-glitch {
  0% { transform: translate(0); filter: none; }
  12% { transform: translate(-4px, 1px) skewX(-0.6deg); filter: hue-rotate(38deg) contrast(1.5); }
  24% { transform: translate(3px, -2px); filter: hue-rotate(-24deg) saturate(2.2); }
  36% { transform: translate(-2px, 0) skewX(0.5deg); filter: contrast(1.9); }
  52% { transform: translate(1px, 1px); filter: hue-rotate(16deg); }
  70% { transform: translate(0); filter: none; }
  100% { transform: translate(0); filter: none; }
}

#progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: linear-gradient(90deg, var(--acc), var(--acc-2));
  z-index: var(--z-progress);
  pointer-events: none;
}

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-flash);
}

#flash.go {
  animation: flash-out 0.55s ease-out both;
}

/* ---------- 文字工具 ---------- */
.k-line {
  font-family: var(--mono);
  color: var(--acc);
  letter-spacing: 3px;
  font-size: clamp(12px, 1.4vw, 14px);
  display: flex;
  align-items: center;
  gap: 12px;
}

.k-line::before {
  content: "";
  width: 44px;
  height: 1px;
  background: var(--acc);
  display: inline-block;
}

.num-tab {
  font-variant-numeric: tabular-nums;
}

/* 逐字容器（fx.js splitChars 填充 .ch） */
.split .ch {
  display: inline-block;
  transform: translateY(112%) rotate(2.5deg);
  opacity: 0;
  transition: transform var(--dur-3) var(--ease), opacity 0.6s ease;
  transition-delay: var(--chd, 0s);
  will-change: transform;
}

.split.in .ch {
  transform: translateY(0) rotate(0);
  opacity: 1;
}

/* 滚动 reveal */
.rv {
  opacity: 0;
  transform: translateY(36px);
  transition: opacity 0.8s ease, transform 0.95s var(--ease);
  transition-delay: var(--d, 0s);
}

.rv.in {
  opacity: 1;
  transform: none;
}

.rv-l {
  opacity: 0;
  transform: translateX(-40px);
  transition: opacity 0.8s ease, transform 0.95s var(--ease);
  transition-delay: var(--d, 0s);
}

.rv-l.in {
  opacity: 1;
  transform: none;
}

.rv-s {
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.7s ease, transform 0.85s var(--ease-back);
  transition-delay: var(--d, 0s);
}

.rv-s.in {
  opacity: 1;
  transform: none;
}

/* ---------- 区块骨架 ---------- */
section {
  position: relative;
  z-index: var(--z-content);
}

.sec-head {
  position: relative;
  margin-bottom: clamp(44px, 7vh, 90px);
}

.ghost {
  position: absolute;
  top: 50%;
  left: -0.04em;
  transform: translateY(-58%);
  font-family: var(--disp);
  font-size: clamp(88px, 15vw, 210px);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: transparent;
  -webkit-text-stroke: 1px var(--faint);
  user-select: none;
  pointer-events: none;
  white-space: nowrap;
}

.sec-num {
  font-family: var(--mono);
  color: var(--acc);
  font-size: 13px;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

h2.sec-title {
  font-family: var(--disp);
  font-size: clamp(38px, 6.4vw, 74px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
  padding-bottom: 0.08em;
}

.sec-sub {
  color: var(--dim);
  margin-top: 14px;
  max-width: 580px;
  font-size: 15px;
}

/* ---------- 关键帧 ---------- */
@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-2%, 1%); }
  66% { transform: translate(1%, -2%); }
  100% { transform: translate(0, 0); }
}

@keyframes flash-out {
  0% { opacity: 0; }
  18% { opacity: 0.92; }
  100% { opacity: 0; }
}

@keyframes blink {
  50% { opacity: 0; }
}

@keyframes pop-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes cue-drop {
  0% { transform: scaleY(0); transform-origin: top; }
  55% { transform: scaleY(1); transform-origin: top; }
  56% { transform-origin: bottom; }
  100% { transform: scaleY(0); transform-origin: bottom; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(110%); opacity: 0; }
}

@keyframes float-y {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 var(--acc-glow); }
  70% { box-shadow: 0 0 0 14px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes marquee-fallback {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* ---------- 静帧 / 降级 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
  .rv,
  .rv-l,
  .rv-s,
  .split .ch {
    opacity: 1 !important;
    transform: none !important;
  }
  html {
    scroll-behavior: auto;
  }
}

.still-root *,
.still-root *::before,
.still-root *::after {
  animation: none !important;
  transition: none !important;
}

.still-root .rv,
.still-root .rv-l,
.still-root .rv-s,
.still-root .split .ch {
  opacity: 1 !important;
  transform: none !important;
}

.still-root #cursor {
  display: none !important;
}
