:root {
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --serif: 'Newsreader', 'Iowan Old Style', Georgia, Cambria, serif;

    --accent: #4a55d6;
    --accent-soft: rgba(74, 85, 214, 0.1);
    --error: #c92a5b;
    --error-soft: rgba(201, 42, 91, 0.1);
    --warning: #b45309;
    --warning-soft: rgba(180, 83, 9, 0.12);
    --info: #64748b;
    --info-soft: rgba(100, 116, 139, 0.12);
    --success: #12876f;
    --success-soft: rgba(18, 135, 111, 0.12);

    --bg: #ffffff;
    --bg-sunken: #fafafa;
    --surface: #ffffff;
    --ink: #18181b;
    --ink-2: #52525b;
    --muted: #8b8b94;
    --line: #ebebee;
    --line-strong: #dcdce1;
    --overlay: rgba(24, 24, 27, 0.32);
    --shadow-overlay: 0 16px 40px rgba(24, 24, 27, 0.12);

    --topbar: 52px;
    --statusbar: 30px;
    --drawer: 300px;
    --editor-size: 15px;
    --preview-size: 17px;
    --ease: 160ms cubic-bezier(0.2, 0, 0.2, 1);
}

[data-theme='dark'] {
    --accent: #9aa5ff;
    --accent-soft: rgba(154, 165, 255, 0.14);
    --error: #ff7d9e;
    --error-soft: rgba(255, 125, 158, 0.13);
    --warning: #f0b357;
    --warning-soft: rgba(240, 179, 87, 0.13);
    --info: #9aa4b8;
    --info-soft: rgba(154, 164, 184, 0.12);
    --success: #5fd3b4;
    --success-soft: rgba(95, 211, 180, 0.13);

    --bg: #131316;
    --bg-sunken: #17171a;
    --surface: #1a1a1e;
    --ink: #ececef;
    --ink-2: #b9b9c2;
    --muted: #85858f;
    --line: #2a2a30;
    --line-strong: #3a3a42;
    --overlay: rgba(0, 0, 0, 0.5);
    --shadow-overlay: 0 16px 40px rgba(0, 0, 0, 0.5);
}

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

body.is-locked {
    overflow: hidden;
}

h1, h2, h3, h4, p, dl, dd {
    margin: 0;
}

button {
    font: inherit;
    color: inherit;
}

.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: absolute;
    top: -60px;
    left: 12px;
    z-index: 2000;
    padding: 9px 14px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    text-decoration: none;
    transition: top var(--ease);
}

.skip-link:focus {
    top: 10px;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.app {
    display: grid;
    grid-template-rows: var(--topbar) minmax(0, 1fr) var(--statusbar);
    height: 100vh;
}

/* ---------- topbar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
}

.topbar-left {
    flex: 1;
}

.icon-btn {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
}

.icon-btn:hover {
    background: var(--bg-sunken);
    color: var(--ink);
}

.icon-btn[aria-expanded='true'] {
    background: var(--accent-soft);
    color: var(--accent);
}

.icon-btn-sm {
    width: 26px;
    height: 26px;
    font-size: 12px;
}

.badge {
    position: absolute;
    top: 1px;
    right: 0;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 9px;
    font-weight: 600;
    line-height: 14px;
    text-align: center;
}

.badge[hidden] {
    display: none;
}

.badge.is-error {
    background: var(--error);
}

.doc-title {
    min-width: 0;
    width: min(42ch, 40vw);
    padding: 5px 8px;
    margin-left: 2px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    text-overflow: ellipsis;
    transition: background var(--ease), border-color var(--ease);
}

.doc-title:hover {
    background: var(--bg-sunken);
}

.doc-title:focus {
    background: var(--surface);
    border-color: var(--line-strong);
    outline: none;
}

/* ---------- workspace ---------- */

.workspace {
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.panes {
    display: flex;
    height: 100%;
    min-height: 0;
}

.pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 50%;
    min-width: 0;
    min-height: 0;
}

.pane-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 34px;
    padding: 0 16px;
    border-bottom: 1px solid var(--line);
    flex: none;
}

.pane-label,
.drawer-bar h2,
.block h3 {
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

.pane-hint {
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--muted);
    opacity: 0.8;
}

.pane-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}

.switch:hover {
    color: var(--ink-2);
}

.switch input {
    accent-color: var(--accent);
    width: 13px;
    height: 13px;
    margin: 0;
    cursor: pointer;
}

.mini-select,
select,
input[type='text'],
input[type='url'],
input[type='password'] {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    padding: 5px 8px;
}

.mini-select {
    font-size: 11.5px;
    color: var(--muted);
    padding: 2px 6px;
    border-color: transparent;
    background: transparent;
    max-width: 110px;
}

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

/* ---------- editor ---------- */

.editor-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    background: var(--bg);
}

#markdown-input,
.editor-layer {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 28px 32px 45vh;
    border: 0;
    font-family: var(--mono);
    font-size: var(--editor-size);
    font-weight: 400;
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    tab-size: 4;
}

.editor-layer {
    z-index: 1;
    overflow: hidden;
    color: transparent;
    pointer-events: none;
}

.editor-layer .flag {
    background: transparent;
    color: transparent;
    text-decoration-line: underline;
    text-decoration-style: wavy;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 4px;
    text-decoration-skip-ink: none;
    text-decoration-color: var(--info);
}

.editor-layer .flag-error {
    text-decoration-color: var(--error);
}

.editor-layer .flag-warning {
    text-decoration-color: var(--warning);
}

#markdown-input {
    z-index: 2;
    background: transparent;
    color: var(--ink);
    caret-color: var(--accent);
    resize: none;
    overflow-y: auto;
}

#markdown-input:focus {
    outline: none;
}

#markdown-input::placeholder {
    color: var(--muted);
}

/* ---------- splitter ---------- */

.splitter {
    position: relative;
    flex: none;
    width: 9px;
    cursor: col-resize;
    background: transparent;
}

.splitter::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 4px;
    width: 1px;
    background: var(--line);
    transition: background var(--ease), width var(--ease);
}

.splitter:hover::after,
.splitter:focus-visible::after,
body.is-resizing .splitter::after {
    background: var(--accent);
    width: 2px;
}

body.is-resizing {
    cursor: col-resize;
    user-select: none;
}

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

.preview {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 40px 48px 45vh;
    background: var(--bg);
    font-family: var(--serif);
    font-size: var(--preview-size);
    line-height: 1.72;
}

[data-preview-width='narrow'] .preview > * {
    max-width: 34rem;
    margin-left: auto;
    margin-right: auto;
}

[data-preview-width='medium'] .preview > * {
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
}

[data-preview-width='wide'] .preview > * {
    max-width: 52rem;
    margin-left: auto;
    margin-right: auto;
}

.preview > :first-child {
    margin-top: 0;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
    font-family: var(--sans);
    color: var(--ink);
    font-weight: 600;
    line-height: 1.28;
    letter-spacing: -0.011em;
    margin: 1.9em 0 0.5em;
    scroll-margin-top: 16px;
}

.preview h1 {
    font-size: 1.72em;
    letter-spacing: -0.02em;
}

.preview h2 {
    font-size: 1.3em;
}

.preview h3 {
    font-size: 1.1em;
}

.preview h4, .preview h5, .preview h6 {
    font-size: 1em;
    color: var(--ink-2);
}

.preview .header-link {
    margin-left: 8px;
    font-size: 0.62em;
    color: var(--line-strong);
    text-decoration: none;
    opacity: 0;
    transition: opacity var(--ease);
}

.preview h1:hover .header-link,
.preview h2:hover .header-link,
.preview h3:hover .header-link,
.preview h4:hover .header-link,
.preview h5:hover .header-link,
.preview h6:hover .header-link {
    opacity: 1;
}

.preview p,
.preview li {
    color: var(--ink-2);
}

.preview p {
    margin: 0 0 1.15em;
}

.preview ul,
.preview ol {
    margin: 0 0 1.2em;
    padding-left: 1.3em;
}

.preview li {
    margin-bottom: 0.4em;
}

.preview li > ul,
.preview li > ol {
    margin-top: 0.4em;
}

.preview .task-list-item {
    list-style: none;
    margin-left: -1.3em;
}

.preview .task-list-item input {
    margin-right: 0.45em;
    accent-color: var(--accent);
}

.preview blockquote {
    margin: 1.6em 0;
    padding: 0.2em 0 0.2em 1.15em;
    border-left: 2px solid var(--line-strong);
    color: var(--muted);
    font-style: italic;
}

.preview blockquote p:last-child {
    margin-bottom: 0;
}

.preview code,
.preview pre,
.preview table,
.preview .toc {
    font-family: var(--sans);
}

.preview code {
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 0.08em 0.34em;
    border-radius: 5px;
    font-size: 0.82em;
}

.preview pre {
    position: relative;
    margin: 1.6em 0;
    padding: 1em 1.15em;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink-2);
    font-size: 0.78em;
    line-height: 1.65;
    overflow-x: auto;
}

.preview pre::before {
    content: attr(data-lang);
    position: absolute;
    top: 9px;
    right: 12px;
    font-size: 9.5px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--muted);
}

.preview pre code {
    background: none;
    border: 0;
    color: inherit;
    padding: 0;
    font-size: 1em;
}

.preview a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.preview a:hover {
    text-decoration-color: var(--accent);
}

.preview a[data-blocked-url='true'] {
    color: var(--muted);
    text-decoration-style: dashed;
}

.preview img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    margin: 1.4em 0;
}

.preview figure {
    margin: 1.6em 0;
    text-align: center;
}

.preview figcaption {
    margin-top: 0.5em;
    font-family: var(--sans);
    font-size: 0.8em;
    color: var(--muted);
}

.preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.6em 0;
    font-size: 0.88em;
}

.preview th,
.preview td {
    border-bottom: 1px solid var(--line);
    padding: 0.55em 0.7em;
    text-align: left;
}

.preview th {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.9em;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.preview hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 2.6em 0;
}

.preview mark {
    background: var(--warning-soft);
    color: inherit;
    padding: 0.05em 0.2em;
    border-radius: 3px;
}

.preview del {
    color: var(--muted);
}

.preview .footnotes {
    margin-top: 3em;
    padding-top: 1.2em;
    border-top: 1px solid var(--line);
    font-size: 0.86em;
    color: var(--muted);
}

.preview .footnote-body {
    display: none;
}

.preview .toc {
    margin-bottom: 2em;
    padding: 0.9em 1.2em;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 0.88em;
}

.preview .toc-title {
    margin: 0 0 0.4em;
    font-size: 0.82em;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
}

.preview .toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* ---------- drawers ---------- */

.drawer {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    width: var(--drawer);
    max-width: 86vw;
    background: var(--surface);
    transition: transform 200ms cubic-bezier(0.2, 0, 0.2, 1);
}

.drawer-left {
    left: 0;
    border-right: 1px solid var(--line);
    transform: translateX(-101%);
}

.drawer-right {
    right: 0;
    border-left: 1px solid var(--line);
    transform: translateX(101%);
}

html.drawer-rail-open .drawer-left,
html.drawer-inspector-open .drawer-right {
    transform: none;
}

.drawer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 44px;
    padding: 0 10px 0 16px;
    flex: none;
}

.drawer-bar.sub {
    border-top: 1px solid var(--line);
    margin-top: 6px;
}

.count {
    min-width: 20px;
    padding: 1px 7px;
    border-radius: 9px;
    background: var(--bg-sunken);
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 500;
    text-align: center;
}

.rail-tools {
    display: flex;
    gap: 6px;
    padding: 0 12px 10px;
}

.ghost-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 11.5px;
    cursor: pointer;
    transition: color var(--ease), border-color var(--ease), background var(--ease);
}

.ghost-btn:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--bg-sunken);
}

.ghost-btn.danger:hover {
    color: var(--error);
    border-color: var(--error);
    background: var(--error-soft);
}

.doc-list,
.outline-list,
.issue-list,
.version-list,
.palette-list {
    list-style: none;
    margin: 0;
    padding: 0 8px 10px;
    overflow-y: auto;
    min-height: 0;
}

.doc-list {
    flex: none;
    max-height: 34vh;
}

.doc-open {
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 100%;
    padding: 6px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.doc-open:hover {
    background: var(--bg-sunken);
}

.doc-item.is-active .doc-open {
    background: var(--accent-soft);
}

.doc-name {
    font-size: 12.5px;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-item.is-active .doc-name {
    color: var(--accent);
    font-weight: 500;
}

.doc-info {
    font-size: 10.5px;
    color: var(--muted);
}

.outline-list {
    flex: 1;
}

.outline-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 4px 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    color: var(--ink-2);
}

.outline-item:hover {
    background: var(--bg-sunken);
    color: var(--ink);
}

.outline-item.level-1 {
    color: var(--ink);
    font-weight: 500;
}

.outline-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.outline-line {
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--muted);
    flex: none;
}

.inspector-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 16px;
}

.block {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.block:last-child {
    border-bottom: 0;
}

.block h3 {
    padding: 0 16px 8px;
}

.block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 16px;
}

.block-head h3 {
    padding-bottom: 8px;
}

.tabs {
    display: flex;
    gap: 1px;
    padding: 0 12px 8px;
}

.tab {
    flex: 1;
    padding: 4px 6px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
}

.tab:hover {
    color: var(--ink-2);
    background: var(--bg-sunken);
}

.tab.is-active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
}

.issue-list {
    max-height: 52vh;
    padding: 0 8px;
}

.issue {
    padding: 8px 9px;
    border-left: 2px solid transparent;
    border-radius: 0 7px 7px 0;
}

.issue + .issue {
    margin-top: 1px;
}

.issue-error { border-left-color: var(--error); }
.issue-warning { border-left-color: var(--warning); }
.issue-info { border-left-color: var(--line-strong); }

.issue.is-active {
    background: var(--accent-soft);
    border-left-color: var(--accent);
}

.issue-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.issue-severity {
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.issue-error .issue-severity { color: var(--error); }
.issue-warning .issue-severity { color: var(--warning); }
.issue-info .issue-severity { color: var(--muted); }

.issue-type {
    font-size: 9.5px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.issue-message {
    font-size: 12.5px;
    color: var(--ink);
}

.issue-hint {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 1px;
}

.issue-excerpt {
    display: block;
    margin-top: 5px;
    padding: 3px 6px;
    background: var(--bg-sunken);
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.issue-actions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.mini-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 10.5px;
    cursor: pointer;
    transition: color var(--ease), border-color var(--ease), background var(--ease);
}

.mini-btn:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--bg-sunken);
}

.metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    margin: 0 12px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 9px;
    overflow: hidden;
}

.metrics > div {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 8px 11px;
    background: var(--surface);
}

.metrics dt {
    font-size: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.metrics dd {
    font-size: 14px;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.tone-good { color: var(--success); }
.tone-warn { color: var(--warning); }
.tone-bad { color: var(--error); }
.tone-neutral { color: var(--ink); }

.actions {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 8px;
}

.action {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 6px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ink-2);
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
}

.action i {
    width: 13px;
    color: var(--muted);
    text-align: center;
}

.action:hover {
    background: var(--bg-sunken);
    color: var(--ink);
}

.action:hover i {
    color: var(--accent);
}

.hint {
    padding: 8px 16px 0;
    font-size: 11px;
    color: var(--muted);
}

.empty-note {
    padding: 12px 10px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.drawer-backdrop {
    position: absolute;
    inset: 0;
    z-index: 30;
    background: var(--overlay);
    animation: fade-in 160ms ease;
}

.drawer-backdrop[hidden] {
    display: none;
}

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

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

.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    overflow: hidden;
}

.status-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.status-saved { color: var(--success); }
.status-saving { color: var(--warning); }
.status-warn { color: var(--warning); }
.status-error { color: var(--error); }

.status-item.is-busy i {
    animation: spin 900ms linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- overflow menu ---------- */

.menu {
    position: fixed;
    z-index: 120;
    top: calc(var(--topbar) - 4px);
    right: 46px;
    width: 208px;
    padding: 5px;
    border: 1px solid var(--line-strong);
    border-radius: 11px;
    background: var(--surface);
    box-shadow: var(--shadow-overlay);
    animation: menu-in 140ms cubic-bezier(0.2, 0, 0.2, 1);
}

.menu[hidden] {
    display: none;
}

@keyframes menu-in {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: none; }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 6px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ink-2);
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
}

.menu-item i {
    width: 14px;
    color: var(--muted);
    text-align: center;
}

.menu-item:hover {
    background: var(--bg-sunken);
    color: var(--ink);
}

.menu-item:hover i {
    color: var(--accent);
}

.menu-sep {
    height: 1px;
    margin: 5px 7px;
    background: var(--line);
}

/* ---------- dialogs ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 13px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.07);
}

.btn-ghost {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--ink-2);
}

.btn-ghost:hover {
    background: var(--bg-sunken);
    color: var(--ink);
}

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    filter: brightness(1.07);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: var(--overlay);
    animation: fade-in 140ms ease;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    display: flex;
    flex-direction: column;
    width: min(540px, 100%);
    max-height: min(84vh, 880px);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    box-shadow: var(--shadow-overlay);
    overflow: hidden;
    animation: modal-in 170ms cubic-bezier(0.2, 0, 0.2, 1);
}

.modal-content-wide {
    width: min(780px, 100%);
}

.modal-content-narrow {
    width: min(400px, 100%);
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.99); }
    to { opacity: 1; transform: none; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 12px 13px 18px;
    border-bottom: 1px solid var(--line);
}

.modal-header h2 {
    font-size: 13.5px;
    font-weight: 600;
}

.modal-body {
    padding: 18px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 14px;
}

.field label {
    font-size: 11.5px;
    font-weight: 500;
    color: var(--ink-2);
}

.field input,
.field select {
    width: 100%;
}

.field output {
    font-size: 11.5px;
    color: var(--muted);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

input[type='range'] {
    accent-color: var(--accent);
    width: 100%;
}

.option-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.find-status {
    font-size: 12px;
    color: var(--muted);
    padding: 7px 10px;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: 7px;
}

.find-status.is-empty {
    color: var(--warning);
}

.format-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
    gap: 7px;
    margin-bottom: 16px;
}

.format-card {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-sunken);
    cursor: pointer;
    transition: border-color var(--ease), background var(--ease);
}

.format-card:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.format-card input {
    accent-color: var(--accent);
    margin-bottom: 5px;
}

.format-card strong {
    font-size: 12.5px;
    color: var(--ink);
}

.format-card span {
    font-size: 10.5px;
    color: var(--muted);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}

.template-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-sunken);
    text-align: left;
    cursor: pointer;
    transition: border-color var(--ease), background var(--ease), color var(--ease);
}

.template-card:hover {
    border-color: var(--accent);
    background: var(--surface);
}

.template-card i {
    font-size: 15px;
    color: var(--accent);
}

.template-card h3 {
    font-size: 12.5px;
    font-weight: 600;
}

.template-card p {
    font-size: 11.5px;
    color: var(--muted);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.stats-cell {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 10px 12px;
    background: var(--surface);
}

.stats-label {
    font-size: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.stats-value {
    font-size: 14.5px;
    color: var(--ink);
}

.stats-section {
    margin-top: 20px;
}

.stats-section h3 {
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 9px;
}

.gauge-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.gauge {
    display: grid;
    grid-template-columns: 180px 1fr 66px;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.gauge-label {
    color: var(--ink-2);
}

.gauge-track {
    height: 5px;
    border-radius: 3px;
    background: var(--bg-sunken);
    overflow: hidden;
}

.gauge-fill {
    height: 100%;
    border-radius: 3px;
    background: currentColor;
}

.gauge-value {
    text-align: right;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.word-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 0;
}

.word-item {
    display: grid;
    grid-template-columns: 130px 1fr 32px;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.word-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.word-bar {
    height: 5px;
    border-radius: 3px;
    background: var(--bg-sunken);
    overflow: hidden;
}

.word-fill {
    display: block;
    height: 100%;
    background: var(--accent);
    opacity: 0.7;
}

.word-count {
    text-align: right;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    height: 140px;
    padding: 6px 4px 0;
    border-bottom: 1px solid var(--line);
}

.bar-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
    height: 100%;
    justify-content: flex-end;
}

.bar {
    width: 100%;
    max-width: 56px;
    min-height: 3px;
    border-radius: 5px 5px 0 0;
    background: var(--accent);
    opacity: 0.75;
}

.bar-label {
    font-size: 10.5px;
    color: var(--muted);
}

.bar-value {
    font-size: 11px;
    color: var(--ink-2);
    font-weight: 500;
}

.type-list {
    display: flex;
    gap: 7px;
    padding: 0;
}

.type-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-sunken);
    font-size: 12px;
    text-transform: capitalize;
}

.type-item.is-zero {
    color: var(--muted);
}

.version-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 58vh;
}

.version-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-sunken);
}

.version-info {
    min-width: 0;
}

.version-info strong {
    font-size: 12.5px;
}

.version-meta {
    display: block;
    font-size: 11px;
    color: var(--muted);
}

.version-preview {
    font-size: 12px;
    color: var(--ink-2);
    margin-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-group {
    margin: 0;
    padding: 4px 14px 2px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.settings-group legend {
    padding: 0 6px;
    font-size: 10.5px;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
}

.settings-group .hint {
    padding: 0 0 10px;
}

/* ---------- palette ---------- */

.palette-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: grid;
    place-items: start center;
    padding-top: 11vh;
    background: var(--overlay);
    animation: fade-in 120ms ease;
}

.palette-overlay[hidden] {
    display: none;
}

.palette {
    width: min(520px, 92vw);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    box-shadow: var(--shadow-overlay);
    overflow: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 150ms ease, transform 150ms cubic-bezier(0.2, 0, 0.2, 1);
}

.palette-overlay.is-open .palette {
    opacity: 1;
    transform: none;
}

#palette-input {
    width: 100%;
    padding: 13px 16px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    font-size: 13.5px;
}

#palette-input:focus {
    outline: none;
}

.palette-list {
    max-height: 44vh;
    padding: 5px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--ink-2);
}

.palette-item i {
    width: 14px;
    color: var(--muted);
}

.palette-item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.palette-item.is-active i {
    color: var(--accent);
}

.palette-label {
    flex: 1;
}

.palette-item kbd {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
}

.palette-empty {
    padding: 14px;
    text-align: center;
    color: var(--muted);
    font-size: 12.5px;
}

/* ---------- toasts ---------- */

.toast-container {
    position: fixed;
    left: 50%;
    bottom: calc(var(--statusbar) + 14px);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--surface);
    box-shadow: var(--shadow-overlay);
    font-size: 12px;
    color: var(--ink);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 180ms ease, transform 180ms cubic-bezier(0.2, 0, 0.2, 1);
}

.toast.is-visible {
    opacity: 1;
    transform: none;
}

.toast i {
    font-size: 12px;
}

.toast-success i { color: var(--success); }
.toast-error i { color: var(--error); }
.toast-warning i { color: var(--warning); }
.toast-info i { color: var(--accent); }

.toast-close {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

.toast-close:hover {
    color: var(--ink);
}

.exit-focus {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 11.5px;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity var(--ease), color var(--ease), border-color var(--ease);
}

.exit-focus:hover {
    opacity: 1;
    color: var(--ink);
    border-color: var(--line-strong);
}

.exit-focus[hidden] {
    display: none;
}

/* ---------- focus mode ---------- */

html.focus-mode .topbar,
html.focus-mode .statusbar,
html.focus-mode .drawer,
html.focus-mode .drawer-backdrop {
    display: none;
}

html.focus-mode .app {
    grid-template-rows: minmax(0, 1fr);
}

html.focus-mode .pane-bar {
    display: none;
}

html.focus-mode .editor-wrap,
html.focus-mode .preview {
    padding-top: 36px;
}

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

@media (max-width: 860px) {
    .splitter {
        display: none;
    }

    .panes {
        flex-direction: column;
    }

    .pane {
        flex: 1 1 50%;
        min-height: 180px;
    }

    .preview {
        padding: 28px 22px 40vh;
    }

    #markdown-input,
    .editor-layer {
        padding: 20px 22px 40vh;
    }

    .doc-title {
        width: 34vw;
    }
}

@media (max-width: 560px) {
    .field-row {
        grid-template-columns: 1fr;
    }

    .gauge {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .gauge-value {
        text-align: left;
    }

    .status-right #storage-status {
        display: none;
    }

    .doc-title {
        width: 28vw;
    }
}

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

@media print {
    .topbar,
    .statusbar,
    .drawer,
    .drawer-backdrop,
    .pane-bar,
    .splitter,
    #editor-pane,
    .menu,
    .toast-container,
    .modal,
    .palette-overlay {
        display: none !important;
    }

    .app {
        display: block;
        height: auto;
    }

    .pane {
        display: block;
    }

    .preview {
        max-width: none;
        padding: 0;
        overflow: visible;
    }
}
