:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #5b6478;
  --border: #e2e6ef;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef0ff;
  --kept-bg: #dcfce7;
  --kept-text: #14532d;
  --drop-bg: #fee2e2;
  --drop-text: #9f1239;
  --code-bg: #f3f4f8;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --panel: #121826;
    --text: #e5e7ef;
    --muted: #98a1b6;
    --border: #253047;
    --accent: #818cf8;
    --accent-strong: #a5b4fc;
    --accent-soft: #1e2140;
    --kept-bg: #123524;
    --kept-text: #bbf7d0;
    --drop-bg: #3a1620;
    --drop-text: #fda4af;
    --code-bg: #0e1422;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "Noto Sans CJK SC", "PingFang SC", "Hiragino Sans", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.86em; background: var(--code-bg); padding: 0.05em 0.35em; border-radius: 5px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 40px; }

/* Header */
.hero { margin-bottom: 18px; }
.brand { margin: 0 0 6px; font-size: 0.8rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
.brand a { color: var(--muted); }
h1 { font-size: clamp(1.7rem, 3.5vw, 2.25rem); line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.02em; }
.lede { font-size: 1.04rem; color: var(--muted); max-width: 780px; margin: 0 0 12px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0 0 12px; }
.pills li { font-size: 0.8rem; padding: 3px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); }
.pills li.hl { border-color: transparent; background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.links { margin: 0; font-size: 0.93rem; }
.links .sep { color: var(--muted); margin: 0 6px; }

/* Status */
.status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding: 10px 14px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); font-size: 0.9rem; }
.status-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #f59e0b; flex: none; }
.status[data-state="ready"] .dot { background: #22c55e; }
.status[data-state="error"] .dot { background: #ef4444; }
.status[data-state="idle"] .dot { background: var(--muted); }
#status-detail { color: var(--muted); }
.bar { flex: 1 1 160px; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; min-width: 120px; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }
.status[data-state="ready"] .bar, .status[data-state="error"] .bar, .status[data-state="idle"] .bar { display: none; }
.privacy { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-left: auto; font-size: 0.85rem; }
.privacy svg { flex: none; }

/* Layout */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } .privacy { margin-left: 0; } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel + .panel { margin-top: 16px; }
.grid .panel + .panel { margin-top: 0; }
.grid .panel { display: flex; flex-direction: column; }
#output { flex: 1 1 auto; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; min-height: 30px; }
.label { font-weight: 650; font-size: 0.92rem; }
.hint { margin: 2px 0 0; font-size: 0.8rem; color: var(--muted); }

textarea {
  width: 100%; resize: vertical; min-height: 220px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 0.94rem; line-height: 1.55;
}
textarea:focus, input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#output { background: var(--panel); }

.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 14px; }
.examples .mini { font-size: 0.78rem; color: var(--muted); margin-right: 2px; }
.chip { font: inherit; font-size: 0.8rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

.control { margin-bottom: 12px; }
.control .label-row { margin-bottom: 2px; min-height: 0; }
output { font-family: var(--mono); font-weight: 650; color: var(--accent-strong); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
.checks { display: grid; gap: 8px; margin-bottom: 14px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 0.9rem; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.check small { display: block; color: var(--muted); font-size: 0.78rem; }

button { font: inherit; cursor: pointer; }
button.primary { width: 100%; padding: 10px 16px; border: 0; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 650; }
@media (prefers-color-scheme: dark) { button.primary { color: #0b0f19; } }
button.primary:hover:not(:disabled) { background: var(--accent-strong); }
button.primary:disabled { opacity: 0.55; cursor: progress; }
button.ghost { padding: 4px 12px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text); font-size: 0.82rem; }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
#load-btn { padding: 6px 14px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font-weight: 600; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; background: var(--bg); min-width: 0; }
.stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat-value { font-size: 1.08rem; font-weight: 680; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { font-size: 0.74rem; line-height: 1.35; color: var(--muted); min-height: 1.2em; }
.note { margin: 10px 0 0; font-size: 0.84rem; color: var(--muted); }
.note.warn { color: var(--drop-text); }

/* Highlight */
.legend { display: flex; gap: 8px; font-size: 0.78rem; }
.legend span { padding: 1px 8px; border-radius: 5px; }
.highlight { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; font-size: 0.95rem; min-height: 3em; max-height: 460px; overflow: auto; }
.highlight:empty::before { content: "Kept and dropped words appear here."; color: var(--muted); }
.k { background: var(--kept-bg); color: var(--kept-text); border-radius: 3px; padding: 1px 0; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.d { background: var(--drop-bg); color: var(--drop-text); text-decoration: line-through; text-decoration-thickness: 1px; border-radius: 3px; padding: 1px 0; -webkit-box-decoration-break: clone; box-decoration-break: clone; }

/* Code */
h2 { font-size: 1.1rem; margin: 0 0 6px; }
.code p { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 0; }
.tab { padding: 7px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 0.88rem; font-weight: 600; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.codebox { position: relative; }
.codebox pre { margin: 0; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 9px 9px; overflow-x: auto; font: 0.84rem/1.6 var(--mono); }
.codebox pre code { background: none; padding: 0; font-size: inherit; }
.codebox .ghost { position: absolute; top: 8px; right: 8px; background: var(--panel); }
.code .after { margin: 10px 0 0; font-size: 0.85rem; }
.c-com { color: var(--muted); }

/* Details */
details summary { cursor: pointer; font-weight: 650; }
details ol, details ul { padding-left: 1.3em; margin: 10px 0; }
details li { margin: 4px 0; }
details p { margin: 10px 0; color: var(--muted); }

footer { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 26px; }
footer code { font-size: 0.8em; }

@media (max-width: 520px) {
  .wrap { padding: 20px 16px 32px; }
  .panel { padding: 13px; }
  textarea { min-height: 180px; }
  #input-hint { display: none; }
}
