/* =============================================
   base.css — 基础重置与全局样式
   业务公式引擎 · 根底重置层
   ============================================= */

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

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 全局 Body ---------- */
body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-regular);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-normal);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--duration-slow) var(--ease-default),
              color var(--duration-slow) var(--ease-default);
}

/* ---------- 背景光晕装饰 ---------- */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-glow-1);
  pointer-events: none;
  z-index: var(--z-base);
}

body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-glow-2);
  pointer-events: none;
  z-index: var(--z-base);
}

/* ---------- 链接 ---------- */
a {
  color: var(--text-link);
  text-decoration: none;
  transition: var(--transition-color);
}

a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

/* ---------- 按钮 ---------- */
button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  outline: none;
}

button:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: var(--opacity-disabled);
}

/* ---------- 输入元素 ---------- */
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
}

textarea {
  resize: none;
}

/* ---------- 列表 ---------- */
ul,
ol {
  list-style: none;
}

/* ---------- 图片 ---------- */
img,
svg {
  display: block;
  max-width: 100%;
}

/* ---------- 标题 ---------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

/* ---------- 段落 ---------- */
p {
  line-height: var(--leading-relaxed);
}

/* ---------- 代码 ---------- */
code,
pre,
kbd {
  font-family: var(--font-mono);
}

code {
  font-size: 0.9em;
  background: var(--bg-badge);
  padding: var(--space-3xs) var(--space-2xs);
  border-radius: var(--radius-sm);
  color: var(--accent-purple);
}

pre {
  background: var(--bg-secondary);
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  border: var(--border-width-thin) solid var(--border-color);
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--text-primary);
}

/* ---------- 表格 ---------- */
table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  padding: var(--space-xs) var(--space-sm);
  border-bottom: var(--border-width-thin) solid var(--border-color);
  text-align: left;
}

th {
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* ---------- 滚动条样式 ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
  transition: background var(--duration-fast) var(--ease-default);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Firefox 滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* ---------- 选中文本样式 ---------- */
::selection {
  background: var(--selection-bg);
  color: var(--selection-color);
}

::-moz-selection {
  background: var(--selection-bg);
  color: var(--selection-color);
}

/* ---------- 焦点可见性 ---------- */
:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
}

/* ---------- 隐藏类 ---------- */
.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !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-width: 0;
}

/* ---------- 通用工具类 ---------- */

/* 毛玻璃卡片 */
.glass-card {
  background: var(--bg-card);
  border: var(--border-width-thin) solid var(--border-color);
  border-radius: var(--radius-card);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  box-shadow: var(--shadow-card);
  transition: var(--transition-normal);
}

.glass-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

/* 渐变文字 */
.gradient-text {
  background: var(--gradient-text);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* 主色渐变背景 */
.gradient-bg {
  background: var(--gradient-main);
  color: var(--text-inverse);
}

/* 弹性布局工具 */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.flex-1 {
  flex: 1;
}

.items-center {
  align-items: center;
}

.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* 文字截断 */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 文字颜色 */
.text-primary    { color: var(--text-primary); }
.text-secondary  { color: var(--text-secondary); }
.text-muted      { color: var(--text-muted); }
.text-blue       { color: var(--accent-blue); }
.text-purple     { color: var(--accent-purple); }
.text-green      { color: var(--accent-green); }
.text-amber      { color: var(--accent-amber); }
.text-red        { color: var(--accent-red); }
.text-gold       { color: var(--accent-gold); }

/* 字号 */
.text-caption { font-size: var(--text-xs); }
.text-label   { font-size: var(--text-sm); }
.text-body    { font-size: var(--text-base); }
.text-sub     { font-size: var(--text-lg); }
.text-title   { font-size: var(--text-xl); }

/* 字重 */
.font-medium  { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold    { font-weight: var(--font-bold); }

/* 圆角 */
.rounded-sm { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* 阴影 */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-glow { box-shadow: var(--shadow-glow); }

/* 动画类 */
.animate-fade-in {
  animation: fade-in var(--anim-fade-duration) var(--ease-default) both;
}

.animate-slide-up {
  animation: slide-up var(--anim-slide-duration) var(--ease-default) both;
}

.animate-pulse {
  animation: pulse var(--anim-pulse-duration) var(--ease-default) infinite;
}

/* 关键帧定义（供工具类与组件复用） */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(0.98); }
}

@keyframes wave {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* 减弱动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
