/* ==========================================================================
   Codec Bench
   Warm paper / graphite instrument panel. Tokens first, components second.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f1eee7;
  --bg-grid: #d9d3c7;
  --surface: #fbf9f4;
  --surface-raised: #fffefb;
  --surface-sunken: #f5f1e9;
  --ink: #17191c;
  --ink-2: #3c3f44;
  --muted: #5d5b55;
  --muted-2: #6f6c65;
  --line: #d5cec0;
  --line-strong: #b6ad9c;

  --accent: #b8370b;
  --accent-hover: #9c2d07;
  --accent-ink: #ffffff;
  --accent-soft: #fae6dc;

  --decode: #0b6672;
  --decode-hover: #08535d;
  --decode-ink: #ffffff;
  --decode-soft: #ddf0f1;

  --ok: #1d6b3b;
  --ok-soft: #e1f1e6;
  --warn: #8a5a12;
  --warn-soft: #f7ecd8;
  --danger: #a11e1e;
  --danger-soft: #fbe7e5;
  --focus: #b8370b;

  --toast-bg: #17191c;
  --toast-ink: #fbf9f4;

  --code-bg: #fffefb;
  --code-gutter-bg: #f5f1e9;
  --code-gutter-ink: #6f6c65;
  --code-tag: #a3370d;
  --code-attr: #0b6672;
  --code-string: #1d6b3b;
  --code-number: #7a4a0c;
  --code-keyword: #8f1d1d;
  --code-comment: #6f6c65;
  --code-punct: #3c3f44;

  --shadow-sm: 0 1px 1px rgba(23, 25, 28, 0.04);
  --shadow: 0 20px 44px -28px rgba(23, 25, 28, 0.48), 0 2px 8px -4px rgba(23, 25, 28, 0.12);

  --font-ui: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --font-mono: "Cascadia Code", "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;

  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 11px;
  --r-pill: 999px;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0e1012;
  --bg-grid: #191c1f;
  --surface: #15181b;
  --surface-raised: #1b1f22;
  --surface-sunken: #101316;
  --ink: #ece9e2;
  --ink-2: #c9c5bc;
  --muted: #a6a29a;
  --muted-2: #918d85;
  --line: #2a2f34;
  --line-strong: #3d444b;

  --accent: #ff7a45;
  --accent-hover: #ff9064;
  --accent-ink: #1c0d07;
  --accent-soft: #2f1a11;

  --decode: #5fd8c9;
  --decode-hover: #7ce4d7;
  --decode-ink: #05201d;
  --decode-soft: #112b28;

  --ok: #72d68e;
  --ok-soft: #12291a;
  --warn: #e5b766;
  --warn-soft: #2b2113;
  --danger: #ff8177;
  --danger-soft: #2c1614;
  --focus: #ff9a6b;

  --toast-bg: #ece9e2;
  --toast-ink: #101214;

  --code-bg: #101316;
  --code-gutter-bg: #15181b;
  --code-gutter-ink: #918d85;
  --code-tag: #ff9a6b;
  --code-attr: #5fd8c9;
  --code-string: #72d68e;
  --code-number: #e5b766;
  --code-keyword: #ff8177;
  --code-comment: #918d85;
  --code-punct: #c9c5bc;

  --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.35);
  --shadow: 0 24px 54px -26px rgba(0, 0, 0, 0.72), 0 2px 10px -4px rgba(0, 0, 0, 0.5);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.28;
  -webkit-mask-image: radial-gradient(circle at 50% -10%, #000 0, transparent 68%);
  mask-image: radial-gradient(circle at 50% -10%, #000 0, transparent 68%);
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

textarea {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

code,
kbd {
  font-family: var(--font-mono);
}

:where(button, a, input, textarea):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

textarea:focus-visible {
  outline: none;
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  text-decoration: none;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.noscript {
  width: min(calc(100% - 40px), 1360px);
  margin: 12px auto;
  padding: 10px 14px;
  border: 1px solid var(--warn);
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- shell ---------- */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(calc(100% - 40px), 1360px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px 0 10px;
}

@media (min-width: 901px) {
  /* 桌面端把编辑器锁在视口内滚动，避免长文本把整页撑高 */
  .app {
    height: 100vh;
    height: 100dvh;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 10px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 var(--accent-hover);
}

.brand-mark .icon {
  width: 22px;
  height: 22px;
  stroke-width: 1.9;
}

.brand-copy {
  min-width: 0;
}

.brand-kicker {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  line-height: 1.2;
  text-transform: uppercase;
}

.brand h1 {
  margin-top: 1px;
  font-size: 19px;
  font-weight: 680;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.icon-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.icon-btn {
  width: 38px;
  padding: 0;
}

.ghost-btn {
  padding: 0 12px;
  font-size: 12.5px;
}

.icon-btn .icon,
.ghost-btn .icon {
  width: 17px;
  height: 17px;
}

html[data-theme="light"] .icon-moon,
html[data-theme="dark"] .icon-sun {
  display: none;
}

/* ---------- mode bar ---------- */

.modebar {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.modebar-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cats {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 31px;
  padding: 0 11px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.cat-index {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.cat[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.cat[aria-pressed="true"] .cat-index {
  color: var(--accent);
}

.modes {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 31px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mode-chip::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background-color 0.15s ease;
}

.mode-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 640;
}

.mode-chip[aria-pressed="true"]::before {
  background: var(--accent);
}

.live-switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 31px;
  margin-left: auto;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
}

.live-switch .icon {
  width: 13px;
  height: 13px;
  color: var(--accent);
}

.live-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted-2);
  transition: transform 0.18s ease, background-color 0.16s ease;
}

.live-switch input:checked + .switch-track {
  border-color: var(--accent);
  background: var(--accent);
}

.live-switch input:checked + .switch-track::after {
  background: var(--accent-ink);
  transform: translateX(14px);
}

.live-switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.optionbar {
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  min-height: 34px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.option-copy {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex: 1 1 320px;
  min-width: 0;
}

.opt-label {
  flex: none;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.option-controls {
  display: flex;
  align-items: center;
  gap: 8px 14px;
  flex-wrap: wrap;
}

.opt-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.opt-check input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

.opt-seg {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
}

.opt-seg button {
  height: 24px;
  padding: 0 8px;
  border-radius: 3px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  white-space: nowrap;
}

.opt-seg button[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ---------- workbench ---------- */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px minmax(0, 1fr);
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.workbench[data-dir="encode"] {
  --flow: var(--accent);
  --flow-hover: var(--accent-hover);
  --flow-ink: var(--accent-ink);
  --flow-soft: var(--accent-soft);
}

.workbench[data-dir="decode"] {
  --flow: var(--decode);
  --flow-hover: var(--decode-hover);
  --flow-ink: var(--decode-ink);
  --flow-soft: var(--decode-soft);
}

.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: pane-rise 0.34s ease both;
}

.pane-output {
  animation-delay: 0.05s;
}

.pane::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
  height: 2px;
  background: linear-gradient(90deg, var(--flow) 0, transparent 62%);
  opacity: 0.85;
  pointer-events: none;
}

.pane:focus-within {
  border-color: var(--flow);
  box-shadow: 0 0 0 3px var(--flow-soft);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 10px 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.pane-index {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.pane-title h2 {
  font-size: 13px;
  font-weight: 680;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge[data-tone="accent"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 29px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.mini-btn .icon {
  width: 14px;
  height: 14px;
}

.mini-btn.is-success {
  color: var(--ok);
}

.mini-btn:disabled {
  opacity: 0.4;
}

.pane-body {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.pane-output .pane-body {
  background: var(--surface-sunken);
}

.pane-body > textarea {
  display: block;
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 14px 16px;
  border: 0;
  outline: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.72;
  resize: none;
  tab-size: 2;
}

.pane-body > textarea::placeholder {
  color: var(--muted-2);
  opacity: 1;
}

/* ---------- CodeMirror editors ---------- */

.pane-body .CodeMirror {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: auto;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.72;
  tab-size: 2;
}

.pane-body .CodeMirror-scroll {
  min-height: 100%;
}

.pane-body .CodeMirror-lines {
  padding: 14px 0;
}

.pane-body .CodeMirror pre.CodeMirror-line,
.pane-body .CodeMirror pre.CodeMirror-line-like {
  padding: 0 16px;
}

.pane-body .CodeMirror-gutters {
  border-right: 1px solid var(--line);
  background: var(--surface-sunken);
}

.pane-body .CodeMirror-linenumber {
  padding: 0 9px 0 10px;
  color: var(--code-gutter-ink);
  font-variant-numeric: tabular-nums;
}

.pane-body .CodeMirror-cursor {
  border-left-color: var(--ink);
}

.pane-body .CodeMirror-selected,
.pane-body .CodeMirror-focused .CodeMirror-selected {
  background: var(--accent-soft);
}

.pane-body .CodeMirror-placeholder {
  color: var(--muted-2);
}

.pane-body .CodeMirror-activeline-background {
  background: var(--surface-sunken);
}

.pane-output .CodeMirror-gutters {
  background: var(--surface);
}

/* token palette: scoped to the CodeMirror theme, both themes ≥ 4.5:1 */

.cm-s-codec-bench .cm-tag,
.cm-s-codec-bench .cm-bracket {
  color: var(--code-tag);
}

.cm-s-codec-bench .cm-attribute,
.cm-s-codec-bench .cm-def,
.cm-s-codec-bench .cm-property,
.cm-s-codec-bench .cm-variable-2 {
  color: var(--code-attr);
}

.cm-s-codec-bench .cm-string,
.cm-s-codec-bench .cm-string-2 {
  color: var(--code-string);
}

.cm-s-codec-bench .cm-number,
.cm-s-codec-bench .cm-atom,
.cm-s-codec-bench .cm-builtin {
  color: var(--code-number);
}

.cm-s-codec-bench .cm-keyword,
.cm-s-codec-bench .cm-operator,
.cm-s-codec-bench .cm-qualifier {
  color: var(--code-keyword);
}

.cm-s-codec-bench .cm-comment,
.cm-s-codec-bench .cm-meta {
  color: var(--code-comment);
}

.cm-s-codec-bench .cm-error {
  color: var(--danger);
}

.pane-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.01em;
}

.foot-hint {
  color: var(--muted-2);
}

/* ---------- bridge ---------- */

.bridge {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 0;
}

.bridge-label {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-align: center;
  text-transform: uppercase;
}

.dirswitch {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.dir-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.dir-btn:last-child {
  border-bottom: 0;
}

.dir-btn .icon {
  width: 15px;
  height: 15px;
}

.dir-btn[aria-pressed="true"][data-dir="encode"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.dir-btn[aria-pressed="true"][data-dir="decode"] {
  background: var(--decode);
  color: var(--decode-ink);
}

.dir-btn:disabled {
  opacity: 0.42;
}

.bridge-note {
  padding: 0 2px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.45;
  text-align: center;
}

.bridge-note:not([hidden]) + .flow-line {
  margin-top: 1px;
}

.flow-line {
  position: relative;
  height: 22px;
}

.flow-line::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 7px;
  left: 50%;
  width: 1px;
  background: var(--flow);
  opacity: 0.4;
}

.flow-line::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--flow);
  border-bottom: 1.5px solid var(--flow);
  opacity: 0.7;
  transform: translateX(-50%) rotate(45deg);
}

.convert-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--flow);
  color: var(--flow-ink);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 0 var(--flow-hover);
  transition: filter 0.15s ease, transform 0.1s ease, box-shadow 0.1s ease;
}

.convert-btn .icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
  stroke: none;
}

.convert-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* ---------- auto candidates & errors ---------- */

.candidates {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px dashed var(--line);
  background: var(--surface-sunken);
}

.candidates-label {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.candidate {
  min-height: 25px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.candidate[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 640;
}

.notice {
  margin: 10px 12px 0;
  padding: 8px 10px;
  border: 1px solid var(--danger);
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.pane-output.has-error {
  border-color: var(--danger);
}

.pane-output.is-stale::before {
  background: linear-gradient(90deg, var(--warn) 0, transparent 62%);
}

.pane-output.is-stale #outHint {
  color: var(--warn);
}

/* ---------- hash results ---------- */

.hash-results {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
}

.hash-row {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}

.hash-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}

.hash-name {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.hash-meta .tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: 9px;
  font-weight: 600;
  white-space: nowrap;
}

.tag-ok {
  border-color: color-mix(in srgb, var(--ok) 28%, transparent);
  background: var(--ok-soft);
  color: var(--ok);
}

.tag-warn {
  border-color: color-mix(in srgb, var(--warn) 28%, transparent);
  background: var(--warn-soft);
  color: var(--warn);
}

.hash-bits {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
}

.hash-copy {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-left: auto;
  border-radius: var(--r-sm);
  color: var(--muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.hash-copy:disabled {
  opacity: 0.35;
}

.hash-copy.is-success {
  color: var(--ok);
}

.hash-value {
  display: block;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.62;
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* ---------- status bar ---------- */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  flex-wrap: wrap;
  padding: 8px 2px 2px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--muted-2);
  box-shadow: 0 0 0 3px transparent;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.status[data-kind="ok"] .status-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.status[data-kind="error"] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.status[data-kind="busy"] .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.status-text {
  overflow-wrap: anywhere;
}

.status-meta {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

/* ---------- help dialog ---------- */

.help-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(84vh, 760px);
  max-height: min(84dvh, 760px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.help-dialog::backdrop {
  background: rgba(10, 12, 14, 0.56);
}

.help-dialog[open] {
  animation: dialog-in 0.18s ease both;
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 13px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.dialog-head h2 {
  margin-top: 2px;
  font-size: 18px;
  font-weight: 680;
  letter-spacing: -0.01em;
}

.dialog-body {
  padding: 18px 20px 22px;
  overflow: auto;
  columns: 2;
  column-gap: 28px;
}

.help-section {
  break-inside: avoid;
  margin-bottom: 20px;
}

.help-section h3 {
  margin-bottom: 5px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.help-section p,
.help-section li {
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.72;
}

.help-section p + p {
  margin-top: 7px;
}

.help-section li + li {
  margin-top: 3px;
}

.help-section code,
.help-section kbd {
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-sunken);
  color: var(--ink);
  font-size: 0.92em;
}

.help-section kbd {
  border-bottom-width: 2px;
  font-family: var(--font-ui);
  font-size: 0.88em;
}

/* ---------- preview dialog ---------- */

.preview-dialog {
  width: min(1120px, calc(100vw - 32px));
  height: min(820px, 86vh);
  height: min(820px, 86dvh);
  max-height: 90vh;
  max-height: 90dvh;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.preview-dialog::backdrop {
  background: rgba(10, 12, 14, 0.6);
}

.preview-dialog[open] {
  animation: dialog-in 0.18s ease both;
}

.preview-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: 11px 12px 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.preview-head-copy {
  min-width: 0;
}

.preview-head h2 {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 680;
  letter-spacing: -0.01em;
}

.preview-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-widths,
.preview-views {
  display: flex;
  gap: 1px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
}

.preview-widths button,
.preview-views button {
  height: 27px;
  padding: 0 8px;
  border-radius: 3px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.preview-widths button[aria-pressed="true"],
.preview-views button[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 7px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.preview-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--accent);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.preview-note {
  overflow-wrap: anywhere;
}

.preview-stage {
  display: block;
  flex: 1;
  min-height: 0;
  padding: 14px;
  background: var(--surface-sunken);
  overflow: auto;
}

.preview-frame {
  width: 100%;
  height: 100%;
  min-height: 360px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: width 0.18s ease;
}

.preview-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

/* ---------- preview source view ---------- */

.preview-source {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  background: var(--code-bg);
}

.source-head {
  display: flex;
  align-items: center;
  gap: 6px 10px;
  flex-wrap: wrap;
  padding: 6px 12px 6px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.source-lang {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.source-count {
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.source-hint {
  margin-right: auto;
  color: var(--muted);
  font-size: 10.5px;
  overflow-wrap: anywhere;
}

.source-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.source-scroll:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.source-lines {
  display: grid;
  grid-template-columns: max-content minmax(max-content, 1fr);
  grid-auto-rows: min-content;
  width: max-content;
  min-width: 100%;
  padding: 10px 0 12px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.62;
  tab-size: 2;
}

.source-ln {
  position: sticky;
  left: 0;
  z-index: 1;
  padding: 0 9px 0 12px;
  border-right: 1px solid var(--line);
  background: var(--code-gutter-bg);
  color: var(--code-gutter-ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.source-lc {
  padding: 0 16px 0 12px;
  white-space: pre;
  overflow-wrap: normal;
}

.preview-source.is-wrap .source-lines {
  grid-template-columns: max-content minmax(0, 1fr);
  width: auto;
}

.preview-source.is-wrap .source-lc {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* token palette: scoped to the source view so Prism class names cannot hit app components */

.source-lc .token {
  white-space: inherit;
}

.source-lc .token.comment,
.source-lc .token.prolog,
.source-lc .token.doctype,
.source-lc .token.cdata {
  color: var(--code-comment);
}

.source-lc .token.punctuation {
  color: var(--code-punct);
}

.source-lc .token.tag,
.source-lc .token.deleted,
.source-lc .token.selector {
  color: var(--code-tag);
}

.source-lc .token.attr-name,
.source-lc .token.property,
.source-lc .token.function,
.source-lc .token.class-name {
  color: var(--code-attr);
}

.source-lc .token.attr-value,
.source-lc .token.string,
.source-lc .token.char,
.source-lc .token.inserted {
  color: var(--code-string);
}

.source-lc .token.entity,
.source-lc .token.number,
.source-lc .token.boolean,
.source-lc .token.constant,
.source-lc .token.symbol,
.source-lc .token.regex,
.source-lc .token.important,
.source-lc .token.variable {
  color: var(--code-number);
}

.source-lc .token.keyword,
.source-lc .token.operator,
.source-lc .token.url,
.source-lc .token.atrule,
.source-lc .token.rule {
  color: var(--code-keyword);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 9px 14px;
  border-radius: var(--r-md);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- pointer affordances ---------- */

@media (any-hover: hover) {
  .icon-btn:hover,
  .ghost-btn:hover {
    border-color: var(--line-strong);
    background: var(--surface-sunken);
    color: var(--ink);
  }

  .cat:hover,
  .mode-chip:hover {
    background: var(--surface-sunken);
    color: var(--ink);
  }

  .cat[aria-pressed="true"]:hover {
    background: var(--surface-raised);
  }

  .mode-chip[aria-pressed="true"]:hover {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .mini-btn:hover:not(:disabled),
  .hash-copy:hover:not(:disabled) {
    background: var(--surface-sunken);
    color: var(--ink);
  }

  .preview-widths button:hover {
    background: var(--surface-raised);
    color: var(--ink);
  }

  .dir-btn:hover:not(:disabled):not([aria-pressed="true"]) {
    background: var(--surface-sunken);
    color: var(--ink);
  }

  .convert-btn:hover {
    filter: brightness(1.06);
  }

  .candidate:hover {
    border-color: var(--line-strong);
    color: var(--ink);
  }

  .candidate[aria-pressed="true"]:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .workbench {
    grid-template-columns: minmax(0, 1fr);
    flex: 0 1 auto;
    gap: 8px;
  }

  .bridge {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0;
  }

  .bridge-label,
  .flow-line,
  .bridge-note:not([hidden]) + .flow-line {
    display: none;
  }

  .bridge-note:not([hidden]) {
    flex: 0 1 auto;
    order: 3;
    padding: 0 2px;
    text-align: left;
  }

  .dirswitch {
    flex: 1;
    flex-direction: row;
  }

  .dir-btn {
    flex: 1;
    height: 44px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .dir-btn:last-child {
    border-right: 0;
  }

  .convert-btn {
    min-width: 116px;
    height: 44px;
  }

  .pane-body > textarea {
    flex: 0 0 auto;
    height: clamp(150px, 21svh, 190px);
    min-height: 150px;
  }

  .pane-body .CodeMirror {
    flex: 0 0 auto;
    height: clamp(150px, 21svh, 190px);
    min-height: 150px;
  }

  .hash-results {
    min-height: 180px;
  }
}

@media (max-width: 640px) {
  .app {
    width: calc(100% - 24px);
    padding-top: 10px;
  }

  .topbar {
    gap: 10px;
  }

  .brand-kicker {
    display: none;
  }

  .brand h1 {
    font-size: 17.5px;
  }

  .local-badge {
    display: none;
  }

  .modebar {
    padding: 8px 10px;
  }

  .cats {
    width: 100%;
  }

  .cat {
    flex: 1;
    justify-content: center;
    padding: 0 6px;
  }

  .modes {
    width: auto;
    flex: 1;
  }

  .live-switch {
    width: auto;
    height: 31px;
    margin-left: auto;
    padding-top: 0;
    padding-left: 10px;
    border-top: 0;
    border-left: 1px solid var(--line);
    justify-content: flex-end;
  }

  .optionbar {
    gap: 8px;
  }

  .option-copy {
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 2px 8px;
  }

  .mode-note {
    flex-basis: 100%;
  }

  .option-controls {
    width: 100%;
  }

  .pane-head {
    padding-left: 10px;
  }

  .pane-body > textarea {
    padding: 12px 13px;
    font-size: 14px;
  }

  .pane-body .CodeMirror {
    font-size: 14px;
  }

  .pane-body .CodeMirror-lines {
    padding: 12px 0;
  }

  .pane-body .CodeMirror pre.CodeMirror-line,
  .pane-body .CodeMirror pre.CodeMirror-line-like {
    padding: 0 13px;
  }

  .pane-foot {
    padding: 7px 10px;
  }

  .foot-hint {
    display: none;
  }

  .statusbar {
    padding-bottom: 4px;
  }

  .status-meta {
    display: none;
  }

  .dialog-body {
    columns: 1;
    padding: 16px 16px 20px;
  }

  .help-dialog {
    max-height: 88dvh;
  }

  .preview-dialog {
    width: calc(100vw - 16px);
    height: 92dvh;
    max-height: 94dvh;
  }

  .preview-head {
    padding: 10px 10px 9px 14px;
  }

  .preview-head-actions {
    gap: 6px;
  }

  .preview-widths button {
    padding: 0 7px;
  }

  .preview-meta {
    padding: 6px 14px;
    font-size: 10.5px;
  }

  .preview-stage {
    padding: 8px;
  }

  .preview-frame {
    min-height: 300px;
  }

  .source-head {
    padding: 6px 10px;
  }

  .source-hint {
    display: none;
  }

  .source-lines {
    font-size: 12px;
  }

  .source-lc {
    padding-right: 12px;
  }
}

@media (max-width: 400px) {
  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand h1 {
    font-size: 16.5px;
  }

  .ghost-btn {
    width: 38px;
    padding: 0;
  }

  .btn-label {
    display: none;
  }

  .cat-index {
    display: none;
  }

  .mode-chip {
    padding: 0 8px;
    font-size: 12px;
  }

  .convert-btn {
    min-width: 46px;
    width: 46px;
  }

  .convert-btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .pane-index {
    display: none;
  }

  .mini-btn {
    padding: 0 6px;
  }

  .hash-results {
    padding: 10px;
  }
}

@media (pointer: coarse) {
  .icon-btn,
  .ghost-btn {
    min-height: 44px;
  }

  .icon-btn {
    width: 44px;
  }

  .ghost-btn {
    min-width: 44px;
  }

  .cat,
  .mode-chip {
    min-height: 44px;
  }

  .live-switch {
    min-height: 44px;
  }

  .mini-btn {
    min-height: 44px;
  }

  .hash-copy {
    width: 44px;
    height: 44px;
  }

  .preview-widths button {
    min-height: 44px;
  }

  .preview-views button {
    min-height: 44px;
  }

  .opt-seg button {
    min-height: 44px;
  }

  .opt-check {
    min-height: 44px;
  }

  .pane-body > textarea {
    font-size: 16px;
  }

  .pane-body .CodeMirror textarea {
    font-size: 16px;
  }
}

/* ---------- motion ---------- */

@keyframes pane-rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.pane-output.is-fresh {
  animation: result-flash 0.36s ease;
}

@keyframes result-flash {
  0% {
    box-shadow: 0 0 0 0 var(--flow-soft);
  }
  30% {
    box-shadow: 0 0 0 3px var(--flow-soft);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .pane,
  .help-dialog[open],
  .preview-dialog[open] {
    animation: none;
  }
}

@media (forced-colors: active) {
  .pane,
  .modebar,
  .dirswitch,
  .hash-row,
  .candidate,
  .badge {
    border: 1px solid CanvasText;
  }

  .source-ln {
    border-right: 1px solid CanvasText;
  }

  .switch-track::after {
    background: CanvasText;
  }
}
