/* ====== 主题变量 ====== */
:root {
  --bg: #f6f7fb;
  --bg-card: #ffffff;
  --bg-hover: #f0f2f8;
  --bg-input: #f6f7fb;
  --text: #1a1d29;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.1);
  --primary-text: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 0.2s ease;
  --header-h: 64px;
  --max-w: 900px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1d29;
  --bg-hover: #232735;
  --bg-input: #232735;
  --text: #e8eaf0;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: #2a2e3c;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: rgba(129, 140, 248, 0.15);
  --primary-text: #0f1117;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Noto Sans SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

/* ====== Header ====== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  max-width: var(--max-w);
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 1.4rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
}

/* 搜索框 */
.search-box {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

#search::placeholder {
  color: var(--text-muted);
}

/* 主题切换 */
.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

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

/* 语言切换器 */
.lang-switcher {
  position: relative;
  flex-shrink: 0;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--transition);
}

.lang-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--primary);
}

.lang-flag {
  font-size: 1.1rem;
  line-height: 1;
}

.lang-code {
  letter-spacing: 0.03em;
}

.lang-btn svg {
  opacity: 0.6;
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition);
  z-index: 200;
}

.lang-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition);
}

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

.lang-option.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.lang-option-flag {
  font-size: 1.15rem;
  line-height: 1;
}

/* ====== Main ====== */
.main {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 32px 20px;
}

.hidden {
  display: none !important;
}

/* ====== Hero ====== */
.hero {
  text-align: center;
  margin-bottom: 36px;
  padding-top: 12px;
}

.hero-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.hero-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ====== 类别网格 ====== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.category-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition);
}

.category-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.category-card:active {
  transform: translateY(-1px);
}

.card-icon {
  font-size: 1.8rem;
  line-height: 1;
  flex-shrink: 0;
}

.card-body {
  min-width: 0;
}

.card-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 48px 0;
  font-size: 0.95rem;
}

/* ====== 换算页 ====== */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 20px;
  transition: all var(--transition);
}

.back-btn:hover {
  color: var(--text);
  border-color: var(--primary);
  background: var(--primary-light);
}

.converter-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.converter-icon {
  font-size: 2rem;
  line-height: 1;
}

.converter-title {
  font-size: 1.4rem;
  font-weight: 700;
}

/* 输入行 */
.converter-input-row {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.input-group {
  flex: 1;
}

.select-group {
  flex: 0 0 200px;
}

#inputValue,
#inputUnit {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 500;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

#inputValue:focus,
#inputUnit:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

#inputValue::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

#inputUnit {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

[data-theme="dark"] #inputUnit {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* 结果区 */
.results-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.results-header {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.copy-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.copy-all-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.result-item:hover {
  border-color: var(--primary);
  background: var(--bg-hover);
}

.result-unit {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.result-value-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-value {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.copy-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all var(--transition);
}

.result-item:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.empty-hint {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 0;
  font-size: 0.9rem;
}

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 999;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== Footer ====== */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  transition: border-color var(--transition);
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin-top: 12px;
}

.footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.78rem;
  transition: color var(--transition);
}

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

/* ====== SEO 内容区 ====== */
.seo-content {
  margin-top: 40px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.seo-content h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.seo-content p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 8px;
}

/* ====== 广告位 ====== */
.ad-container {
  margin: 20px 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-top {
  margin-top: 24px;
}

.ad-bottom {
  margin-top: 28px;
}

/* ====== 静态页面 ====== */
.static-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 4px 20px;
}

.static-page h1 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.static-page .updated-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.static-page h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 24px;
  margin-bottom: 10px;
}

.static-page p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.75;
  margin-bottom: 10px;
}

.static-page ul {
  margin: 8px 0 14px 20px;
}

.static-page li {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.75;
  margin-bottom: 4px;
}

.static-page a {
  color: var(--primary);
  text-decoration: none;
}

.static-page a:hover {
  text-decoration: underline;
}

/* 联系表单 */
.contact-form {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.form-group input,
.form-group textarea {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-submit {
  align-self: flex-start;
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  font-family: inherit;
}

.form-submit:hover {
  background: var(--primary-hover);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ====== 顶部 Tab 切换 ====== */
.main-tabs {
  display: flex;
  gap: 4px;
  padding: 0 4px 16px;
}

.main-tab {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

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

.main-tab.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

/* ====== 计算器 ====== */
.calculator-view {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 20px;
}

.calc-mode-switcher {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 4px;
  border: 1px solid var(--border);
}

.calc-mode-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.calc-mode-btn:hover {
  color: var(--text);
}

.calc-mode-btn.active {
  background: var(--primary);
  color: var(--primary-text);
}

.calc-display-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}

.calc-history {
  min-height: 20px;
}

.calc-history-item {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-display {
  font-size: 2.4rem;
  font-weight: 700;
  text-align: right;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.calc-display.error {
  color: #ef4444;
}

.calc-indicators {
  display: flex;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

.calc-indicator {
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-hover);
}

.calc-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calc-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.calc-buttons.sci .calc-row {
  grid-template-columns: repeat(5, 1fr);
}

.calc-btn {
  padding: 16px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  user-select: none;
}

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

.calc-btn:active {
  transform: scale(0.96);
}

.calc-btn.fn {
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.calc-btn.op {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-light);
}

.calc-btn.sci {
  font-size: 0.85rem;
  background: var(--bg-card);
  color: var(--text-secondary);
}

/* ====== 响应式 ====== */
@media (max-width: 640px) {
  .header-inner {
    padding: 0 14px;
    gap: 8px;
  }

  .logo-text {
    display: none;
  }

  .search-box {
    max-width: none;
  }

  .main {
    padding: 20px 14px;
  }

  .calc-display {
    font-size: 1.8rem;
  }

  .calc-btn {
    padding: 14px 4px;
    font-size: 1rem;
  }

  .calc-btn.sci {
    font-size: 0.75rem;
  }

  .hero-title {
    font-size: 1.4rem;
  }

  .hero-subtitle {
    font-size: 0.85rem;
  }

  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  .category-card {
    padding: 14px 12px;
    gap: 10px;
  }

  .card-icon {
    font-size: 1.5rem;
  }

  .converter-input-row {
    flex-direction: column;
    gap: 10px;
  }

  .select-group {
    flex: 1;
  }

  #inputValue,
  #inputUnit {
    height: 48px;
    font-size: 1rem;
  }

  .result-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .result-value-wrap {
    width: 100%;
    justify-content: space-between;
  }

  .copy-btn {
    opacity: 1;
  }

  .lang-code {
    display: none;
  }

  .lang-btn {
    padding: 0 8px;
  }

  .lang-dropdown {
    right: -10px;
  }
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

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

/* ====== 选中文本 ====== */
::selection {
  background: var(--primary-light);
  color: var(--primary);
}
