/* Hashmark v1 — paper on the left, ink on the right. */

:root {
  --font-display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
  --font-ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-doc: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --bg: #EDF0F6;
  --surface: #FFFFFF;
  --surface-2: #F5F7FB;
  --line: #DCE1EC;
  --line-strong: #C3CADB;
  --ink: #111A2E;
  --ink-2: #4A566F;
  --ink-3: #6F7B95;
  --brand: #2B45F5;
  --brand-hover: #2137D6;
  --brand-ink: #FFFFFF;
  --brand-tint: #E8ECFF;
  --mark: #FFE14D;
  --ok: #0E8F63;
  --warn: #9A6200;
  --warn-bg: #FFF4D6;
  --err: #C93030;
  --err-bg: #FDECEC;

  --paper: #FFFFFF;
  --paper-ink: #1B2338;
  --code-bg: #0F1626;
  --code-ink: #D9E0F2;
  --code-dim: #5B6785;
  --code-line: #1D2740;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-pop: 0 12px 32px rgba(17, 26, 46, .16), 0 2px 6px rgba(17, 26, 46, .08);
  --ring: 0 0 0 3px rgba(43, 69, 245, .32);
  --rail-w: 344px;
}

[data-theme='dark'] {
  --bg: #0A0F1B;
  --surface: #131A2B;
  --surface-2: #192237;
  --line: #26314B;
  --line-strong: #37446A;
  --ink: #E8ECF6;
  --ink-2: #A9B4CE;
  --ink-3: #8592B0;
  --brand: #8DA0FF;
  --brand-hover: #A6B4FF;
  --brand-ink: #0A0F1B;
  --brand-tint: #1D2848;
  --warn: #F2C255;
  --warn-bg: #2C2410;
  --err: #FF8383;
  --err-bg: #331A1F;
  --paper: #182036;
  --paper-ink: #E3E8F5;
  --code-bg: #070B14;
  --code-line: #161F35;
  --ring: 0 0 0 3px rgba(141, 160, 255, .4);
  --shadow-pop: 0 14px 36px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 14.5px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--ring); }
code { font-family: var(--font-mono); font-size: .92em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }

.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-sm { width: 14px; height: 14px; }

/* ---------- layout ---------- */
.app {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr);
}
.icon-btn.only-narrow { display: none; }

.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); width: calc(var(--rail-w) - 32px); flex: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--mark); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; fill: none; stroke: #111A2E; stroke-width: 2.4; stroke-linecap: round; }
.brand-name { font: 800 21px/1 var(--font-display); letter-spacing: -.02em; }
.doc-title { flex: 1; min-width: 0; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.rail {
  grid-row: 2; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line);
  padding: 16px 16px 12px; display: flex; flex-direction: column; gap: 18px; min-height: 0;
}
.stage { grid-row: 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; font-size: 14px; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-soft { background: var(--brand-tint); color: var(--brand); }
.btn-soft:hover { background: color-mix(in srgb, var(--brand-tint) 70%, var(--brand) 12%); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn { background: none; border: 0; padding: 2px 4px; color: var(--ink-3); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; margin-right: 6px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; font-weight: 500; font-size: 13px; color: var(--ink-2); }
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(17, 26, 46, .14); }

/* ---------- menu ---------- */
.menu-anchor { position: relative; margin-left: 4px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 290px; padding: 6px; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 8px; text-align: left; color: var(--ink); }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu button[disabled] { opacity: .45; cursor: not-allowed; }
.menu small { margin-left: 6px; color: var(--ink-3); font-family: var(--font-mono); font-size: 12px; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ---------- dropzone ---------- */
.dropzone {
  text-align: center; padding: 22px 16px 18px; border-radius: 14px; cursor: pointer;
  border: 1.5px dashed var(--line-strong); background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-tint); }
.dz-icon { width: 44px; height: 44px; margin: 0 auto 8px; display: grid; place-items: center; border-radius: 12px; background: var(--mark); color: #111A2E; }
.dz-icon .ic { width: 22px; height: 22px; }
.dz-title { margin: 0; font: 700 17px/1.2 var(--font-display); letter-spacing: -.01em; }
.dz-sub { margin: 4px auto 14px; max-width: 250px; color: var(--ink-3); font-size: 13px; }
.dz-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

/* ---------- file list ---------- */
.rail-section { display: flex; flex-direction: column; gap: 10px; }
.rail-head { display: flex; align-items: center; justify-content: space-between; }
.rail-head h2 { margin: 0; font: 700 15px var(--font-display); letter-spacing: -.005em; }
.count { display: inline-block; min-width: 22px; padding: 0 7px; margin-left: 4px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font: 500 12px/20px var(--font-ui); text-align: center; }

.combined-card {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; text-align: left;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.combined-card:hover { border-color: var(--line-strong); }
.combined-card[aria-pressed='true'] { border-color: var(--brand); background: var(--brand-tint); }
.cc-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--ink); color: var(--surface); display: grid; place-items: center; flex: none; }
[data-theme='dark'] .cc-icon { background: var(--mark); color: #111A2E; }
.cc-txt { display: flex; flex-direction: column; min-width: 0; }
.cc-name { font-weight: 600; }
.cc-meta { font-size: 12.5px; color: var(--ink-3); }

.merge { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.merge summary { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; cursor: pointer; list-style: none; font-weight: 500; font-size: 13.5px; color: var(--ink-2); }
.merge summary::-webkit-details-marker { display: none; }
.merge[open] summary .ic { transform: rotate(180deg); }
.merge-body { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.field > span { font-weight: 500; }
.field select, .field input {
  height: 36px; padding: 0 10px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); color: var(--ink);
}
.field select:hover, .field input:hover { border-color: var(--ink-3); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-inline select { height: 30px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
.opt { font-weight: 400; font-style: normal; color: var(--ink-3); font-size: 12.5px; }

.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.file {
  display: grid; grid-template-columns: 16px 20px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 10px; border: 1px solid transparent; position: relative;
}
.file:hover { background: var(--surface-2); }
.file[data-active='true'] { background: var(--brand-tint); border-color: color-mix(in srgb, var(--brand) 45%, transparent); }
.file.is-ghost { opacity: .4; }
.grip { border: 0; background: none; color: var(--ink-3); padding: 0; cursor: grab; display: grid; place-items: center; height: 28px; touch-action: none; }
.grip:active { cursor: grabbing; }
.file .check input { margin: 0; }
.file-main { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0; border: 0; background: none; text-align: left; }
.badge {
  flex: none; width: 34px; height: 34px; border-radius: 8px; background: var(--c, #5C6884); color: #fff;
  display: grid; place-items: center; font: 600 9.5px/1 var(--font-mono); letter-spacing: .02em; text-transform: uppercase;
}
.file-txt { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file[data-status='error'] .file-meta, .file[data-status='needs-server'] .file-meta { color: var(--err); }
.file-state { display: grid; place-items: center; width: 24px; }
.file-state .ic { width: 16px; height: 16px; }
.file[data-status='done'] .file-state { color: var(--ok); }
.file[data-status='error'] .file-state, .file[data-status='needs-server'] .file-state { color: var(--err); }
.file-actions { display: none; gap: 0; }
.file-actions button { width: 28px; height: 28px; display: grid; place-items: center; border: 0; background: none; border-radius: 7px; color: var(--ink-3); }
.file-actions button:hover { background: var(--surface); color: var(--ink); }
.file-actions button[data-act='remove']:hover { color: var(--err); }
.file:hover .file-actions, .file:focus-within .file-actions, .file[data-active='true'] .file-actions { display: flex; }
.file:hover .file-state, .file:focus-within .file-state, .file[data-active='true'] .file-state { display: none; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-note { margin: 0; font-size: 13px; color: var(--ink-3); padding: 2px 4px; }
.privacy { display: flex; gap: 7px; align-items: flex-start; margin: auto 0 0; padding-top: 10px; font-size: 12.5px; color: var(--ink-3); }
.privacy .ic { margin-top: 3px; color: var(--ok); }

/* ---------- formatting bar ---------- */
.fmtbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 2px; padding: 8px 14px; position: relative;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.fmt-group { display: flex; gap: 1px; padding-right: 8px; margin-right: 6px; border-right: 1px solid var(--line); }
.fmt-group:last-of-type { border-right: 0; }
.fmtbar button { min-width: 32px; height: 32px; padding: 0 6px; display: grid; place-items: center; border: 0; border-radius: 7px; background: none; color: var(--ink-2); font-size: 13px; }
.fmtbar button:hover { background: var(--surface-2); color: var(--ink); }
.fmtbar button[aria-pressed='true'] { background: var(--brand-tint); color: var(--brand); }
.fmtbar button:disabled { opacity: .35; cursor: not-allowed; }
.link-pop {
  position: absolute; left: 14px; top: calc(100% + 6px); z-index: 20; display: flex; gap: 8px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop);
}
.link-pop input { width: 260px; height: 30px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--surface); }

.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--warn-bg); color: var(--warn); font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.notice-actions { display: flex; gap: 6px; }

/* ---------- panes ---------- */
.panes-wrap { position: relative; flex: 1; min-height: 0; }
.panes { display: grid; height: 100%; grid-template-columns: var(--split, 50%) 8px minmax(0, 1fr); }
.panes[data-view='visual'] { grid-template-columns: minmax(0, 1fr); }
.panes[data-view='markdown'] { grid-template-columns: minmax(0, 1fr); }
.panes[data-view='visual'] .divider, .panes[data-view='visual'] .pane-md,
.panes[data-view='markdown'] .divider, .panes[data-view='markdown'] .pane-visual { display: none; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-head {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 18px; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.pane-md .pane-head { background: var(--code-bg); border-bottom-color: var(--code-line); color: #AAB5D1; }
.pane-hint { font-weight: 400; color: var(--ink-3); }
.pane-md .pane-hint { color: var(--code-dim); }
.divider { cursor: col-resize; background: var(--bg); position: relative; touch-action: none; }
.divider::after { content: ''; position: absolute; left: 3px; top: 50%; width: 2px; height: 36px; margin-top: -18px; border-radius: 2px; background: var(--line-strong); }
.divider:hover::after, .divider:focus-visible::after, .divider.is-drag::after { background: var(--brand); }

.paper-wrap { flex: 1; overflow: auto; padding: 28px 24px 96px; background: var(--bg); container-type: inline-size; }
.doc {
  max-width: 760px; margin: 0 auto; min-height: 100%; padding: clamp(28px, 8cqw, 56px) clamp(24px, 8.5cqw, 68px) 72px; outline: none;
  background: var(--paper); color: var(--paper-ink); border: 1px solid var(--line); border-radius: 6px;
  font: 400 18px/1.7 var(--font-doc); font-optical-sizing: auto; overflow-wrap: anywhere;
}
.doc[contenteditable='false'] { opacity: .75; }
.doc > :first-child { margin-top: 0; }
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6 { font-family: var(--font-display); line-height: 1.2; letter-spacing: -.015em; margin: 1.6em 0 .5em; font-weight: 700; }
.doc h1 { font-size: 2.05em; font-weight: 800; letter-spacing: -.025em; }
.doc h2 { font-size: 1.5em; }
.doc h3 { font-size: 1.22em; }
.doc h4, .doc h5, .doc h6 { font-size: 1.02em; }
.doc p { margin: 0 0 1em; }
.doc a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.doc ul, .doc ol { padding-left: 1.5em; margin: 0 0 1em; }
.doc li { margin: .25em 0; }
.doc li > input[type='checkbox'] { margin-right: .5em; accent-color: var(--brand); transform: translateY(1px); }
.doc ul:has(> li > input[type='checkbox']) { list-style: none; padding-left: .2em; }
.doc blockquote { margin: 1.2em 0; padding: .1em 1.1em; border-left: 3px solid var(--mark); color: color-mix(in srgb, var(--paper-ink) 78%, transparent); font-style: italic; }
.doc code { font-family: var(--font-mono); font-size: .82em; background: var(--surface-2); border: 1px solid var(--line); padding: .08em .35em; border-radius: 5px; }
.doc pre { margin: 1.1em 0; padding: 14px 16px; background: var(--code-bg); color: var(--code-ink); border-radius: 9px; overflow: auto; font: 400 14px/1.6 var(--font-mono); }
.doc pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
.doc hr { border: 0; height: 1px; background: var(--line-strong); margin: 2em 0; }
.doc img { max-width: 100%; height: auto; border-radius: 4px; }
.doc table { border-collapse: collapse; width: 100%; margin: 1.2em 0; font: 400 15px/1.5 var(--font-ui); display: block; overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line-strong); padding: 8px 11px; text-align: left; vertical-align: top; min-width: 60px; }
.doc th { background: var(--surface-2); font-weight: 600; }
.doc .md-comment { margin: 1em 0; padding: 3px 12px; border: 1px dashed var(--line-strong); border-radius: 99px; width: fit-content; max-width: 100%; font: 400 12px var(--font-mono); color: var(--ink-3); user-select: none; }
.doc .md-comment::before { content: '<!-- '; } .doc .md-comment::after { content: ' -->'; }
.doc .md-front { margin: 0 0 1.5em; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface-2); font: 400 13px/1.5 var(--font-mono); }
.doc .md-front span { display: block; font: 600 12px var(--font-ui); color: var(--ink-3); margin-bottom: 4px; }
.doc .md-front pre { margin: 0; padding: 0; background: none; color: inherit; font-size: inherit; }
.doc ::selection { background: var(--mark); color: #111A2E; }

.code-wrap { position: relative; flex: 1; min-height: 0; background: var(--code-bg); overflow: hidden; }
#hl, #raw {
  position: absolute; inset: 0; margin: 0; padding: 24px 28px 96px; border: 0; width: 100%; height: 100%;
  font: 400 13.5px/1.75 var(--font-mono); letter-spacing: 0; tab-size: 2;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; word-break: normal;
  overflow: auto; scrollbar-width: none;
}
#hl::-webkit-scrollbar, #raw::-webkit-scrollbar { display: none; }
#hl { color: var(--code-ink); pointer-events: none; overflow: hidden; }
#hl code { font: inherit; background: none; border: 0; padding: 0; color: inherit; }
#raw { background: transparent; color: transparent; caret-color: var(--mark); resize: none; outline: none; }
#raw.no-hl { color: var(--code-ink); }
#raw::selection { background: rgba(255, 225, 77, .32); }
#raw:focus-visible { box-shadow: none; }
.t-hash { color: var(--mark); font-weight: 500; }
.t-h { color: #FFFFFF; font-weight: 500; }
.t-b { color: #FFFFFF; font-weight: 500; }
.t-i { color: #E7ECFA; font-style: italic; }
.t-s { color: var(--code-dim); text-decoration: line-through; }
.t-code { color: #7FE3B7; }
.t-link { color: #93A5FF; }
.t-mark { color: #F5A3BF; }
.t-dim { color: var(--code-dim); }
.t-fence { color: var(--code-dim); }
.t-block { color: #7FE3B7; }

/* ---------- state card (converting / error) ---------- */
.state-card { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(3px); }
.state-inner { max-width: 440px; width: 100%; padding: 28px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-pop); }
.state-inner h3 { margin: 12px 0 6px; font: 700 20px var(--font-display); letter-spacing: -.01em; }
.state-inner p { margin: 0 0 16px; color: var(--ink-2); }
.state-inner .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.state-icon { width: 46px; height: 46px; margin: 0 auto; display: grid; place-items: center; border-radius: 12px; background: var(--err-bg); color: var(--err); }
.state-icon.is-work { background: var(--brand-tint); color: var(--brand); }
.state-icon .spinner { width: 22px; height: 22px; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 0 auto 4px; max-width: 260px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* ---------- status bar ---------- */
.statusbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 16px; background: var(--surface); border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-3); }
.st-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.st-warn { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border: 0; border-radius: 99px; background: var(--warn-bg); color: var(--warn); font-size: 12.5px; }
.st-right { font-variant-numeric: tabular-nums; white-space: nowrap; }
.st-source { white-space: nowrap; }
.menu .menu-hist { display: none; }

/* ---------- dialogs, toasts, veil ---------- */
.dlg { width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
.dlg-narrow { width: min(460px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(10, 15, 27, .55); }
.dlg form { display: flex; flex-direction: column; max-height: min(720px, 90vh); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 10px 22px; }
.dlg-head h2 { margin: 0; font: 700 19px var(--font-display); letter-spacing: -.01em; }
.dlg-body { padding: 4px 22px 18px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.dlg fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.dlg legend { padding: 0; margin-bottom: 6px; font: 700 14px var(--font-display); }
.hint { margin: 0; color: var(--ink-2); font-size: 13.5px; }
.test-row { display: flex; align-items: center; gap: 10px; }
.test-result { font-size: 13px; color: var(--ink-2); }
.test-result.ok { color: var(--ok); } .test-result.bad { color: var(--err); }
.paste-box { min-height: 200px; max-height: 340px; overflow: auto; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); outline: none; }
.paste-box:empty::before { content: attr(data-placeholder); color: var(--ink-3); }
.hist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.hist-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; }
.hist-item b { font-weight: 600; }
.hist-item small { display: block; color: var(--ink-3); font-size: 12.5px; }
.hist-item.is-current { background: var(--brand-tint); border-color: transparent; }
.notes-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }

.toasts { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-pop); font-size: 14px; max-width: min(520px, 92vw); animation: rise .2s ease-out; }
[data-theme='dark'] .toast { background: #E8ECF6; color: #0A0F1B; }
.toast button { border: 0; background: rgba(255, 255, 255, .16); color: inherit; border-radius: 7px; padding: 4px 10px; font-weight: 600; }
[data-theme='dark'] .toast button { background: rgba(10, 15, 27, .12); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.dropveil { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgba(43, 69, 245, .18); backdrop-filter: blur(4px); pointer-events: none; }
.dropveil-card { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 34px 54px; border-radius: 22px; background: var(--surface); border: 2px dashed var(--brand); font: 700 22px var(--font-display); }
.dropveil-card .ic { width: 34px; height: 34px; color: var(--brand); }
.dropveil-card p { margin: 0; }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .icon-btn.only-narrow { display: grid; }
  .brand { width: auto; }
  .doc-title { display: none; }
  .topbar { gap: 8px; }
  .topbar-actions { margin-left: auto; }
  .seg { margin-right: 0; }
  .seg button[data-view='split'] { display: none; }
  .btn-primary span { display: none; }
  .btn-primary .ic-sm { display: none; }
  .rail {
    position: fixed; z-index: 40; top: 56px; bottom: 0; left: 0; width: min(360px, 92vw);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-pop);
  }
  .app[data-rail='open'] .rail { transform: none; }
  .stage { grid-column: 1; }
  .panes, .panes[data-view] { grid-template-columns: minmax(0, 1fr); }
  .divider { display: none !important; }
  .panes[data-view='split'] .pane-md, .panes[data-view='visual'] .pane-md { display: none; }
  .panes[data-view='markdown'] .pane-visual { display: none; }
  .doc { padding: 28px 22px 48px; font-size: 17px; }
  .paper-wrap { padding: 14px 10px 90px; }
  .fmtbar { overflow-x: auto; flex-wrap: nowrap; }
  .fmt-group { flex: none; }
  .link-pop { position: fixed; left: 12px; right: 12px; top: 112px; }
  .link-pop input { flex: 1; width: auto; min-width: 0; }
}

@media (max-width: 560px) {
  .brand-name { display: none; }
  #btnHistory { display: none; }
  .menu .menu-hist { display: flex; }
  .seg button { padding: 5px 9px; }
  .icon-btn { width: 34px; }
  .st-extra { display: none; }
  .statusbar { padding: 6px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- v3: dragging anywhere on a row, and the Sort dialog ---- */
.file { cursor: grab; }
.file-main, .file .check, .file-actions button { cursor: pointer; }
.file.is-chosen { cursor: grabbing; }
.file.is-drag { box-shadow: var(--shadow-pop); background: var(--surface); }
.rail-head-actions { display: inline-flex; gap: 10px; align-items: center; }
.rail-head-actions .link-btn { display: inline-flex; align-items: center; gap: 4px; }
.rail-head-actions .link-btn:disabled { opacity: .4; pointer-events: none; }
.sort-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .sort-row { grid-template-columns: 1fr; } }
.sort-extra { display: flex; flex-direction: column; gap: 10px; }
.sort-extra[hidden] { display: none; }
.dlg input[type='text'], .dlg textarea { width: 100%; box-sizing: border-box; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: 14px var(--font-mono, monospace); }
.dlg input[type='text']:focus, .dlg textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2, var(--ink)); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--ink); }
.sort-preview-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.sort-preview { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; counter-reset: s; }
.sort-preview li { counter-increment: s; display: flex; gap: 10px; align-items: center; padding: 6px 10px; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.sort-preview li:last-child { border-bottom: 0; }
.sort-preview li::before { content: counter(s); min-width: 22px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.sort-preview .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sort-preview .key { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--brand-tint); color: var(--ink); white-space: nowrap; }
.sort-preview li.nomatch .key { background: transparent; color: var(--err); }
.sort-error { margin: 0 0 8px; color: var(--err); font-size: 13px; }
.sort-error[hidden] { display: none; }
