/* ---------- tokens ---------- */
:root {
  --bg: #f6f7fb;
  --bg-soft: #eef0f7;
  --card: #ffffff;
  --card-2: #fafbff;
  --border: #e4e7f0;
  --text: #1b1f2a;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --accent-text: #ffffff;
  --ok: #12855f;
  --err: #c02626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

html[data-theme="dark"] {
  --bg: #0e1117;
  --bg-soft: #141924;
  --card: #161c27;
  --card-2: #1a2130;
  --border: #26303f;
  --text: #e7ecf3;
  --muted: #93a0b4;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.14);
  --accent-text: #0e1117;
  --ok: #34d399;
  --err: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0e1117;
    --bg-soft: #141924;
    --card: #161c27;
    --card-2: #1a2130;
    --border: #26303f;
    --text: #e7ecf3;
    --muted: #93a0b4;
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.14);
    --accent-text: #0e1117;
    --ok: #34d399;
    --err: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: auto; height: 34px; }
.logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #22d3ee);
  display: grid; align-content: center; justify-items: center; gap: 4px;
  box-shadow: 0 6px 16px var(--accent-soft);
}
.logo i { display: block; height: 3px; border-radius: 2px; background: #fff; opacity: 0.95; }
.logo i:nth-child(1) { width: 18px; }
.logo i:nth-child(2) { width: 13px; }
.logo i:nth-child(3) { width: 16px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; letter-spacing: 0.2px; }
.brand-text span { font-size: 12px; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.pill {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: 0.18s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 63px);
}

.sidebar {
  padding: 18px 14px 18px 18px;
  border-right: 1px solid var(--border);
  background: var(--card-2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
}
.search input {
  border: 0; outline: 0; background: transparent; color: var(--text);
  width: 100%; font-size: 14px;
}

#tool-nav { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.nav-group-title {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 2px 6px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  border: 1px solid transparent;
  transition: 0.15s;
  width: 100%;
  background: transparent;
  text-align: left;
  font: inherit;
}
.nav-item:hover { background: var(--bg-soft); }
.nav-item .badge {
  flex: 0 0 28px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}
.nav-item .label { font-size: 14px; }
.nav-item .hint { display: block; font-size: 11px; color: var(--muted); }
.nav-item[aria-current="true"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.nav-item[aria-current="true"] .badge { background: var(--accent); color: var(--accent-text); }
.nav-item[aria-current="true"] .hint { color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  display: flex; gap: 6px; align-items: center;
  font-size: 11px; color: var(--muted); padding: 6px;
}

main { padding: 26px 30px 40px; max-width: 1180px; width: 100%; }

/* ---------- tool ---------- */
.tool { animation: rise 0.25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.tool-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 16px;
}
.tool-head h2 { margin: 0 0 3px; font-size: 22px; letter-spacing: 0.2px; }
.tool-head p { margin: 0; color: var(--muted); font-size: 13.5px; }
.chip {
  font-size: 11.5px; color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.pane {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 14px;
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--card-2);
  min-height: 40px;
}
.actions { display: flex; gap: 6px; }

.io {
  width: 100%;
  min-height: 190px;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  outline: 0;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
}
textarea.io { display: block; }
pre.io { overflow: auto; }
.io.tall { min-height: 230px; }
.io:focus { background: color-mix(in srgb, var(--accent) 4%, transparent); }

.row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  margin: 4px 0 16px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: 0.16s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 6px 16px var(--accent-soft);
}
.btn.primary:hover { filter: brightness(1.06); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; }
.btn.ghost:hover { background: var(--accent-soft); color: var(--accent); }
.file-btn { position: relative; overflow: hidden; }

.input {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
  font: inherit;
  font-size: 13.5px;
  outline: 0;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grow { flex: 1 1 320px; min-width: 200px; }
.tiny { width: 70px; }
.flags { width: 78px; }
.slash { color: var(--muted); font-size: 18px; }
.mono { font-family: var(--mono); }

.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

.status { font-size: 12.5px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.kv {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}
.kv span { font-size: 11.5px; color: var(--muted); }
.kv b { font-size: 14px; font-weight: 600; word-break: break-all; }

.params { display: grid; gap: 8px; margin-bottom: 16px; }
.param {
  display: grid; grid-template-columns: minmax(120px, 220px) 1fr;
  gap: 10px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card);
  font-family: var(--mono); font-size: 12.5px;
}
.param span:first-child { color: var(--accent); word-break: break-all; }
.param span:last-child { color: var(--text); word-break: break-all; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.stat {
  border: 1px solid var(--border); border-radius: 12px; background: var(--card);
  padding: 14px; display: flex; flex-direction: column; gap: 2px;
}
.stat b { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.color-input {
  width: 46px; height: 38px; padding: 2px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); cursor: pointer;
}
.color-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
.color-preview {
  border-radius: var(--radius);
  min-height: 190px;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 16px;
  box-shadow: var(--shadow);
  transition: background 0.2s;
}
.color-preview span { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }

.matches { display: grid; gap: 6px; padding: 10px 12px; max-height: 260px; overflow: auto; }
.match {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 9px; border-radius: 8px; background: var(--bg-soft);
  font-family: var(--mono); font-size: 12.5px; word-break: break-all;
}
.match .idx { color: var(--muted); flex: 0 0 auto; }
.match mark, #re-highlight mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 2px; }
.empty { color: var(--muted); font-size: 13px; padding: 12px; }

.io.bare {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.strength { height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; margin: 4px 0 8px; }
.strength-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.25s, background 0.25s; }

.foot {
  margin-top: 34px; padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  font-size: 12px; color: var(--muted);
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translate(-50%, 16px);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: 0.22s; z-index: 50;
}
.toast.show { opacity: 0.96; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 12px 12px; gap: 10px; }
  .search { padding: 6px 10px; }
  #tool-nav { flex-direction: row; overflow-x: auto; gap: 8px; padding-bottom: 2px; }
  .nav-group { display: contents; }
  .nav-group-title { display: none; }
  .nav-item { width: auto; flex: 0 0 auto; padding: 6px 10px; border: 1px solid var(--border); background: var(--card); }
  .nav-item .hint { display: none; }
  .nav-item .badge { width: 22px; height: 22px; flex-basis: 22px; border-radius: 6px; }
  .nav-item .label { font-size: 13px; }
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 20px 16px 32px; }
  .color-layout { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
  .brand-text span { display: none; }
  .foot { flex-direction: column; }
}

/* ---------- media tool ---------- */
.media-preview {
  margin-top: 10px;
  min-height: 220px;
  display: grid;
  place-items: center;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.media-preview-el { max-width: 100%; max-height: 320px; display: block; }
.media-empty { font-size: 12.5px; color: var(--muted); }
.media-opts { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 10px; }
.media-opts label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.media-opts input { width: 84px; }
.media-hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.media-note { margin-top: 14px; display: flex; gap: 18px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }

/* ---------- gif slice tool ---------- */
.slice-preview { padding: 10px; }
.slice-stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; }
.slice-stage img { max-width: 100%; max-height: 340px; display: block; border-radius: 8px; }
.slice-lines { position: absolute; inset: 0; pointer-events: none; }
.slice-lines i {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.85) 0 7px, rgba(0, 0, 0, 0) 7px 14px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
}
.media-opts-radios { gap: 16px; }
.media-opts-radios label { cursor: pointer; }
.media-opts input[type="radio"] { width: auto; margin: 0; accent-color: var(--accent); }
.slice-results {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.slice-card {
  margin: 0;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.slice-card img { width: 100%; height: auto; display: block; border-radius: 8px; background: #000; }
.slice-card figcaption {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11.5px; color: var(--muted);
}
.slice-card .btn { text-align: center; }

.icp {
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
}
.icp:hover { color: var(--text); }
