/* ==========================================================================
   MyTool 工具箱 — 首页样式
   浅色为默认主题，html[data-theme="dark"] 覆盖为深色。
   只用系统字体：页面部署在 nginx 上也能离线使用，不请求任何外部资源。
   ========================================================================== */

:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f6f8fd;
  --surface-3: #eaf0fb;
  --hero-1: #fbfcff;
  --hero-2: #f2f6ff;
  --ink: #101725;
  --ink-2: #46536a;
  --muted: #7b8798;
  --line: #dce3f0;
  --line-strong: #c5d0e3;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #e9f0ff;
  --dot: #ccd7ec;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 1px 3px rgba(16, 24, 40, 0.05), 0 12px 26px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 10px 20px rgba(16, 24, 40, 0.08), 0 28px 56px rgba(16, 24, 40, 0.13);
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --topbar-h: 62px;
  --rail-w: 258px;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
        "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
        "Noto Sans SC", "Source Han Sans SC", sans-serif;
  --num: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #0c111b;
  --surface: #131a26;
  --surface-2: #0f1623;
  --surface-3: #1a2334;
  --hero-1: #151d2b;
  --hero-2: #101724;
  --ink: #e9eef8;
  --ink-2: #b4c0d3;
  --muted: #8592a6;
  --line: #232f42;
  --line-strong: #33415a;
  --accent: #6b93ff;
  --accent-strong: #8aa9ff;
  --accent-soft: #1a2540;
  --dot: #1f2a3d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.35), 0 12px 26px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.4), 0 28px 56px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

code {
  font: 12px/1 var(--num);
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--ink-2);
}

kbd {
  font: 11px/1 var(--num);
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 7px;
}

.i {
  width: 20px;
  height: 20px;
  display: block;
  flex: none;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  transition: top 0.15s ease;
}

.skip:focus {
  top: 10px;
}

.noscript {
  margin: 24px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-gap {
  flex: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 10px;
}

.mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(150deg, #3d78ff, #1f4fd8);
  color: #fff;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.32);
}

.mark svg {
  width: 18px;
  height: 18px;
}

.brand-name {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  padding-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 9px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.search-trigger .i {
  width: 16px;
  height: 16px;
}

.search-trigger:hover {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-2);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-2);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}

.icon-sun {
  display: none;
}

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

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

/* ---------- 布局 ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  align-items: start;
}

.rail {
  position: sticky;
  top: var(--topbar-h);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 20px 14px 22px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.rail-title {
  padding: 2px 10px 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 13.5px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.rail-item .i {
  width: 17px;
  height: 17px;
  color: var(--muted);
  transition: color 0.15s ease;
}

.rail-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.rail-item:hover .i {
  color: var(--ink-2);
}

.rail-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.rail-item.is-active .i {
  color: var(--accent);
}

.rail-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-count {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.rail-sep {
  height: 1px;
  margin: 9px 10px;
  background: var(--line);
}

.rail-foot {
  margin-top: auto;
  padding: 16px 10px 0;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 28px 44px;
  min-width: 0;
}

/* ---------- 首屏 ---------- */

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 326px;
  gap: 30px;
  padding: 34px 32px 30px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--hero-1), var(--hero-2));
  box-shadow: var(--shadow-sm);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 0) 0 0 / 20px 20px;
  opacity: 0.55;
  -webkit-mask-image: linear-gradient(155deg, #000 0%, rgba(0, 0, 0, 0.35) 42%, transparent 72%);
  mask-image: linear-gradient(155deg, #000 0%, rgba(0, 0, 0, 0.35) 42%, transparent 72%);
  pointer-events: none;
}

.hero-main {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.hero h1 {
  font-size: clamp(30px, 3.1vw, 49px);
  line-height: 1.15;
  letter-spacing: -0.022em;
}

.hero-sub {
  max-width: 44ch;
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ink-2);
}

/* 搜索条：整个首页的主控件 */
.cmd-wrap {
  position: relative;
  max-width: 620px;
  margin-top: 2px;
}

.cmd {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 7px 0 16px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.cmd:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-md);
}

.cmd > .i {
  width: 19px;
  height: 19px;
  color: var(--muted);
}

.cmd input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: none;
  outline: none;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
}

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

.cmd input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.cmd-kbd {
  flex: none;
}

.cmd-go {
  flex: none;
  height: 42px;
  padding: 0 20px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.cmd-go:hover {
  background: var(--accent-strong);
}

/* 深色主题的强调色偏亮，按钮文字改用深色以保证对比度 */
html[data-theme="dark"] .cmd-go {
  color: #0b1220;
}

html[data-theme="dark"] .cmd-go:hover {
  background: var(--accent-strong);
  color: #0b1220;
}

/* 搜索结果 */
.results {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 330px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}

.results[hidden] {
  display: none;
}

.result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.result.is-active {
  background: var(--accent-soft);
}

.result-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 600;
}

.result-cat {
  font-size: 11.5px;
  color: var(--muted);
}

.results-hint {
  margin: 6px 8px 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 11px;
  color: var(--muted);
}

.results-empty {
  padding: 14px 12px;
  font-size: 13px;
  color: var(--muted);
}

/* 常用小标签 */
.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.chips[hidden] {
  display: none;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  height: 29px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}

/* ---------- 快捷入口 ---------- */

.quick {
  position: relative;
  z-index: 1;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.quick-title {
  padding: 3px 6px 5px;
  font-size: 12.5px;
  font-weight: 700;
}

.quick-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.quick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  transition: background 0.15s ease, border-color 0.15s ease;
}

a.quick-item:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.quick-item.is-planned {
  border-style: dashed;
  background: var(--surface-2);
  cursor: default;
}

.quick-text {
  min-width: 0;
  flex: 1;
}

.quick-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}

.quick-desc {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- 分类图标底色 ---------- */

.tile {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background: var(--tile-bg, var(--surface-3));
  color: var(--tile-fg, var(--ink-2));
}

.tile .i {
  width: 20px;
  height: 20px;
}

.tile-sm {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}

.tile-sm .i {
  width: 17px;
  height: 17px;
}

.cat-format   { --tile-bg: #eef1ff; --tile-fg: #3b4fe0; }
.cat-encoding { --tile-bg: #e6f6f9; --tile-fg: #0b7f9e; }
.cat-security { --tile-bg: #fdeef1; --tile-fg: #c33a5c; }
.cat-protocol { --tile-bg: #f3eefc; --tile-fg: #6d3ed0; }
.cat-datetime { --tile-bg: #fdf3e2; --tile-fg: #a46800; }
.cat-image    { --tile-bg: #e9f6ed; --tile-fg: #14804a; }

html[data-theme="dark"] .cat-format   { --tile-bg: #1c2244; --tile-fg: #9aabff; }
html[data-theme="dark"] .cat-encoding { --tile-bg: #10282f; --tile-fg: #62cfe4; }
html[data-theme="dark"] .cat-security { --tile-bg: #2c1720; --tile-fg: #f085a2; }
html[data-theme="dark"] .cat-protocol { --tile-bg: #241a3c; --tile-fg: #b79bff; }
html[data-theme="dark"] .cat-datetime { --tile-bg: #2b2113; --tile-fg: #e3ac5c; }
html[data-theme="dark"] .cat-image    { --tile-bg: #122a1d; --tile-fg: #6fce96; }

.badge {
  flex: none;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
}

/* ---------- 工具列表 ---------- */

.tools {
  scroll-margin-top: calc(var(--topbar-h) + 12px);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 2px 2px 14px;
}

.section-head-text h2 {
  font-size: 19px;
  letter-spacing: -0.012em;
}

.section-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.filter:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.filter.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

.filter-n {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.65;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 172px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  text-align: left;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

a.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-title {
  margin-top: 3px;
  font-size: 15px;
  letter-spacing: -0.004em;
}

.card-desc {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12.5px;
  line-height: 1.68;
  color: var(--muted);
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}

.card-cat {
  font-size: 11.5px;
  color: var(--muted);
}

.card-go {
  margin-left: auto;
  color: var(--line-strong);
  transition: color 0.16s ease, transform 0.16s ease;
}

.card-go .i {
  width: 16px;
  height: 16px;
}

a.card:hover .card-go {
  color: var(--accent);
  transform: translate(1px, -1px);
}

.card.is-planned {
  border-style: dashed;
  background: var(--surface-2);
  cursor: default;
}

.card.is-planned .card-title {
  color: var(--ink-2);
}

.card.is-planned .tile {
  opacity: 0.8;
}

.card.is-planned:hover {
  border-color: var(--line-strong);
}

.card.is-planned .badge {
  margin-left: auto;
}

.empty {
  grid-column: 1 / -1;
  padding: 34px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---------- 页脚 / 提示 ---------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
}

.foot p:last-child {
  margin-left: auto;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 28px;
  max-width: min(92vw, 460px);
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 12px;
  background: #101725;
  color: #f4f7ff;
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
}

.toast[hidden] {
  display: none;
}

html[data-theme="dark"] .toast {
  background: #e9eef8;
  color: #101725;
}

/* ---------- 窄屏 ---------- */

@media (max-width: 1080px) {
  .hero {
    grid-template-columns: minmax(0, 1fr) 296px;
    gap: 22px;
    padding: 28px 26px 26px;
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: static;
    display: block;
    height: auto;
    overflow: visible;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail-title,
  .rail-sep,
  .rail-foot {
    display: none;
  }

  .rail-nav {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .rail-item {
    width: auto;
    padding: 7px 12px;
    border: 1px solid var(--line);
    white-space: nowrap;
  }

  .rail-count {
    margin-left: 2px;
  }

  .main {
    padding: 18px 16px 36px;
    gap: 18px;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    padding: 24px 20px;
    border-radius: 16px;
  }

  .hero-sub {
    max-width: none;
  }

  .cmd-wrap {
    max-width: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 0 14px;
    gap: 8px;
  }

  .brand-sub,
  .search-trigger-label,
  .search-trigger .kbd-hint {
    display: none;
  }

  .search-trigger {
    padding: 0 10px;
    gap: 6px;
  }

  .hero h1 {
    font-size: 29px;
  }

  .hero-sub {
    font-size: 13.5px;
  }

  .cmd {
    height: 50px;
    padding-left: 13px;
  }

  .cmd-kbd {
    display: none;
  }

  .cmd-go {
    height: 38px;
    padding: 0 15px;
    font-size: 13.5px;
  }

  .grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .foot p:last-child {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition-duration: 0.01ms !important;
  }

  a.card:hover {
    transform: none;
  }
}
