/* Markdown editor: the full-screen app (bar, editor, preview, status), its menus, and the page below it.
   White and quiet: hairlines instead of boxes, one dark primary button, everything else ghost. Dark via app.css tokens,
   plus a forced dark theme from the menu ([data-theme="dark"]). Preview typography lives in preview.css. */
:root[data-theme="dark"] { --bg: #101113; --surface: #17191c; --ink: #ecebe7; --ink2: #cfcdc7; --muted: #9b9a94; --line: #2a2d31; --soft: #1e2125; --accent: #ecebe7; --accent-fg: #101113; --link: #8fb0ff; --focus: #8fb0ff; --bubble: #1b2433; --bubble-ink: #9dbcf0; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25); color-scheme: dark }
:root { --md-bg: #ffffff; --md-hair: #ececea; --md-hover: #f3f3f1; --md-chip: #ffffff; --md-track: #f1f1ef; --md-menu: #ffffff; --md-amber: #d97706; --md-green: #16a34a }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --md-bg: #141517; --md-hair: #26282c; --md-hover: #1f2124; --md-chip: #2a2d31; --md-track: #1c1e21; --md-menu: #1c1e21; --md-amber: #f59e0b; --md-green: #4ade80 } }
:root[data-theme="dark"] { --md-bg: #141517; --md-hair: #26282c; --md-hover: #1f2124; --md-chip: #2a2d31; --md-track: #1c1e21; --md-menu: #1c1e21; --md-amber: #f59e0b; --md-green: #4ade80 }

.md-app { --split: 50%; position: relative; display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh; min-height: 420px; background: var(--md-bg); color: var(--ink); font: 14px/1.4 var(--sans); overflow: hidden }

/* Bar */
.md-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; height: 52px; padding: 0 10px 0 12px; border-bottom: 1px solid var(--md-hair) }
.md-file { display: flex; align-items: center; gap: 6px; min-width: 0 }
.md-home { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; transition: background .15s }
.md-home:hover { background: var(--md-hover) }
.md-home svg { display: block; border-radius: 7px }
.md-name { min-width: 0; width: 100%; max-width: 340px; height: 34px; padding: 0 10px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--ink); font: 600 14.5px/1 var(--sans); letter-spacing: -.005em; text-overflow: ellipsis; transition: background .15s, border-color .15s }
.md-name:hover { background: var(--md-hover) }
.md-name:focus { outline: none; background: var(--md-bg); border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent) }
.md-dirty { flex: none; width: 8px; height: 8px; margin-left: -2px; border-radius: 50%; background: var(--md-amber) }

.md-views { display: flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--md-track) }
.md-view { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: 550 13px/1 var(--sans); cursor: pointer; transition: color .15s, background .15s, box-shadow .15s }
.md-view:hover { color: var(--ink) }
.md-view[aria-checked="true"] { background: var(--md-chip); color: var(--ink); box-shadow: 0 1px 2px rgba(17, 19, 22, .08), 0 0 0 1px rgba(17, 19, 22, .04) }
.md-view svg { opacity: .9 }

.md-actions { position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 4px }
.md-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; color: var(--ink2); font: 550 13.5px/1 var(--sans); white-space: nowrap; cursor: pointer; transition: background .15s, color .15s, transform .1s }
.md-btn:hover { background: var(--md-hover); color: var(--ink) }
.md-btn:active { transform: translateY(.5px) }
.md-btn.md-icon { width: 34px; padding: 0 }
.md-split-btn { position: relative; display: flex; margin-left: 4px }
.md-primary { background: var(--ink); color: var(--md-bg) }
.md-primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--md-bg)); color: var(--md-bg) }
.md-split-btn > .md-primary:first-child { border-radius: 9px 0 0 9px; padding-right: 11px }
.md-caret { width: 28px; padding: 0; border-radius: 0 9px 9px 0; box-shadow: inset 1px 0 0 color-mix(in srgb, var(--md-bg) 22%, transparent) }
.md-caret svg { transition: transform .15s }
.md-caret[aria-expanded="true"] svg { transform: rotate(180deg) }

/* Menus */
.md-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; min-width: 232px; padding: 6px; border: 1px solid var(--md-hair); border-radius: 13px; background: var(--md-menu); box-shadow: 0 12px 32px rgba(17, 19, 22, .12), 0 2px 6px rgba(17, 19, 22, .06); transform-origin: top right; animation: md-pop .14s var(--ease) }
@keyframes md-pop { from { opacity: 0; transform: translateY(-4px) scale(.98) } }
.md-mi { display: flex; align-items: center; justify-content: space-between; gap: 24px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font: 450 13.5px/1 var(--sans); text-align: left; cursor: pointer }
.md-mi:hover, .md-mi:focus-visible { background: var(--md-hover); outline: none }
.md-mi[aria-checked] span:first-child::before { content: ""; display: inline-block; width: 16px; margin-right: 6px; text-align: center }
.md-mi[aria-checked="true"] span:first-child::before { content: "✓"; color: var(--link); font-weight: 700 }
.md-key { color: var(--muted); font: 450 12px/1 var(--sans); letter-spacing: .02em }
.md-sep { height: 1px; margin: 6px 4px; background: var(--md-hair) }
.md-mlabel { margin: 6px 10px 2px; color: var(--muted); font: 600 11px/1.4 var(--sans); letter-spacing: .06em; text-transform: uppercase }

/* Panes */
.md-panes { position: relative; display: grid; grid-template-columns: minmax(0, var(--split)) 1px minmax(0, 1fr); min-height: 0 }
.md-app[data-view="edit"] .md-panes { grid-template-columns: minmax(0, 1fr) 0 0 }
.md-app[data-view="preview"] .md-panes { grid-template-columns: 0 0 minmax(0, 1fr) }
.md-app[data-view="edit"] :is(.md-preview, .md-gutter), .md-app[data-view="preview"] :is(.md-editor, .md-gutter) { visibility: hidden }
.md-editor { position: relative; min-width: 0; min-height: 0; overflow: hidden }
.md-app[data-view="edit"] .md-editor { justify-self: center; width: min(100%, 980px) }
.md-text { display: block; width: 100%; height: 100%; padding: 20px 24px 40vh 56px; border: 0; resize: none; background: transparent; color: var(--ink); font: 15px/24px var(--mono); tab-size: 2; outline: none }
.md-text::placeholder { color: var(--muted) }
.md-editor .monaco-editor { --vscode-focusBorder: transparent }
.md-editor .monaco-editor .margin, .md-editor .monaco-editor-background { background: var(--md-bg) }

.md-gutter { position: relative; z-index: 2; background: var(--md-hair); cursor: col-resize; touch-action: none; outline: none }
.md-gutter::before { content: ""; position: absolute; inset: 0 -5px }
.md-gutter::after { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 3px; background: var(--focus); opacity: 0; transition: opacity .15s }
.md-gutter:hover::after, .md-gutter:focus-visible::after, .md-gutter.is-drag::after { opacity: 1; transition-delay: .1s }
.md-app.is-resizing { cursor: col-resize; user-select: none }
.md-app.is-resizing iframe, .md-app.is-resizing .md-panes > * { pointer-events: none }

.md-preview { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; scroll-padding-top: 24px; outline: none }
.md-preview:focus-visible { box-shadow: inset 0 0 0 2px var(--focus) }
.md-preview .md-doc { padding: 28px 40px 45vh }
@media (max-width: 1100px) { .md-preview .md-doc { padding: 24px 28px 45vh } }

/* Status */
.md-status { display: flex; align-items: center; gap: 18px; height: 30px; padding: 0 16px; border-top: 1px solid var(--md-hair); color: var(--muted); font: 450 12px/1 var(--sans); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden }
.md-stat { overflow: hidden; text-overflow: ellipsis }
.md-saved { display: inline-flex; align-items: center; gap: 6px; margin-left: auto }
.md-saved::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: .6 }
.md-saved[data-state="disk"]::before { background: var(--md-green); opacity: 1 }
.md-saved[data-state="dirty"]::before { background: var(--md-amber); opacity: 1 }
.md-about { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none }
.md-about:hover { color: var(--ink) }

/* Drop overlay */
.md-drop { position: absolute; inset: 8px; z-index: 40; display: grid; place-items: center; border: 2px dashed var(--focus); border-radius: 16px; background: color-mix(in srgb, var(--md-bg) 88%, transparent); backdrop-filter: blur(2px); pointer-events: none; animation: md-fade .12s ease }
.md-drop p { margin: 0; padding: 12px 18px; border-radius: 12px; background: var(--md-bg); color: var(--ink); font: 600 16px/1.3 var(--sans); box-shadow: var(--shadow) }
@keyframes md-fade { from { opacity: 0 } }

/* Shortcuts dialog */
.md-dialog { width: min(520px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--md-hair); border-radius: 18px; background: var(--md-menu); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, .2) }
.md-dialog::backdrop { background: rgba(17, 19, 22, .28); backdrop-filter: blur(2px) }
.md-dialog h2 { margin: 0 0 16px; font-size: 1.15rem }
.md-keylist { display: grid; gap: 2px; margin: 0 0 20px }
.md-keylist div { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--md-hair); font-size: 14px }
.md-keylist dt { white-space: nowrap } .md-keylist dd { margin: 0; color: var(--ink2) }

/* Focus mode: just the text, centred. */
.md-app[data-focus] { grid-template-rows: 0 1fr 0 }
.md-app[data-focus] :is(.md-bar, .md-status) { visibility: hidden; overflow: hidden; border: 0 }
.md-app[data-focus] .md-panes { grid-template-columns: minmax(0, 1fr) 0 0 }
.md-app[data-focus] :is(.md-preview, .md-gutter) { visibility: hidden }
.md-app[data-focus] .md-editor { justify-self: center; width: min(100%, 820px); padding-top: 6vh }

/* Code blocks: copy button */
.md-doc pre { position: relative }
.code-copy { position: absolute; top: 8px; right: 8px; height: 26px; padding: 0 10px; border: 1px solid var(--md-hair); border-radius: 7px; background: var(--md-bg); color: var(--muted); font: 550 12px/1 var(--sans); opacity: 0; cursor: pointer; transition: opacity .15s }
.md-doc pre:hover .code-copy, .code-copy:focus-visible { opacity: 1 }
.code-copy:hover { color: var(--ink) }

/* Narrow screens: labels go, the split view goes (one pane at a time). */
@media (max-width: 1080px) { .md-actions .md-btn:not(.md-primary) span, .md-view span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0) } .md-view { padding: 0 10px } .md-actions .md-btn:not(.md-primary):not(.md-caret) { width: 34px; padding: 0 } }
@media (max-width: 760px) {
  .md-bar { grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; padding: 0 6px 0 8px }
  .md-view-split { display: none }
  .md-app[data-view="split"] .md-panes { grid-template-columns: minmax(0, 1fr) 0 0 }
  .md-app[data-view="split"] :is(.md-preview, .md-gutter) { visibility: hidden }
  .md-split-btn > .md-primary:first-child span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0) }
  .md-split-btn > .md-primary:first-child { width: 36px; padding: 0 }
  .md-actions .md-btn[data-cmd="open"] { display: none }
  .md-pos, .md-about { display: none }
  .md-text { padding: 16px 16px 40vh; font-size: 16px }
  .md-preview .md-doc { padding: 20px 18px 40vh }
}

/* Print / PDF: only the preview, on white. */
@media print {
  @page { margin: 18mm 16mm }
  body > :not(.md-app) { display: none !important }
  html, body { background: #fff !important }
  .md-app { display: block; height: auto; min-height: 0; overflow: visible; background: #fff }
  .md-bar, .md-status, .md-editor, .md-gutter, .md-drop, .md-dialog, .code-copy { display: none !important }
  .md-panes { display: block }
  .md-preview { visibility: visible !important; overflow: visible; height: auto }
  .md-preview .md-doc { max-width: none; padding: 0 }
}

/* Page below the app */
.md-steps { list-style: none; counter-reset: s; padding: 0; margin: 20px 0 24px; display: grid; gap: 20px }
.md-steps li { counter-increment: s; position: relative; min-height: 32px; padding-left: 48px }
.md-steps li::before { content: counter(s); position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); font: 700 .92rem/1 var(--display); color: var(--ink) }
/* The shared article rule gives every section h3 a 32px top margin; here the title sits level with its number. */
.ft-article .md-steps h3, .ft-article .md-uses h3 { margin: 0 0 4px }
.ft-article .md-steps h3 { padding-top: 5px }
.md-steps p, .md-uses p { margin: 0; color: var(--ink2) }
.md-uses { list-style: none; padding: 0; margin: 20px 0 8px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px }
.md-uses li { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface) }
.table-wrap { overflow-x: auto; margin: 16px 0 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface) }
.md-cheat { width: 100%; border-collapse: collapse; font-size: .95rem }
.md-cheat th, .md-cheat td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line) }
.md-cheat tr:last-child td { border-bottom: 0 }
.md-cheat th { font-size: .85rem; color: var(--muted); font-weight: 600 }
/* Each snippet and key is one unbreakable chip; the cell wraps between chips, never inside one. */
.md-cheat :is(code, kbd) { display: inline-block; margin: 1px 0; white-space: pre; line-height: 1.5 }
.md-cheat code { font: .88em/1.5 var(--mono); padding: .05em .4em; border-radius: 5px; background: var(--soft); color: var(--ink) }
.md-cheat td:first-child { width: 46% }
.md-keytable td.md-keys { width: 1%; white-space: nowrap; padding-right: 28px }
/* Phones: one row per block, the snippet on top and its meaning under it, so nothing scrolls sideways. */
@media (max-width: 640px) {
  .md-cheat:not(.md-keytable) thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%) }
  .md-cheat:not(.md-keytable) tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line) }
  .md-cheat:not(.md-keytable) tr:last-child { border-bottom: 0 }
  .md-cheat:not(.md-keytable) td { display: block; width: auto; padding: 0; border: 0 }
  .md-cheat:not(.md-keytable) td + td { margin-top: 4px; color: var(--ink2) }
  .md-keytable td { padding: 9px 12px } .md-keytable td.md-keys { padding-right: 20px }
}
