/* CM Tools —— 克制的专业风格：平色、细边框、极少投影。light / dark / system 三态 */

:root {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --accent: #5558e6;
  --accent-strong: #4245d4;
  --accent-soft: #eef0fd;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --badge-ink: #4f52c9;
  --badge-bg: #eef0fd;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .04);
  --shadow-2: 0 8px 24px rgb(0 0 0 / .10);
  --radius: 12px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1014;
    --surface: #17181d;
    --surface-2: #1f2026;
    --ink: #e7e8ea;
    --muted: #9a9ba3;
    --line: #2a2b33;
    --line-strong: #3a3b45;
    --accent: #7b7eff;
    --accent-strong: #979aff;
    --accent-soft: #24264a;
    --danger: #ef6f66;
    --danger-soft: #3a201d;
    --badge-ink: #aeb0ff;
    --badge-bg: #262848;
    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 8px 24px rgb(0 0 0 / .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1014;
  --surface: #17181d;
  --surface-2: #1f2026;
  --ink: #e7e8ea;
  --muted: #9a9ba3;
  --line: #2a2b33;
  --line-strong: #3a3b45;
  --accent: #7b7eff;
  --accent-strong: #979aff;
  --accent-soft: #24264a;
  --danger: #ef6f66;
  --danger-soft: #3a201d;
  --badge-ink: #aeb0ff;
  --badge-bg: #262848;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-2: 0 8px 24px rgb(0 0 0 / .5);
}

* { box-sizing: border-box; }
/* 显式兜底 [hidden]，防止 display:flex 等覆盖浏览器默认 */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  overflow-x: clip;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto; padding: 11px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: inline-flex; align-items: center; gap: 9px; }
.brand-logo { width: 26px; height: 26px; display: block; }
.brand-name {
  font-family: var(--mono); font-weight: 700; font-size: 14px;
  letter-spacing: .02em; color: var(--ink);
}
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 10px; flex: none; flex-wrap: nowrap; }
.btn-new-tool .btn-plus { font-weight: 600; }

/* ---------- 主题切换 ---------- */
.theme-toggle {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: color .12s, border-color .12s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.theme-toggle svg { width: 16px; height: 16px; display: none; }
html:not([data-theme]) .theme-toggle .ti-system { display: block; }
html[data-theme="light"] .theme-toggle .ti-light { display: block; }
html[data-theme="dark"] .theme-toggle .ti-dark { display: block; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 7px 14px; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; line-height: 1.4;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px; cursor: pointer;
  font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- 头像 ---------- */
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--badge-ink);
  font-weight: 700; font-family: var(--mono); font-size: 13px;
}
.avatar-lg { width: 72px; height: 72px; border-radius: 50%; font-size: 26px; }
.avatar-link { border-radius: 50%; display: block; outline: 1px solid var(--line); outline-offset: 1px; transition: outline-color .12s; }
.avatar-link:hover { outline-color: var(--accent); }

/* ---------- 布局 ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 32px 20px 64px; }
.section { margin-bottom: 44px; }
.section-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.section-head h2 { font-size: 15px; font-weight: 650; margin: 0; }
.section-note { color: var(--muted); font-size: 13px; }
.hero { padding: 36px 0 22px; max-width: 660px; }
.hero h1 { font-size: clamp(24px, 4vw, 34px); letter-spacing: -.02em; font-weight: 700; }
.hero p { color: var(--muted); font-size: 16px; }
.empty {
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; color: var(--muted);
}
.site-footer {
  text-align: center; color: var(--muted); font-family: var(--mono);
  font-size: 12px; padding: 24px 0 36px;
  border-top: 1px solid var(--line);
}

/* ---------- 搜索 ---------- */
.search-wrap {
  position: relative; display: flex; align-items: center;
  width: 100%; margin: 0 0 28px;
}
.search-icon {
  position: absolute; left: 13px; width: 16px; height: 16px;
  color: var(--muted); pointer-events: none;
}
.search-wrap input {
  width: 100%; padding: 9px 72px 9px 38px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 14px;
  transition: border-color .12s, box-shadow .12s;
}
.search-wrap input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.search-wrap input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.search-clear {
  position: absolute; right: 40px; border: none; background: transparent;
  color: var(--muted); width: 24px; height: 24px; border-radius: 6px;
  cursor: pointer; font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.search-clear:hover { background: var(--surface-2); color: var(--ink); }
.search-kbd {
  position: absolute; right: 11px; font-family: var(--mono); font-size: 11px;
  color: var(--muted); border: 1px solid var(--line); border-radius: 5px;
  padding: 0 6px; background: var(--surface-2); pointer-events: none;
}
#search-empty { margin-bottom: 28px; }
@media (hover: none) {
  .search-kbd { display: none; }
  .search-wrap input { padding-right: 38px; }
  .search-clear { right: 9px; }
}

/* ---------- 工具卡片 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(268px, 100%), 1fr));
  gap: 14px;
}
.grid > * { min-width: 0; max-width: 100%; }
.card {
  position: relative;
  display: flex; gap: 13px; align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  min-width: 0;
  transition: border-color .12s, background .12s;
}
.card:hover { border-color: var(--line-strong); }
.card-link { position: absolute; inset: 0; border-radius: var(--radius); z-index: 1; }
.tool-icon {
  width: 44px; height: 44px; border-radius: 10px; flex: none; align-self: flex-start;
  object-fit: contain;
}
.tool-icon-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 18px;
  color: var(--badge-ink); background: var(--accent-soft);
}
.card-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.card-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.card-name {
  font-weight: 600; font-size: 14.5px; transition: color .12s; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge {
  flex: none; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--badge-bg); color: var(--badge-ink); font-weight: 500;
}
.card-desc {
  margin: 3px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55;
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot {
  display: flex; align-items: center; gap: 8px;
  margin-top: auto; padding-top: 8px; min-height: 26px;
}
.card-host {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 11px;
  color: color-mix(in srgb, var(--muted) 80%, transparent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-actions {
  position: relative; z-index: 2; flex: none;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity .12s;
}
.card-actions .icon-btn {
  width: 26px; height: 26px; border-radius: 6px; font-size: 13px;
  border: 1px solid var(--line); background: var(--surface);
}
.card-actions .icon-btn:hover {
  border-color: var(--line-strong); background: var(--surface-2); color: var(--ink);
}
.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }
@media (hover: none) { .card-actions { opacity: 1; } } /* 触屏设备常显 */

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
.field-label { display: block; margin-bottom: 4px; }
.field input, .field textarea {
  display: block; width: 100%; margin-top: 5px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; font: inherit; font-size: 14px; font-weight: 400;
  transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; font-size: 14px; }
.check input { accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.form-error {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 22%, transparent);
  border-radius: 8px; padding: 8px 12px; font-size: 13.5px; margin: 10px 0;
}

/* ---------- 认证页 / 消息页 ---------- */
.auth-card {
  max-width: 400px; margin: 7vh auto 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 30px 28px; box-shadow: var(--shadow-1);
}
.auth-card h1 { font-size: 21px; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin-top: -6px; }
.auth-alt { color: var(--muted); font-size: 13.5px; margin-top: 18px; }
.msg-text { color: var(--muted); margin-bottom: 20px; }
.resend-form { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; }

/* ---------- 账户页 ---------- */
.page-narrow { max-width: 560px; margin: 0 auto; }
.page-narrow h1 { font-size: 22px; }
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.panel h2 { font-size: 14.5px; font-weight: 650; }
.panel-danger { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.kv { display: grid; grid-template-columns: 80px 1fr; gap: 6px 12px; margin: 0 0 16px; }
.kv dt { color: var(--muted); font-size: 13.5px; }
.kv dd { margin: 0; }

/* ---------- 图片选择/裁切 ---------- */
.picker-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.icon-current { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.icon-current.avatar-lg { width: 72px; height: 72px; border-radius: 50%; }
.crop-stage {
  margin-top: 12px; max-height: 340px; overflow: hidden;
  border-radius: 10px; background: var(--surface-2);
}
.crop-stage img { display: block; max-width: 100%; }
.crop-stage .svg-preview { width: 96px; height: 96px; object-fit: contain; margin: 12px; }

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgb(0 0 0 / .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 460px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-2); padding: 20px 22px;
  animation: modal-in .14s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.spacer { flex: 1; }

/* ---------- 管理员排序 ---------- */
.sort-btn { margin-left: auto; }
.sort-list {
  list-style: none; margin: 0 0 4px; padding: 0;
  max-height: 60vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px;
}
.sort-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: var(--surface); cursor: grab;
}
.sort-item:last-child { border-bottom: none; }
.sort-item.dragging { opacity: .5; background: var(--surface-2); cursor: grabbing; }
.sort-item .tool-icon { width: 34px; height: 34px; border-radius: 8px; font-size: 15px; }
.sort-grip { color: var(--muted); cursor: grab; font-size: 14px; line-height: 1; user-select: none; flex: none; }
.sort-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 640px) {
  .topbar-inner { padding: 9px 14px; gap: 8px; }
  .nav { gap: 8px; }
  .btn-new-tool { width: 32px; height: 32px; padding: 0; border-radius: 8px; font-size: 18px; }
  .btn-new-tool .btn-label { display: none; }
  .nav .btn:not(.btn-new-tool) { padding: 6px 11px; font-size: 13px; }
}
@media (max-width: 520px) {
  .container { padding: 22px 14px 48px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { flex-direction: column; gap: 10px; padding: 12px; }
  .card-desc { -webkit-line-clamp: 3; }
  .card-foot { flex-wrap: wrap; row-gap: 4px; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal { max-width: none; border-radius: 0; min-height: 100%; animation: none; }
  .brand-name { display: none; }
  .hero { padding: 20px 0 12px; }
  .hero h1 { overflow-wrap: anywhere; }
  .section-head { gap: 6px 10px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .kv dd { overflow-wrap: anywhere; }
  .auth-card { padding: 24px 18px; margin-top: 3vh; }
}
@media (max-width: 400px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .card { flex-direction: row; gap: 12px; }
  .card-desc { -webkit-line-clamp: 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- 语言切换 ---------- */
.lang-toggle {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); height: 32px; min-width: 32px; padding: 0 7px;
  border-radius: 8px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .12s, border-color .12s;
}
.lang-toggle:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- 顶栏 IP 徽标 ---------- */
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.brand { flex: none; }
.ip-chip {
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--muted); height: 24px; padding: 0 9px;
  border-radius: 999px; cursor: pointer;
  font-family: var(--mono); font-size: 11.5px; line-height: 1;
  display: inline-flex; align-items: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
  flex: 0 1 auto; min-width: 0;
  transition: color .12s, border-color .12s;
}
.ip-chip:hover { color: var(--ink); border-color: var(--line-strong); }
.ip-chip.copied { color: var(--accent-strong); border-color: var(--accent); }
@media (max-width: 520px) { .ip-chip { max-width: 120px; font-size: 11px; padding: 0 7px; } }
@media (max-width: 360px) { .ip-chip { display: none !important; } }
