/* ===== URL 编码解码工具 样式（独立一份；色板与科研导航站、RegexLab、WorldTime 一致） =====
   ① 顶栏/卡片/按钮/深浅主题与全站同一套变量，保证与主站入口观感一致。
   ② 模式与操作是两组分段按钮；原文/结果是等高的 monospace 文本区。
   ③ 编码对照表与历史记录是数据驱动列表，窄屏自动换行。 */
:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-hover: #f0f2f5;
  --text: #2c3e50;
  --text-sub: #7f8c9b;
  --border: #e8ebef;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, .1);
  --accent-text: #fff;
  --danger: #e2544d;
  --ok: #2f9e5f;
  --shadow: 0 2px 8px rgba(30, 40, 60, .06);
  --bar-bg: #f7f8fa;
  --code-bg: #f4f6f9;
  --tag-bg: #eef2f7;
  --warn-bg: rgba(250, 204, 21, .22);
  --esc: #c0563f;
}

html[data-theme="dark"] {
  --bg: #060a17;
  --bg-card: #0d1424;
  --bg-hover: #1a2336;
  --text: #dce3ec;
  --text-sub: #8794a8;
  --border: #1e2a44;
  --accent: #4d94ff;
  --accent-soft: rgba(77, 148, 255, .16);
  --accent-text: #fff;
  --danger: #ff6b64;
  --ok: #4ade80;
  --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  --bar-bg: #0a1120;
  --code-bg: #101a30;
  --tag-bg: #16213a;
  --warn-bg: rgba(250, 204, 21, .22);
  --esc: #f2a396;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
  font-variant-numeric: tabular-nums;
  transition: background .25s, color .25s;
}
.mono, .box, .frag, .map-code code, .hist-out code {
  font-family: "Cascadia Code", "Consolas", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* ===== 顶栏（全站统一骨架） ===== */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar .back { color: var(--accent); text-decoration: none; font-size: 14px; white-space: nowrap; }
.topbar .back:hover { text-decoration: underline; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { min-width: 0; overflow: hidden; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; flex: none; }
.brand-mark img { width: 26px; height: 26px; }
.brand-text h1 { font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text p { font-size: 12px; color: var(--text-sub); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-btn {
  border: none; background: var(--bg-card); color: var(--text-sub);
  padding: 6px 10px; font-size: 13px; cursor: pointer; text-decoration: none;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn.active { background: var(--accent); color: var(--accent-text); }

/* ===== 主体 ===== */
.main { max-width: 1060px; margin: 0 auto; padding: 16px 16px 4px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px 16px 18px; margin-bottom: 14px; min-width: 0;
}
.card h2 { font-size: 17px; margin: 2px 0 8px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.hint { font-size: 13px; color: var(--text-sub); margin-bottom: 12px; }

/* ===== 模式 / 操作 分段按钮 ===== */
.seg-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg-label { font-size: 13px; color: var(--text-sub); font-weight: 600; }
.seg {
  display: flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; flex-wrap: wrap;
}
.seg-btn {
  border: none; background: var(--bg-card); color: var(--text);
  padding: 8px 14px; font-size: 13.5px; cursor: pointer; font-family: inherit; line-height: 1.35;
  display: flex; flex-direction: column; gap: 1px; text-align: left;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn small { font-size: 11px; color: var(--text-sub); font-weight: 400; }
.seg-btn:hover { background: var(--bg-hover); }
.seg-btn.active { background: var(--accent-soft); color: var(--accent); }
.seg-btn.active small { color: var(--accent); opacity: .85; }
.op-seg .seg-btn { flex-direction: row; align-items: center; gap: 6px; }

/* ===== 文本区 ===== */
.box {
  width: 100%; min-height: 132px; resize: vertical;
  border: 1px solid var(--border); background: var(--code-bg); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.7;
  tab-size: 4; overflow-wrap: break-word; word-break: break-word;
}
.box:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.box.bad { border-color: var(--danger); }
.box[readonly] { background: var(--bg-card); }
.stats { margin-top: 8px; font-size: 12.5px; color: var(--text-sub); min-height: 1.5em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stats b { color: var(--accent); font-weight: 600; }
.stats .err { color: var(--danger); }

/* ===== 通用按钮 ===== */
.mini {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-sub);
  border-radius: 6px; padding: 2px 8px; font-size: 11.5px; cursor: pointer; font-family: inherit;
}
.mini:hover { background: var(--bg-hover); color: var(--text); }
.mini.primary { color: var(--accent); border-color: var(--accent); }
.mini.primary:hover { background: var(--accent-soft); }

/* ===== 编码对照表 ===== */
.map-list { display: flex; flex-direction: column; gap: 6px; }
.map-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; background: var(--bg-card);
}
.map-char {
  font-size: 15px; font-weight: 700; min-width: 2.2em; text-align: center;
  background: var(--tag-bg); border-radius: 7px; padding: 1px 8px; color: var(--text);
}
.map-arrow { color: var(--text-sub); font-size: 13px; }
.map-code { color: var(--esc); font-size: 13px; min-width: 0; word-break: break-all; flex: 0 1 auto; }
.map-bytes { margin-left: auto; font-size: 11.5px; color: var(--text-sub); white-space: nowrap; }
.map-none { font-size: 13px; color: var(--text-sub); }

/* ===== 历史记录 ===== */
.hist-list { display: flex; flex-direction: column; gap: 8px; }
.hist-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  background: var(--bg-card); cursor: pointer; transition: border-color .15s;
}
.hist-item:hover { border-color: var(--accent); }
.hist-tag {
  display: inline-block; font-size: 11px; line-height: 1.4; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); margin-right: 8px; vertical-align: 1px;
}
.hist-time { font-size: 11px; color: var(--text-sub); }
.hist-body { display: flex; gap: 10px; margin-top: 5px; min-width: 0; }
.hist-col { flex: 1 1 50%; min-width: 0; }
.hist-col .lbl { font-size: 11px; color: var(--text-sub); }
.hist-col code {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 12.5px; color: var(--text); background: var(--code-bg);
  border-radius: 6px; padding: 2px 8px; margin-top: 1px;
}
.hist-empty { font-size: 13px; color: var(--text-sub); }

/* ===== 底部说明 ===== */
.doc { margin: 22px 0 34px; }
.doc h2 { font-size: 17px; margin: 20px 0 8px; }
.doc p, .doc li, .doc dd { font-size: 14px; color: var(--text); }
.doc ul { padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc dl { padding-left: 2px; }
.doc dl dt { font-weight: 600; margin: 10px 0 2px; }
.doc dl dd { margin: 0 0 4px; }
.doc .ver { margin-top: 26px; font-size: 12.5px; color: var(--text-sub); }
.rel-links { list-style: none; padding-left: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.rel-links a { color: var(--accent); text-decoration: none; font-size: 14px; }
.rel-links a:hover { text-decoration: underline; }

/* ===== toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(16px);
  background: var(--text); color: var(--bg-card); font-size: 13.5px;
  padding: 9px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 100; box-shadow: 0 6px 22px rgba(0,0,0,.28);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .hist-body { flex-direction: column; gap: 4px; }
  .map-bytes { margin-left: 0; }
}