:root {
  --bg: #ffffff;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --gutter-bg: #f9fafb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --btn: #111827;
  --btn-bg: #f3f4f6;
  --btn-bg-hover: #e5e7eb;
  --accent: #2563eb;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  --nav-h: 46px;
  --toolbar-h: 54px;
  --container-w: 1200px;
  --container-pad: 12px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --fg: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  --gutter-bg: #0f172a;
  --surface: #0b1220;
  --surface-2: #0f172a;
  --btn: #e5e7eb;
  --btn-bg: #111827;
  --btn-bg-hover: #0b1220;
  --accent: #60a5fa;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}

.navbar__inner {
  width: 100%;
  max-width: var(--container-w);
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 var(--container-pad);
  gap: 10px;
}

.navbar__title {
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 18px;
}

.navbar__meta {
  font-size: 12px;
  color: var(--muted);
}

.toolbar {
  position: sticky;
  top: var(--nav-h);
  z-index: 10;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.toolbar__inner {
  width: 100%;
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 0 var(--container-pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar__left,
.toolbar__right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn);
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.btn:hover {
  background: var(--btn-bg-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn--ghost {
  background: transparent;
}

.btn--file {
  display: inline-flex;
  align-items: center;
}

#fileInput {
  display: none;
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  height: 32px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

.select {
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  font-size: 13px;
  height: 26px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  height: 32px;
}

.toggle input {
  accent-color: var(--accent);
}

.divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

.main {
  height: calc(100vh - var(--nav-h) - var(--toolbar-h));
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
  width: 100%;
  max-width: var(--container-w);
  margin: 0 auto;
}

@media (max-width: 980px) {
  .main {
    grid-template-columns: 1fr;
    min-height: 0;
  }
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.panel:last-child {
  border-right: none;
}

.panel__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.panel__title {
  font-weight: 600;
}

.panel__meta {
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
  text-align: right;
}

.editorWrap,
.editor {
  flex: 1;
  min-height: 0;
}

.editorWrap {
  display: flex;
}

.editor {
  width: 100%;
  height: 100%;
}

.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.footer__inner {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 22px var(--container-pad) 34px;
}

.about {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.about__title {
  margin: 0;
  font-size: 18px;
}

.about__p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.about__ref {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.about__ref a {
  color: var(--accent);
  text-decoration: none;
}

.about__ref a:hover {
  text-decoration: underline;
}

.about__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 980px) {
  .about__grid {
    grid-template-columns: 1fr;
  }
}

.about__card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 12px;
}

.about__card--wide {
  padding: 12px;
}

.about__h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.about__list {
  margin: 0;
  padding-left: 18px;
  color: color-mix(in oklab, var(--fg) 82%, var(--muted));
  line-height: 1.7;
}

.about__k {
  color: var(--fg);
  font-weight: 600;
}

.about__code {
  margin: 0;
  overflow: auto;
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 13px;
  line-height: 1.6;
}

.about code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 12px;
  background: color-mix(in oklab, var(--surface) 80%, transparent);
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  padding: 1px 6px;
  border-radius: 999px;
}

.faq {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ===== 通用工具类 - 用于工具页面 ===== */

/* 页面容器 */
.page-container {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 24px var(--container-pad);
}

/* 页面头部 */
.page-header {
  text-align: center;
  margin-bottom: 32px;
  padding: 32px 24px;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--fg);
  margin: 0 0 12px 0;
  letter-spacing: -0.5px;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 15px;
  margin: 0;
}

/* 卡片组件 */
.card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  margin: 0 0 20px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* 表单组件 */
.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 14px;
  color: var(--fg);
}

.form-input,
.form-select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--bg);
  color: var(--fg);
  transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 90%);
}

.form-input::placeholder {
  color: var(--muted);
}

/* 按钮组件 */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

/* 结果展示 */
.result-card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  display: none;
}

.result-card.is-visible {
  display: block;
}

/* 统计网格 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-item {
  padding: 20px 16px;
  background: var(--surface-2);
  border-radius: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

/* 进度条 */
.progress-container {
  margin: 20px 0;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 999px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

/* 消息提示 */
.message {
  padding: 16px;
  border-radius: 10px;
  margin: 16px 0;
  font-size: 14px;
}

.message--success {
  background: color-mix(in srgb, #22c55e, var(--bg) 90%);
  color: #15803d;
  border: 1px solid color-mix(in srgb, #22c55e, var(--border) 50%);
}

.message--error {
  background: color-mix(in srgb, #ef4444, var(--bg) 90%);
  color: #b91c1c;
  border: 1px solid color-mix(in srgb, #ef4444, var(--border) 50%);
}

.message--info {
  background: color-mix(in srgb, var(--accent), var(--bg) 90%);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent), var(--border) 50%);
}

/* 导航链接 */
.navbar__links {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-link {
  text-decoration: none;
  color: var(--fg);
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: var(--surface-2);
}

.nav-link.is-active {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent), transparent 95%);
}

/* 表格样式 */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface-2);
  color: var(--fg);
  font-weight: 600;
  font-size: 13px;
}

.data-table td {
  color: var(--fg);
}

.data-table tbody tr:hover {
  background: var(--surface-2);
}

/* 评分星星 */
.rating-stars {
  display: flex;
  gap: 4px;
}

.rating-star {
  color: #f59e0b;
  font-size: 16px;
}

/* 页面背景装饰 */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(ellipse 80% 50% at 50% -20%, color-mix(in srgb, var(--accent), transparent 90%), transparent),
    radial-gradient(ellipse 60% 40% at 80% 100%, color-mix(in srgb, var(--accent), transparent 95%), transparent);
  pointer-events: none;
  z-index: -1;
}

/* 页面头部装饰 */
.page-header {
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent), #8b5cf6 50%), var(--accent));
  background-size: 200% 100%;
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* 卡片悬停效果 */
.card {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
  box-shadow: 0 4px 20px color-mix(in srgb, var(--accent), transparent 90%);
  border-color: color-mix(in srgb, var(--accent), var(--border) 50%);
}

/* 输入框图标支持 */
.form-input-icon {
  position: relative;
}

.form-input-icon .form-input {
  padding-left: 42px;
}

.form-input-icon .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 18px;
}

/* 按钮加载状态 */
.btn-primary.is-loading {
  position: relative;
  color: transparent;
}

.btn-primary.is-loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin-left: -10px;
  margin-top: -10px;
  border: 2px solid transparent;
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* 统计项动画 */
.stat-item {
  transition: all 0.3s ease;
}

.stat-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent), transparent 85%);
}

/* 结果卡片淡入动画 */
.result-card.is-visible {
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 进度条光泽效果 */
.progress-fill {
  position: relative;
  overflow: hidden;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shine 2s infinite;
}

@keyframes shine {
  to {
    left: 100%;
  }
}

/* 表格行进入动画 */
.data-table tbody tr {
  animation: fadeIn 0.3s ease backwards;
}

.data-table tbody tr:nth-child(1) { animation-delay: 0.05s; }
.data-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.data-table tbody tr:nth-child(3) { animation-delay: 0.15s; }
.data-table tbody tr:nth-child(4) { animation-delay: 0.2s; }
.data-table tbody tr:nth-child(5) { animation-delay: 0.25s; }

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* 导航链接下划线动画 */
.nav-link {
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s ease;
  border-radius: 2px;
}

.nav-link:hover::after,
.nav-link.is-active::after {
  transform: scaleX(1);
}

.nav-link.is-active::after {
  bottom: 2px;
}

/* 徽章组件 */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge--primary {
  background: color-mix(in srgb, var(--accent), transparent 90%);
  color: var(--accent);
}

.badge--success {
  background: color-mix(in srgb, #22c55e, transparent 90%);
  color: #16a34a;
}

.badge--warning {
  background: color-mix(in srgb, #f59e0b, transparent 90%);
  color: #d97706;
}

/* 分隔线装饰 */
.divider--fancy {
  position: relative;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 24px 0;
}

.divider--fancy::before {
  content: '◆';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  padding: 0 12px;
  color: var(--muted);
  font-size: 10px;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

.empty-state__icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
}

/* 工具提示 */
.tooltip {
  position: relative;
}

.tooltip::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 6px 12px;
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  border: 4px solid transparent;
  border-top-color: var(--fg);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.tooltip:hover::before,
.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
}

/* 响应式 */
@media (max-width: 640px) {
  .page-container {
    padding: 16px var(--container-pad);
  }
  
  .page-header {
    padding: 24px 16px;
    margin-bottom: 24px;
  }
  
  .page-header h1 {
    font-size: 22px;
  }
  
  .card {
    padding: 16px;
  }
  
  .card:hover {
    transform: none;
    box-shadow: var(--shadow);
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  
  .stat-item {
    padding: 16px 12px;
  }
  
  .stat-item:hover {
    transform: none;
  }
  
  .stat-value {
    font-size: 20px;
  }
  
  .data-table {
    font-size: 13px;
  }
  
  .data-table th,
  .data-table td {
    padding: 10px 12px;
  }
  
  .navbar__links {
    gap: 4px;
  }
  
  .nav-link {
    padding: 6px 8px;
    font-size: 13px;
  }
}
