/* 文本排序 · tso- 前缀，颜色全部走全站变量，日/夜模式自动跟随 */
.tso-app {
  --tso-primary: var(--blue, #1677ff);
  --tso-soft: var(--blue-soft, #e8f1ff);
  --tso-green: var(--green, #00b42a);
  width: 100%;
  color: var(--text, #1d2129);
  font-size: 14px;
  line-height: 1.6;
}
.tso-app * { box-sizing: border-box; }
.tso-app button,
.tso-app textarea,
.tso-app input { font-family: inherit; }

.tso-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 12px;
  background: var(--bg-2, #f7f8fa);
}
.tso-modes {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 9px;
  background: var(--card, #fff);
  overflow: hidden;
}
.tso-mode {
  height: 30px;
  padding: 0 16px;
  border: 0;
  border-right: 1px solid var(--border, #e5e6eb);
  background: transparent;
  color: var(--text-2, #4e5969);
  font-size: 13px;
  line-height: 30px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .16s, background .16s;
}
.tso-mode:last-child { border-right: 0; }
.tso-mode:hover:not(.tso-mode-on) { color: var(--tso-primary, #1677ff); background: var(--tso-soft, #e8f1ff); }
.tso-mode.tso-mode-on {
  background: var(--tso-primary, #1677ff);
  color: #fff;
  font-weight: 600;
}

/* ---------- 选项条 ---------- */
.tso-opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin: 10px 0 0;
  padding: 8px 6px 0;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 12px;
  background: var(--bg-2, #f7f8fa);
}
.tso-opt { display: flex; align-items: center; margin: 0 6px 8px; }
.tso-check {
  display: inline-flex;
  align-items: center;
  height: 30px;
  color: var(--text-2, #4e5969);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.tso-check input {
  width: 15px;
  height: 15px;
  margin: 0 6px 0 0;
  accent-color: var(--tso-primary, #1677ff);
  cursor: pointer;
}

/* ---------- 按钮 ---------- */
.tso-btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 7px;
  background: var(--card, #fff);
  color: var(--text-2, #4e5969);
  font-size: 13px;
  line-height: 30px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .16s, border-color .16s, background .16s, box-shadow .16s;
}
.tso-btn:hover:not(:disabled) {
  color: var(--tso-primary, #1677ff);
  border-color: var(--tso-primary, #1677ff);
  background: var(--tso-soft, #e8f1ff);
}
.tso-btn:disabled { opacity: .45; cursor: not-allowed; }
.tso-btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-3, #86909c);
}
.tso-btn-ghost:hover:not(:disabled) { background: var(--tso-soft, #e8f1ff); }
.tso-btn:focus-visible,
.tso-mode:focus-visible,
.tso-check input:focus-visible,
.tso-help summary:focus-visible {
  outline: 2px solid var(--tso-primary, #1677ff);
  outline-offset: 2px;
}

/* ---------- 工作区 ---------- */
.tso-work { display: flex; align-items: stretch; margin-top: 12px; }
.tso-panel {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 12px;
  background: var(--card, #fff);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
  overflow: hidden;
}
.tso-mid {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tso-mid-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px dashed var(--border-2, #c9cdd4);
  border-radius: 50%;
  background: var(--card, #fff);
  color: var(--text-3, #86909c);
}
.tso-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  min-height: 44px;
  padding: 8px 12px 8px 14px;
  border-bottom: 1px solid var(--border, #e5e6eb);
  background: var(--bg-2, #f7f8fa);
}
.tso-panel-title {
  display: inline-flex;
  align-items: center;
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text, #1d2129);
  cursor: default;
}
.tso-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--tso-primary, #1677ff);
  flex: none;
}
.tso-dot-green { background: var(--tso-green, #00b42a); }
.tso-tools { display: flex; align-items: center; margin-left: auto; }
.tso-tools .tso-btn { margin-left: 6px; }

.tso-reshuffle {
  height: 26px;
  margin: 0 4px 8px auto;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text-3, #86909c);
  font-size: 12.5px;
  line-height: 26px;
  cursor: pointer;
  white-space: nowrap;
}
.tso-reshuffle:hover:not(:disabled) { color: var(--tso-primary, #1677ff); }
.tso-reshuffle:disabled { opacity: .4; cursor: default; }

.tso-textarea {
  display: block;
  width: 100%;
  height: 320px;
  min-height: 200px;
  max-height: 58vh;
  margin: 0;
  padding: 14px 16px;
  border: 0;
  border-radius: 0;
  background: var(--bg-input, #fff);
  color: var(--text, #1d2129);
  font-size: 14px;
  line-height: 1.8;
  resize: vertical;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.tso-textarea::placeholder { color: var(--text-3, #86909c); }
.tso-textarea:focus { box-shadow: inset 0 0 0 2px rgba(22, 119, 255, .14); }
.tso-out {
  background: var(--bg-3, #f0f1f5);
  color: var(--text-2, #4e5969);
  cursor: default;
}
.tso-out:focus { box-shadow: inset 0 0 0 2px rgba(22, 119, 255, .1); }

.tso-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  min-height: 34px;
  padding: 7px 14px;
  border-top: 1px solid var(--border, #e5e6eb);
  background: var(--bg-2, #f7f8fa);
  color: var(--text-3, #86909c);
  font-size: 12px;
}
.tso-hint { margin-left: 12px; color: var(--text-3, #86909c); }

/* ---------- 状态与说明 ---------- */
.tso-status {
  min-height: 36px;
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px dashed var(--border, #e5e6eb);
  border-radius: 9px;
  background: var(--bg-2, #f7f8fa);
  color: var(--text-3, #86909c);
  font-size: 12.5px;
  line-height: 1.6;
  transition: color .16s, border-color .16s, background .16s;
}
.tso-status.is-active {
  color: var(--tso-primary, #1677ff);
  border-color: var(--tso-primary, #1677ff);
  background: var(--tso-soft, #e8f1ff);
}
.tso-status.is-done {
  color: var(--tso-green, #00b42a);
  border-color: var(--border, #e5e6eb);
  background: var(--bg-2, #f7f8fa);
}

.tso-help {
  margin-top: 12px;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 10px;
  background: var(--card, #fff);
  overflow: hidden;
}
.tso-help summary {
  position: relative;
  padding: 11px 38px 11px 14px;
  color: var(--text-2, #4e5969);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.tso-help summary::-webkit-details-marker { display: none; }
.tso-help summary::after {
  content: "+";
  position: absolute;
  right: 14px;
  top: 50%;
  margin-top: -10px;
  width: 20px;
  height: 20px;
  line-height: 18px;
  text-align: center;
  border: 1px solid var(--border, #e5e6eb);
  border-radius: 50%;
  color: var(--text-3, #86909c);
  font-size: 15px;
  font-weight: 400;
}
.tso-help[open] summary::after { content: "−"; }
.tso-help-body {
  padding: 0 14px 13px;
  border-top: 1px solid var(--border, #e5e6eb);
  color: var(--text-2, #4e5969);
  font-size: 13px;
  line-height: 1.85;
}
.tso-help-body p { margin: 9px 0 0; }
.tso-help-body b { color: var(--text, #1d2129); }
.tso-help-body code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-code, #f5f5f5);
  color: var(--text, #1d2129);
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 12.5px;
}
.tso-help-note {
  margin-top: 12px !important;
  padding-top: 10px;
  border-top: 1px dashed var(--border, #e5e6eb);
  color: var(--text-3, #86909c) !important;
  font-size: 12.5px;
}

/* 复制失败时的临时选区，不放页面上 */
.tso-sr {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- 暗色补充：只补写死的底色/阴影 ---------- */
body.dark .tso-app { color-scheme: dark; }
body.dark .tso-panel { box-shadow: 0 2px 12px rgba(0, 0, 0, .22); }
body.dark .tso-textarea:focus { box-shadow: inset 0 0 0 2px rgba(96, 165, 250, .22); }
body.dark .tso-out:focus { box-shadow: inset 0 0 0 2px rgba(96, 165, 250, .16); }
body.dark .tso-status.is-active { background: rgba(30, 58, 95, .55); }
body.dark .tso-mid-icon { background: var(--bg-2, #1a2332); }

/* ---------- 手机 ---------- */
@media screen and (max-width: 760px) {
  .tso-bar { padding: 10px 10px; }
  .tso-modes { width: 100%; margin-bottom: 8px; }
  .tso-mode { flex: 1 1 0; padding: 0 6px; text-align: center; }
  .tso-opts { margin: 8px 0 0; padding: 8px 8px 0; }
  .tso-opt { flex: 0 0 50%; width: 50%; margin: 0 0 8px; padding-right: 4px; }
  .tso-work { flex-direction: column; }
  .tso-panel { flex: 0 0 auto; width: 100%; }
  .tso-mid { flex: 0 0 auto; height: 38px; }
  .tso-mid-icon svg { transform: rotate(90deg); }
  .tso-textarea { height: 220px; min-height: 160px; max-height: none; }
  .tso-panel-head { padding: 8px 10px 8px 12px; }
  .tso-panel-foot { padding: 7px 12px; }
  .tso-hint { display: none; }
  .tso-help-body { font-size: 12.5px; }
}

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