/* ============================================
   在线工具箱 - 公共样式
   CSS变量、Reset、排版、暗黑模式、Glassmorphism
   ============================================ */

/* --- Google Fonts（通过 HTML <link> 标签加载，此处保留备用） --- */
/* @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap'); */

/* --- CSS 变量（亮色主题） --- */
:root {
  /* 基础色 */
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-surface-hover: #f5f7fa;
  --color-border: #e2e8f0;
  --color-text: #1a202c;
  --color-text-secondary: #64748b;
  --color-text-muted: #94a3b8;

  /* 主色调 */
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-primary-light: #eff6ff;
  --color-primary-dark: #1d4ed8;
  --color-primary-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);

  /* 语义色 */
  --color-success: #22c55e;
  --color-success-hover: #16a34a;
  --color-success-light: #dcfce7;
  --color-warning: #f59e0b;
  --color-warning-light: #fef3c7;
  --color-error: #ef4444;
  --color-error-hover: #dc2626;
  --color-error-light: #fee2e2;
  --color-info: #06b6d4;
  --color-info-light: #cffafe;

  /* 遮罩层 */
  --color-overlay: rgba(0, 0, 0, 0.45);

  /* 侧边栏 */
  --sidebar-width: 260px;
  --sidebar-bg: #ffffff;
  --sidebar-text: #334155;
  --sidebar-text-hover: #3b82f6;
  --sidebar-active-bg: #eff6ff;
  --sidebar-border: #e2e8f0;

  /* 圆角 */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* 阴影 */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.35);
  --glass-blur: 14px;

  /* 排版 */
  --font-stack: "Inter", system-ui, -apple-system, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Courier New", monospace;

  /* 字号变量 */
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.8125rem;    /* 13px */
  --text-base: 0.875rem;   /* 14px */
  --text-md: 0.9375rem;    /* 15px */
  --text-lg: 1rem;         /* 16px */
  --text-xl: 1.125rem;     /* 18px */
  --text-2xl: 1.25rem;     /* 20px */
  --text-3xl: 1.5rem;      /* 24px */
  --text-4xl: 1.75rem;     /* 28px */
  --text-5xl: 2.25rem;     /* 36px */

  /* 间距 */
  --space-2xs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* 过渡 */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;

  /* 层级 */
  --z-sidebar: 1000;
  --z-overlay: 999;
  --z-header: 998;
  --z-toast: 10000;
  --z-modal: 10001;
}

/* --- 暗黑模式 --- */
[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-hover: #334155;
  --code-bg: #1a2332;
  --color-border: #334155;
  --color-text: #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-muted: #64748b;
  --color-primary: #60a5fa;
  --color-primary-hover: #3b82f6;
  --color-primary-light: #1e3a5f;
  --color-primary-dark: #93c5fd;
  --color-primary-gradient: linear-gradient(135deg, #60a5fa, #a78bfa);
  --color-success: #4ade80;
  --color-success-hover: #22c55e;
  --color-success-light: #14532d;
  --color-warning: #fbbf24;
  --color-warning-light: #713f12;
  --color-error: #f87171;
  --color-error-hover: #ef4444;
  --color-error-light: #7f1d1d;
  --color-info: #22d3ee;
  --color-info-light: #164e63;
  --color-overlay: rgba(0, 0, 0, 0.6);
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-text-hover: #60a5fa;
  --sidebar-active-bg: #1e3a5f;
  --sidebar-border: #334155;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --glass-bg: rgba(30, 41, 59, 0.72);
  --glass-border: rgba(51, 65, 85, 0.5);
}

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

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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-stack);
  font-size: var(--text-lg);
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

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

/* 内联SVG保持默认display，避免菜单图标换行 */
svg:not(:root) {
  display: inline-block;
  vertical-align: middle;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
}

ul,
ol {
  list-style: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* --- 排版系统 --- */
h1 {
  font-size: var(--text-4xl);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

h2 {
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1.35;
}

h3 {
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.4;
}

h4 {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.4;
}

code,
pre {
  font-family: var(--font-mono);
}

code {
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  background: var(--color-surface-hover);
  border-radius: var(--radius-xs);
}

pre {
  font-size: var(--text-base);
  padding: var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  line-height: 1.5;
}

pre code {
  padding: 0;
  background: none;
  border-radius: 0;
}

/* --- Glassmorphism 工具类 --- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.glass-modal {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-xl);
}

/* --- 通用工具类 --- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

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

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

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

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

.text-muted {
  color: var(--color-text-secondary);
}

.text-sm {
  font-size: var(--text-base);
}

.text-xs {
  font-size: var(--text-xs);
}

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-text-muted);
  border-radius: 3px;
}

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

/* --- 选中文字颜色 --- */
::selection {
  background: var(--color-primary);
  color: #ffffff;
}

/* --- color-scheme 声明（让浏览器原生控件跟随主题） --- */
:root {
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
}

/* --- 减少动效 --- */
@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;
  }
}

/* --- Skip Link --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  z-index: calc(var(--z-toast) + 1);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: #ffffff;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: var(--space-md);
}
