/* =========================================================
   NiceTools 全站样式 v2
   参照 33tool.com 优化：
   - 顶部横向分类导航（锚点直达）+ 右侧搜索/语言/收藏
   - 分区标题带 SVG 图标
   - 卡片横向布局：图标 + 名称 + 一行描述（紧凑）
   - 移动端：单列列表行（图标 + 文本 + 收藏）
   配色：白底 + 蓝色主色(#2563eb) + 灰色辅助
   ========================================================= */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #059669;
  --success-light: #ecfdf5;
  --text: #1f2937;
  --text-2: #6b7280;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #eef0f3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-hover: 0 4px 14px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "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;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ================= 顶部导航 ================= */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-top {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
  flex-shrink: 0;
}
.logo svg { color: var(--primary); }
.logo span b { color: var(--primary); }

/* 顶部分类导航：横向滚动 */
.cat-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.cat-nav::-webkit-scrollbar { display: none; }
.cat-nav a {
  color: var(--text-2);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
  transition: all 0.15s;
}
.cat-nav a:hover { color: var(--primary); background: var(--primary-light); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.header-search { position: relative; }
.header-search input {
  width: 180px;
  padding: 7px 32px 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  background: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.header-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.header-search svg {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
}
.search-kbd {
  position: absolute;
  right: 30px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: #9ca3af;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  background: #f9fafb;
  pointer-events: none;
}
.lang-switch {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-switch:hover { border-color: var(--primary); color: var(--primary); }

/* 二级分类快捷条 */
.sub-nav {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.sub-nav::-webkit-scrollbar { display: none; }
.sub-nav a {
  font-size: 13px;
  color: var(--text-2);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  white-space: nowrap;
}
.sub-nav a:hover { color: var(--primary); border-color: var(--primary); }

/* ================= 主体 ================= */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
  width: 100%;
  flex: 1;
}
.section { margin-top: 26px; scroll-margin-top: 68px; }
.section.hidden { display: none; }

.section-title {
  font-size: 17px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
}
.section-title .sec-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.sec-icon svg { width: 16px; height: 16px; }
.sec-count {
  font-size: 12px;
  font-weight: 500;
  color: #9ca3af;
  margin-left: 4px;
}

/* 二级分类子组标题 */
.sub-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  margin: 14px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sub-title::before {
  content: "";
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: #d1d5db;
}
.sub-title:first-child { margin-top: 0; }

/* ================= 卡片 ================= */
/* PC 宽屏 6 列；随视口收窄降列 */
.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
@media (max-width: 1400px) { .grid { grid-template-columns: repeat(5, 1fr); } }
@media (max-width: 1180px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1024px) { .grid { grid-template-columns: repeat(2, 1fr); } }

/* 纵向紧凑卡：图标 + 名称 + 分类标签 + 描述（PC 端） */
.tool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 12px 12px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, border-color 0.15s;
  text-align: center;
}
.tool-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-hover);
}
.tool-card a.card-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  color: inherit;
  flex: 1;
  min-width: 0;
  width: 100%;
}
.tool-card a.card-main:hover { color: inherit; }

.card-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.card-icon svg { width: 21px; height: 21px; }
.card-icon.internal { background: var(--primary-light); color: var(--primary); }
.card-icon.external { background: var(--success-light); color: var(--success); }

.card-text { min-width: 0; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.card-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  line-height: 1.35;
  max-width: 100%;
}
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap;
}
.badge.hot { background: #fef3c7; color: #d97706; }

/* 所属分类标签（chips，最多 3 个 +N） */
.card-cats {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 100%;
}
.cat-chip {
  font-size: 11px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}

.card-desc {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 类型标签（工具/网站）—— 卡片左上角 */
.type-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-2);
  flex-shrink: 0;
  white-space: nowrap;
}
.type-tag.internal { border-color: #dbeafe; color: var(--primary); background: var(--primary-light); }
.type-tag.external { border-color: #d1fae5; color: var(--success); background: var(--success-light); }

/* 收藏按钮 —— 卡片右上角 */
.tool-card .fav-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #d1d5db;
  cursor: pointer;
  padding: 4px;
  line-height: 0;
  transition: color 0.15s, transform 0.15s;
}
.fav-btn:hover { color: #d97706; transform: scale(1.12); }
.fav-btn.active { color: #d97706; }
.fav-btn svg { width: 18px; height: 18px; }

/* ================= 空状态 ================= */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-2);
  font-size: 14px;
}

/* ================= 工具页 ================= */
.tool-page { flex: 1; padding: 28px 0 48px; }
.tool-container { max-width: 900px; margin: 0 auto; padding: 0 16px; }
.tool-head { margin-bottom: 22px; }
.tool-head h1 { font-size: 24px; font-weight: 800; }
.tool-head p { color: var(--text-2); margin-top: 6px; font-size: 14px; }
.tool-body {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--primary-dark); color: #fff; }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--primary); color: var(--primary); background: #fff; }
.btn.small { padding: 5px 13px; font-size: 13px; border-radius: 8px; }

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea:focus, input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
textarea { resize: vertical; min-height: 160px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.hint { font-size: 12px; color: var(--text-2); margin-top: 8px; }
.result-area {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  min-height: 60px;
  word-break: break-all;
  font-size: 14px;
}
.code-block {
  margin: 6px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.text-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.drop-zone {
  padding: 28px 16px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--text-2);
  background: var(--bg);
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover { border-color: var(--primary); }

/* Markdown 预览双栏（移动端上下堆叠） */
@media (max-width: 768px) {
  .md-wrap { grid-template-columns: 1fr !important; }
}

/* ================= 中转页 ================= */
.redirect-page { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 20px; }
.redirect-card {
  width: 100%;
  max-width: 520px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.redirect-card .site-name { font-size: 22px; font-weight: 800; margin: 12px 0 4px; }
.redirect-card .site-desc { color: var(--text-2); font-size: 14px; margin-bottom: 8px; }
.redirect-card .countdown { color: var(--primary); font-size: 15px; font-weight: 600; margin: 18px 0 8px; }
.redirect-card .go-btn { width: 100%; padding: 13px; font-size: 16px; }
.disclaimer {
  margin-top: 20px;
  font-size: 12px;
  color: #9ca3af;
  text-align: left;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px dashed var(--border);
}
.ad-slot {
  margin: 16px 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 13px;
  background: var(--bg);
}

/* ================= 收藏页 ================= */
.favorites-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.favorites-note { font-size: 12px; color: var(--text-2); margin-top: 18px; text-align: center; }

/* ================= 页脚 ================= */
.site-footer { margin-top: 40px; border-top: 1px solid var(--border); padding: 20px 16px; background: #fff; }
.footer-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-2);
}

/* ================= toast ================= */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111827;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= 迷你网格卡片（移动端：只显名称） ================= */
.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 9px;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.menu-btn:hover { border-color: var(--primary); color: var(--primary); }
.menu-btn svg { width: 18px; height: 18px; }

/* ================= 侧边抽屉（移动端导航，参照 33tool） ================= */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 190;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s;
}
.drawer-mask.show { opacity: 1; visibility: visible; }
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 78%;
  max-width: 300px;
  background: #fff;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.25s;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 24px rgba(15, 23, 42, 0.18);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 12px;
  font-size: 18px;
  font-weight: 800;
  border-bottom: 1px solid var(--border);
}
.drawer-head b { color: var(--primary); }
.drawer-nav { padding: 10px 8px; display: flex; flex-direction: column; }
.drawer-nav a {
  padding: 11px 12px;
  border-radius: 9px;
  color: var(--text);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer-nav a:hover, .drawer-nav a.active { background: var(--primary-light); color: var(--primary); }
.drawer-nav a svg { width: 18px; height: 18px; color: var(--text-2); }
.drawer-cat-title {
  padding: 14px 16px 6px;
  font-size: 12px;
  font-weight: 700;
  color: #9ca3af;
  letter-spacing: 1px;
}
.drawer-cats { padding: 0 8px 24px; display: flex; flex-direction: column; }
.drawer-cats a {
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.drawer-cats a:hover { background: var(--primary-light); color: var(--primary); }
.drawer-cats a svg { width: 14px; height: 14px; color: #9ca3af; flex-shrink: 0; }
/* 一级分类展开态：箭头旋转 + 高亮 */
.drawer-cats a.expanded { background: var(--primary-light); color: var(--primary); }
.drawer-cats a.expanded .drawer-arrow { transform: rotate(90deg); color: var(--primary); }
.drawer-cats .drawer-arrow { transition: transform 0.2s; }
/* 抽屉内二级分类展开面板 */
.drawer-sub-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.drawer-sub-panel.open { max-height: 320px; padding: 4px 0 6px 12px; }
.drawer-sub-item {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.drawer-sub-item svg { width: 13px; height: 13px; color: #cbd5e1; flex-shrink: 0; }
.drawer-sub-item:hover { background: var(--primary-light); color: var(--primary); }

/* ================= 分类视图（移动端） ================= */
.cat-view-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
}
.cat-view-head .back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
.cat-view-head .back-btn:hover { border-color: var(--primary); color: var(--primary); }
.cat-view-head .back-btn svg { width: 14px; height: 14px; }
.cat-view-title {
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cat-view-title .sec-icon { width: 26px; height: 26px; border-radius: 7px; }
.cat-view-title .sec-icon svg { width: 14px; height: 14px; }
.cat-view-count { font-size: 12px; font-weight: 500; color: #9ca3af; }

/* ================= 迷你网格卡片（移动端：只显名称） ================= */
.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.mini-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 6px 12px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, border-color 0.15s;
  text-align: center;
  position: relative;
}
.mini-card:hover { border-color: var(--primary); box-shadow: var(--shadow-hover); }
.mini-card a.mini-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  color: inherit;
  width: 100%;
}
.mini-card .card-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}
.mini-card .card-icon svg { width: 17px; height: 17px; }
.mini-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 1.35em;
}
.mini-card .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 10px;
  padding: 0 5px;
}
.mini-card .fav-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px;
}
.mini-card .fav-btn svg { width: 14px; height: 14px; }

/* 超小屏（≤340px）降为 3 列 */
@media (max-width: 340px) {
  .logo span { font-size: 16px; }
  .header-actions .lang-switch { padding: 4px 9px; }
  .mini-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ================= 移动端（≤768px，置于文件末尾确保优先级） ================= */
@media (max-width: 768px) {
  .header-top { padding: 0 12px; gap: 8px; height: 52px; }
  .header-search input { width: 30vw; max-width: 170px; }
  .search-kbd { display: none; }
  .container { padding: 0 12px; }
  .section { margin-top: 22px; scroll-margin-top: 60px; }
  .grid { grid-template-columns: 1fr; gap: 8px; }

  /* 移动端：列表行，描述换行最多2行 */
  .tool-card { padding: 11px 12px; }
  .card-desc { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

  /* 顶部分类导航移入侧边抽屉，正文改用迷你网格（只显名称，默认4列） */
  .cat-nav, .sub-nav { display: none; }
  .menu-btn { display: inline-flex; }
  .mini-grid { grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .mini-card { padding: 12px 4px 10px; }

  /* 移动端输入框防 iOS 聚焦缩放 */
  input[type="text"], input[type="number"], textarea, select, .header-search input { font-size: 16px; }
  .tool-body { padding: 18px 14px; }
  .tool-head h1 { font-size: 21px; }
  .site-footer { padding: 16px 12px; }
  .footer-inner { justify-content: center; text-align: center; }
}
