/* ============ 速用工具箱 样式 ============ */
:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-soft: #EEF2FF;
  --success: #16A34A;
  --danger: #DC2626;
  --warning: #D97706;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="light"] {
  --bg: #F5F6FA;
  --card: #FFFFFF;
  --text: #1F2937;
  --text-2: #6B7280;
  --border: #E5E7EB;
  --hover: #F3F4F6;
  --code-bg: #F9FAFB;
  --toast-bg: #111827;
  --toast-text: #F9FAFB;
}

:root[data-theme="dark"] {
  --bg: #0F1420;
  --card: #1B2333;
  --text: #F3F4F6;
  --text-2: #9CA3AF;
  --border: #2E3A4E;
  --hover: #223049;
  --code-bg: #141B28;
  --toast-bg: #E5E7EB;
  --toast-text: #111827;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .2s, color .2s;
}

/* ---- Header ---- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 18px; font-weight: 700; color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.brand .brand-icon { font-size: 22px; }
.search-wrap { flex: 1; max-width: 420px; margin: 0 auto; }
.search-wrap input {
  width: 100%; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--code-bg); color: var(--text);
  font-size: 14px; outline: none;
}
.search-wrap input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
#theme-toggle {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 17px; cursor: pointer; flex-shrink: 0;
}
#theme-toggle:hover { background: var(--hover); }

/* ---- Main / Layout ---- */
.main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 20px 40px; }
.container { max-width: 1000px; margin: 0 auto; }

/* ---- Home: category + cards ---- */
.category-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--text-2);
  margin: 28px 0 12px; text-transform: uppercase; letter-spacing: .5px;
}
.category-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.tool-card {
  display: block; text-decoration: none;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.tool-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.1); border-color: var(--primary); }
.tool-card .tc-icon { font-size: 28px; line-height: 1; }
.tool-card .tc-name { font-weight: 600; margin: 10px 0 4px; color: var(--text); font-size: 15px; }
.tool-card .tc-desc { font-size: 12.5px; color: var(--text-2); margin: 0; }
.empty-tip { text-align: center; color: var(--text-2); padding: 48px 0; }

/* ---- Tool page ---- */
.tool-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.back-btn {
  text-decoration: none; color: var(--text-2); font-size: 14px;
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
}
.back-btn:hover { background: var(--hover); color: var(--text); }
.tool-head h1 { font-size: 22px; margin: 0; }
.tool-head .th-icon { font-size: 26px; }
.tool-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start;
}
.tool-panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.tool-panel h2 { font-size: 14px; color: var(--text-2); margin: 0 0 14px; font-weight: 600; }
@media (max-width: 820px) {
  .tool-layout { grid-template-columns: 1fr; }
}

/* ---- Form controls ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-2); margin-top: 4px; }
textarea, input[type="text"], input[type="number"], input[type="url"], input[type="password"], input[type="search"], select {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--code-bg); color: var(--text); font-size: 14px; outline: none;
  font-family: inherit;
}
textarea:focus, input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
textarea { resize: vertical; min-height: 120px; font-family: var(--font-mono); line-height: 1.5; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, transform .05s; user-select: none;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  transition: .2s; cursor: pointer;
}
.switch .slider::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }

/* upload zone */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 16px; text-align: center; cursor: pointer;
  color: var(--text-2); font-size: 14px; transition: border-color .15s, background .15s;
  background: var(--code-bg);
}
.upload-zone:hover, .upload-zone.drag { border-color: var(--primary); background: var(--primary-soft); }
.upload-zone .uz-icon { font-size: 30px; display: block; margin-bottom: 8px; }
.upload-zone input[type="file"] { display: none; }

/* result area */
.result-box {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; margin-top: 12px;
  font-family: var(--font-mono); font-size: 13px; white-space: pre-wrap; word-break: break-all;
  max-height: 340px; overflow: auto;
}
.result-img { max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; margin: 10px auto 0; }
.stat-line { font-size: 13px; color: var(--text-2); margin-top: 8px; }
.stat-line b { color: var(--primary); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }
.good-text { color: var(--success); font-size: 13px; margin-top: 8px; }

/* chip list (敏感词命中) */
.chip { display: inline-block; background: #FEE2E2; color: #B91C1C; border-radius: 6px; padding: 2px 8px; font-size: 12px; margin: 3px 4px 0 0; }

/* regex highlight */
.hl-match { background: #FEF08A; color: #713F12; border-radius: 2px; padding: 0 1px; }
:root[data-theme="dark"] .hl-match { background: #F59E0B; color: #111827; }

/* nine-grid preview */
.grid-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; background: var(--border); padding: 2px; border-radius: var(--radius-sm); margin-top: 12px; }
.grid-preview img { width: 100%; display: block; }

/* ascii preview */
.ascii-pre { font-family: var(--font-mono); font-size: 8px; line-height: 1; letter-spacing: 0; white-space: pre; overflow: auto; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; max-height: 400px; }
.ascii-pre.darkbg { background: #0B0F19; color: #E5E7EB; }
.ascii-pre.lightbg { background: #fff; color: #111; }

/* toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg); color: var(--toast-text);
  padding: 10px 20px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 100;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* footer */
.site-footer { padding: 20px; text-align: center; color: var(--text-2); font-size: 12.5px; border-top: 1px solid var(--border); }
.site-footer .footer-links { margin-top: 6px; }

/* progress bar */
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 10px; display: none; }
.progress.show { display: block; }
.progress .bar { height: 100%; width: 0%; background: var(--primary); transition: width .15s; }

/* ---- 结果卡片 / 图片网格 ---- */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.img-card {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; display: flex; flex-direction: column;
}
.img-card .ic-prev { position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden; background: #fff; cursor: zoom-in; }
.img-card .ic-prev img { width: 100%; height: 100%; object-fit: contain; display: block; }
.img-card .ic-name { padding: 6px 8px 2px; font-size: 12px; color: var(--text); word-break: break-all; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.img-card .ic-meta { padding: 0 8px 6px; font-size: 11px; color: var(--text-2); }
.img-card .ic-meta b { color: var(--primary); }
.img-card .ic-meta .saved { color: var(--success); }
.img-card .ic-meta .grew { color: var(--warning); }
.img-card .ic-actions { display: flex; gap: 6px; padding: 0 8px 8px; }
.img-card .ic-actions .btn { flex: 1; }
.img-card .ic-badge { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.55); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 4px; }

/* ---- 灯箱 ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.72);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 12px;
}
.lb-bar { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 900px; }
.lb-title { flex: 1; color: #fff; font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lightbox .btn { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.35); }
.lightbox .btn:hover { background: rgba(255,255,255,.28); }
.lb-img { max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }

/* ---- 文件夹上传 ---- */
.upload-hint { font-size: 12px; color: var(--text-2); margin-top: 6px; }

/* ---- 拼图画布 ---- */
.puzzle-wrap { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.puzzle-shelf {
  width: 200px; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
}
.puzzle-shelf .shelf-title { width: 100%; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.puzzle-canvas-wrap { flex: 1; min-width: 320px; }
.puzzle-canvas {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  position: relative; overflow: hidden; touch-action: none;
}
.puzzle-canvas .pz-grid-line { position: absolute; background: rgba(79,70,229,.12); pointer-events: none; }
.puzzle-canvas .pz-cell { position: absolute; box-shadow: 0 1px 6px rgba(0,0,0,.25); cursor: grab; background:#fff; border:1px solid rgba(0,0,0,.1); }
.puzzle-canvas .pz-cell.dragging { cursor: grabbing; z-index: 5; }
.puzzle-canvas .pz-cell:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
.puzzle-cell-img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; display:block; }
.puzzle-tools { margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.puzzle-shelf img { width: 88px; height: 88px; object-fit: cover; border: 1px solid var(--border); border-radius: 6px; cursor: grab; background:#fff; }
.puzzle-shelf img:hover { outline: 2px solid var(--primary); outline-offset: -2px; }

/* NxN 切图预览 */
.grid-n-preview { display: grid; gap: 2px; background: var(--border); padding: 2px; border-radius: var(--radius-sm); margin-top: 12px; }
.grid-n-preview img { width: 100%; display: block; }
