/* ==========================================================================
   Nib — 마크다운 에디터
   Palette, type scale and component shapes follow the Nib design system.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens */

:root {
  --paper: #FBFAF7;
  --sunk: #F2EFE8;
  --raised: #FFFFFF;
  --ink: #1B1A16;
  --ink2: #6D6961;
  --ink3: #9A958A;
  --line: #E5E1D6;
  --line2: #EFEBE1;
  --accent: oklch(0.55 0.13 45);
  --accent-soft: oklch(0.94 0.035 45);
  --teal: oklch(0.55 0.13 205);
  --teal-soft: oklch(0.94 0.035 205);
  --shell: #EDEAE1;
  --shadow: rgba(40, 34, 20, .5);

  --doc-fs: 16px;
  --split: 50%;

  --sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
          system-ui, "Segoe UI", "Malgun Gothic", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;

  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 22px;
}

[data-theme="dark"] {
  --paper: #15140F;
  --sunk: #1B1A14;
  --raised: #1E1D16;
  --ink: #EDE9DE;
  --ink2: #9C978A;
  --ink3: #6E6A5E;
  --line: #2C2A22;
  --line2: #242219;
  --accent: oklch(0.72 0.12 45);
  --accent-soft: oklch(0.32 0.05 45);
  --teal: oklch(0.72 0.11 205);
  --teal-soft: oklch(0.30 0.045 205);
  --shell: #0D0C09;
  --shadow: rgba(0, 0, 0, .7);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --paper: #15140F;
    --sunk: #1B1A14;
    --raised: #1E1D16;
    --ink: #EDE9DE;
    --ink2: #9C978A;
    --ink3: #6E6A5E;
    --line: #2C2A22;
    --line2: #242219;
    --accent: oklch(0.72 0.12 45);
    --accent-soft: oklch(0.32 0.05 45);
    --teal: oklch(0.72 0.11 205);
    --teal-soft: oklch(0.30 0.045 205);
    --shell: #0D0C09;
    --shadow: rgba(0, 0, 0, .7);
  }
}

[data-fs="0"] { --doc-fs: 14px }
[data-fs="1"] { --doc-fs: 15px }
[data-fs="2"] { --doc-fs: 16px }
[data-fs="3"] { --doc-fs: 18px }
[data-fs="4"] { --doc-fs: 20px }

/* ---------------------------------------------------------------- reset */

* { box-sizing: border-box }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--sans);
  background: var(--shell);
  color: var(--ink);
  font-size: 14px;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

svg { width: 100%; height: 100%; display: block }
svg[viewBox] { fill: none; stroke: currentColor; stroke-width: 1.6 }
svg.solid, .folder-chip svg, .ico-sun circle, .ico-moon path { fill: currentColor; stroke: none }
.ico-sun circle { fill: currentColor }
.ico-sun g { stroke: currentColor; stroke-width: 1.7 }

::-webkit-scrollbar { width: 9px; height: 9px }
::-webkit-scrollbar-thumb { background: color-mix(in oklab, var(--ink3) 45%, transparent); border-radius: 9px }
::-webkit-scrollbar-thumb:hover { background: color-mix(in oklab, var(--ink3) 70%, transparent) }
::-webkit-scrollbar-track { background: transparent }

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

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

@keyframes nibIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }
@keyframes nibUp { from { opacity: 0; transform: translateY(24px) } to { opacity: 1; transform: none } }
@keyframes nibFade { from { opacity: 0 } to { opacity: 1 } }

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

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 208px;
  grid-template-rows: minmax(0, 100%);
  background: var(--shell);
  color: var(--ink);
}

/* Grid and flex children default to min-height:auto, which lets tall content
   push a pane past the viewport and kill its scrollbar. Pin them all to 0. */
.sidebar, .main, .panel { min-height: 0; overflow: hidden }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--sunk);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 12px 10px 14px;
}

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

.brand-mark {
  width: 24px;
  height: 24px;
  flex: none;
  background: var(--accent);
  transform: rotate(45deg);
  border-radius: 4px 9px 4px 9px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0 }
.brand-text b { font-size: 15px; font-weight: 700; letter-spacing: -.02em }
.brand-text small { font-size: 10.5px; color: var(--ink2); white-space: nowrap }

.icon-btn {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: var(--r-md);
  color: var(--ink2);
  display: grid;
  place-items: center;
  transition: background .14s, color .14s;
}
.icon-btn svg { width: 18px; height: 18px }
.icon-btn:hover { background: color-mix(in oklab, var(--ink) 7%, transparent); color: var(--ink) }

.ico-moon { display: none }
[data-theme="dark"] .ico-sun { display: none }
[data-theme="dark"] .ico-moon { display: block }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .ico-sun { display: none }
  [data-theme="auto"] .ico-moon { display: block }
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 11px;
  transition: border-color .14s;
}
.field:focus-within { border-color: color-mix(in oklab, var(--accent) 55%, var(--line)) }
.field input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  outline: none;
  font-size: 13px;
}
.field input::placeholder { color: var(--ink3) }
.field input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none }
.field-plain { background: var(--sunk) }
.field-plain input { font-size: 14px }

.ico-glass {
  flex: none;
  width: 11px;
  height: 11px;
  border: 1.6px solid var(--ink3);
  border-radius: 50%;
  position: relative;
}
.ico-glass::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -3px;
  width: 6px;
  height: 1.7px;
  background: var(--ink3);
  border-radius: 2px;
  transform: rotate(45deg);
}

.sidebar-search { flex: none; margin: 0 12px 10px }

.sidebar-meta {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px 8px;
}

.folder-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--ink3);
  border-radius: 5px;
  padding: 2px 4px;
  margin-left: -4px;
  transition: color .14s;
}
.folder-chip:hover { color: var(--ink) }
.folder-chip svg { width: 13px; height: 13px; flex: none }
.folder-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }

.doc-count { flex: none; font-size: 11px; color: var(--ink3); font-family: var(--mono) }

.doc-list { flex: 1; overflow-y: auto; padding: 0 8px 10px; min-height: 0 }

.doc-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background .12s;
}
.doc-row:hover { background: color-mix(in oklab, var(--ink) 5%, transparent) }
.doc-row.is-active { background: var(--paper); border-color: var(--line) }

.doc-row .name {
  display: block;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Compact rows on desktop; the narrow layout re-enables the snippet. */
.doc-row .snippet {
  display: none;
  font-size: 12.5px;
  color: var(--ink2);
  line-height: 1.45;
  margin-top: 3px;
  overflow: hidden;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.doc-row .meta { display: block; font-size: 11px; color: var(--ink3); margin-top: 3px }
.doc-row.is-dirty .name::after { content: " ●"; color: var(--accent); font-size: 9px; vertical-align: 1px }

.empty-note {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink2);
  font-size: 13px;
  line-height: 1.7;
}
.empty-note b { display: block; color: var(--ink); font-size: 14.5px; margin-bottom: 6px; font-weight: 650 }

.sidebar-foot {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ghost-btn {
  padding: 6px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink2);
  white-space: nowrap;
  transition: color .14s, border-color .14s, background .14s;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--ink3) }
.ghost-btn.danger { color: oklch(0.55 0.18 25) }
[data-theme="dark"] .ghost-btn.danger { color: oklch(0.72 0.15 25) }
.ghost-btn.danger:hover { border-color: currentColor }

.solid-btn {
  padding: 8px 16px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 650;
}

.link-btn { font-size: 13.5px; font-weight: 650; color: var(--accent) }

.sidebar-foot .icon-btn { margin-left: auto }

/* ---------------------------------------------------------------- main */

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  position: relative;
}

.topbar {
  flex: none;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.doc-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--ink);
  padding: 5px 7px;
  margin-left: -7px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .14s;
}
.doc-title:hover { background: var(--sunk) }

.topbar-right { flex: none; display: flex; align-items: center; gap: 4px }

.save-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  margin-right: 4px;
  transition: background .2s;
}
.save-dot.is-dirty { background: var(--accent) }
.save-dot.is-saving { background: var(--teal) }

.segmented {
  display: flex;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
  margin-right: 4px;
}
.segmented button {
  padding: 4px 11px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 650;
  color: var(--ink3);
  white-space: nowrap;
  transition: background .14s, color .14s;
}
.segmented button:hover { color: var(--ink) }
.segmented button.is-on {
  background: var(--raised);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .09);
}

/* ---------------------------------------------------------------- panes */

.workspace { flex: 1; display: flex; min-height: 0; position: relative }

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

.pane-edit { flex: 0 0 var(--split); border-right: 1px solid var(--line) }
.pane-read { flex: 1 }

[data-view="read"] .pane-edit,
[data-view="read"] .pane-split { display: none }
[data-view="read"] .pane-read { flex: 1 }

[data-view="edit"] .pane-read,
[data-view="edit"] .pane-split { display: none }
[data-view="edit"] .pane-edit { flex: 1; border-right: none }

.pane-split {
  flex: none;
  width: 5px;
  margin: 0 -2px;
  cursor: col-resize;
  z-index: 3;
  background: transparent;
  transition: background .15s;
}
.pane-split:hover, .pane-split.is-dragging { background: color-mix(in oklab, var(--accent) 45%, transparent) }

/* toolbar */

.toolbar {
  flex: none;
  height: 37px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line2);
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none }

.tool {
  flex: none;
  height: 25px;
  min-width: 27px;
  padding: 0 8px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink2);
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.tool:hover { background: var(--sunk); color: var(--ink) }
.tool:active { background: var(--accent-soft); color: var(--ink) }
.tool-sep { flex: none; width: 1px; height: 15px; background: var(--line); margin: 0 5px }

/* textarea + measuring mirror */

.editor-wrap { flex: 1; position: relative; min-height: 0 }

#editor, .editor-mirror {
  position: absolute;
  inset: 0;
  width: 100%;
  padding: 20px 22px 40vh;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.8;
  letter-spacing: -.01em;
  border: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  tab-size: 4;
}

#editor {
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  overflow-y: auto;
  caret-color: var(--accent);
}
#editor::placeholder { color: var(--ink3) }

.editor-mirror {
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  color: transparent;
}

/* preview */

.pane-read { overflow: hidden; background: var(--paper) }

.md {
  flex: 1;
  overflow-y: auto;
  padding: 34px 42px 40vh;
  font-size: var(--doc-fs);
  line-height: 1.72;
  letter-spacing: -.005em;
  max-width: 100%;
  /* No scroll-behavior:smooth here — split-view scroll sync needs instant
     positioning. Jumps that should glide pass behavior:'smooth' explicitly. */
}
.md > *:first-child { margin-top: 0 }

/* statusbar */

.statusbar {
  flex: none;
  height: 26px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border-top: 1px solid var(--line2);
  background: var(--sunk);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink3);
}
.statusbar .grow { flex: 1 }
.dot-sep { opacity: .5 }

/* ---------------------------------------------------------------- panels */

.panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--sunk);
  border-left: 1px solid var(--line);
  min-height: 0;
}

.panel-head {
  flex: none;
  padding: 14px 16px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink3);
  letter-spacing: .06em;
}

.sheet-grip { display: none }

.toc { flex: 1; overflow-y: auto; padding: 0 8px 16px; min-height: 0 }

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink2);
  transition: background .12s, color .12s;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-item:hover { background: var(--paper); color: var(--ink) }
.toc-item.is-current { color: var(--ink); font-weight: 650 }
.toc-item .tag { display: none }
.toc-item.lv1 { padding-left: 8px; font-weight: 650 }
.toc-item.lv2 { padding-left: 19px }
.toc-item.lv3 { padding-left: 30px }
.toc-item.lv4 { padding-left: 41px }
.toc-item.lv5 { padding-left: 52px }
.toc-item.lv6 { padding-left: 63px }

/* in-document search — floats over the preview on wide screens */

.panel-search {
  position: absolute;
  top: 54px;
  right: 16px;
  width: 340px;
  max-height: min(60vh, 480px);
  z-index: 30;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 50px -22px var(--shadow);
  animation: nibIn .18s ease both;
  display: none;
}
.panel-search.is-open { display: flex }

.panel-search-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 8px 12px;
  border-bottom: 1px solid var(--line2);
}
.panel-search-head .field { flex: 1 }
.hit-count { flex: none; font-family: var(--mono); font-size: 11.5px; color: var(--ink3) }

.hits { flex: 1; overflow-y: auto; padding: 6px; min-height: 0 }

.hit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-md);
  transition: background .12s;
}
.hit:hover { background: var(--sunk) }
.hit .line { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--ink3); margin-bottom: 3px }
.hit .text {
  display: block;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- scrim, sheets, modals */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 10, .38);
  z-index: 25;
  display: none;
  animation: nibFade .18s ease both;
}
.scrim.is-open { display: block }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(20, 17, 10, .42);
  animation: nibFade .16s ease both;
}
.modal.is-open { display: grid }

.modal-card {
  width: min(460px, 100%);
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 30px 60px -20px var(--shadow);
  animation: nibIn .2s ease both;
}
.modal-narrow { width: min(380px, 100%) }

.modal-head {
  flex: none;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--line2);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.02em }

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

.modal-foot {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 16px 16px;
}

.ask-text { margin: 0 0 12px; font-size: 13.5px; line-height: 1.6; color: var(--ink2) }
.ask-text:empty { display: none }

.group-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink3);
  letter-spacing: .06em;
  padding: 0 6px 8px;
}
.group-label:not(:first-child) { padding-top: 20px }

.group {
  background: var(--raised);
  border: 1px solid var(--line2);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line2);
  font-size: 14px;
}
.row:last-child { border-bottom: none }
.row > span { display: flex; flex-direction: column; gap: 2px; min-width: 0 }
.row small { font-size: 11.5px; color: var(--ink3) }
.row code { font-family: var(--mono); font-size: 12.5px; color: var(--ink3) }

.stepper { display: flex; align-items: center; gap: 12px; flex: none }
.stepper button {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--sunk);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink2);
}
.stepper button:hover { color: var(--ink) }
.stepper b { font-family: var(--mono); font-size: 12.5px; width: 40px; text-align: center; font-weight: 500 }

.switch {
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  padding: 3px;
  display: flex;
  justify-content: flex-start;
  background: var(--line);
  transition: background .18s;
}
.switch i {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .18s cubic-bezier(.3, .8, .4, 1);
}
.switch.is-on { background: var(--accent) }
.switch.is-on i { transform: translateX(18px) }

.keys-body { display: flex; flex-direction: column; gap: 0 }
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 6px;
  border-bottom: 1px solid var(--line2);
  font-size: 13.5px;
}
.key-row:last-child { border-bottom: none }
.key-row kbd {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 6px;
  color: var(--ink2);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- fab, toast, dropzone */

.fab-row {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  justify-content: center;
  gap: 8px;
  pointer-events: none;
  z-index: 15;
}
.fab { pointer-events: auto }

.fab-mode {
  height: 46px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  box-shadow: 0 10px 26px -8px var(--shadow);
}
.fab-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--accent) }
[data-view="edit"] .fab-dot { background: var(--teal) }

.fab-round {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 26px -12px var(--shadow);
}
.fab-round svg { width: 18px; height: 18px }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  z-index: 90;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 30px -12px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0) }

.dropzone {
  position: fixed;
  inset: 12px;
  z-index: 80;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--r-xl);
  background: color-mix(in oklab, var(--paper) 88%, transparent);
  backdrop-filter: blur(2px);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}
.dropzone.is-on { display: grid }

/* ==========================================================================
   markdown output
   ========================================================================== */

.md-h { font-weight: 700; letter-spacing: -.03em; line-height: 1.3; scroll-margin-top: 12px }
.md-h1 { font-size: 2.05em; font-weight: 800; margin: 0 0 .5em }
.md-h2 {
  font-size: 1.42em;
  font-weight: 800;
  margin: 1.5em 0 .5em;
  padding-bottom: .3em;
  border-bottom: 1px solid var(--line2);
}
.md-h3 { font-size: 1.14em; margin: 1.25em 0 .4em }
.md-h4 { font-size: 1em; margin: 1.2em 0 .35em }
.md-h5 { font-size: .94em; margin: 1.2em 0 .35em }
.md-h6 { font-size: .9em; margin: 1.2em 0 .35em; color: var(--ink2) }

.md-p { margin: .85em 0; text-wrap: pretty }

.md-link {
  color: var(--teal);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in oklab, var(--teal) 35%, transparent);
}
.md-link:hover { color: var(--accent); border-bottom-color: var(--accent) }

.md-strike { text-decoration: line-through; color: var(--ink3) }
.md-mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 .12em }
.md-hit { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 .1em }

.md-code-inline {
  font-family: var(--mono);
  font-size: .86em;
  background: var(--sunk);
  border: 1px solid var(--line2);
  border-radius: 5px;
  padding: .1em .35em;
  overflow-wrap: break-word;
}

.md-hr { border: none; border-top: 1px solid var(--line); margin: 2em 0 }

/* lists */

.md-list { margin: .7em 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: .34em }
.md-list.is-tight { gap: .22em }
.md-list .md-list { margin: .3em 0 0 }
.md-li { padding-left: .15em }
.md-li > .md-p:first-child { margin-top: 0 }
.md-li > .md-p:last-child { margin-bottom: 0 }

.md-list-task { padding-left: .1em }
.md-task { list-style: none; display: flex; gap: .6em; align-items: flex-start }
.md-task-body { flex: 1; min-width: 0 }
.md-task-body > .md-p:first-child { margin-top: 0 }
.md-task-body > .md-p:last-child { margin-bottom: 0 }
.md-task.is-done > .md-task-body { color: var(--ink3); text-decoration: line-through }
.md-task.is-done > .md-task-body .md-list { text-decoration: none }

.md-checkbox {
  flex: none;
  width: 1.05em;
  height: 1.05em;
  margin-top: .3em;
  border-radius: 5px;
  border: 1.6px solid var(--line);
  display: inline-grid;
  place-items: center;
  color: var(--paper);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.md-checkbox:hover { border-color: var(--accent) }
.md-task.is-done > .md-checkbox { background: var(--accent); border-color: var(--accent) }
.md-checkbox svg { width: .7em; height: .7em; stroke: currentColor }

/* quote + alerts */

.md-quote {
  margin: 1.2em 0;
  padding: .15em 0 .15em 1.1em;
  border-left: 3px solid var(--accent);
  color: var(--ink2);
}
.md-quote > *:first-child { margin-top: 0 }
.md-quote > *:last-child { margin-bottom: 0 }

.md-alert {
  margin: 1.2em 0;
  padding: 13px 16px;
  border-radius: var(--r-md);
  border: 1px solid color-mix(in oklab, var(--ink2) 28%, transparent);
  background: var(--sunk);
}
.md-alert-kind { font-size: .74em; font-weight: 800; letter-spacing: .08em; margin-bottom: .45em; color: var(--ink2) }
.md-alert-body > *:first-child { margin-top: 0 }
.md-alert-body > *:last-child { margin-bottom: 0 }

.md-alert-tip { background: var(--teal-soft); border-color: color-mix(in oklab, var(--teal) 32%, transparent) }
.md-alert-tip .md-alert-kind { color: var(--teal) }
.md-alert-warning, .md-alert-caution {
  background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 32%, transparent);
}
.md-alert-warning .md-alert-kind, .md-alert-caution .md-alert-kind { color: var(--accent) }
.md-alert-important { background: var(--accent-soft); border-color: color-mix(in oklab, var(--accent) 26%, transparent) }
.md-alert-important .md-alert-kind { color: var(--accent) }

/* tables */

.md-table-wrap {
  margin: 1.2em 0;
  overflow-x: auto;
  border: 1px solid var(--line2);
  border-radius: var(--r-md);
}
.md-table { border-collapse: collapse; width: 100%; font-size: .9em }
.md-table th {
  padding: 10px 13px;
  background: var(--sunk);
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  white-space: nowrap;
}
.md-table td { padding: 10px 13px; border-bottom: 1px solid var(--line2) }
.md-table tbody tr:last-child td { border-bottom: none }

/* code blocks */

.md-code {
  margin: 1.2em 0;
  border: 1px solid var(--line2);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--sunk);
}
.md-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 6px 13px;
  border-bottom: 1px solid var(--line2);
  font-family: var(--mono);
  font-size: .72em;
  font-weight: 700;
  color: var(--ink3);
  letter-spacing: .05em;
  min-height: 28px;
}
.md-copy {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink3);
  padding: 3px 8px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity .14s, background .14s, color .14s;
}
.md-code:hover .md-copy, .md-copy:focus-visible { opacity: 1 }
.md-copy:hover { background: var(--paper); color: var(--ink) }

.md-code-body { display: flex; font-family: var(--mono); font-size: .82em; line-height: 1.65; overflow-x: auto }
.md-code-gutter {
  flex: none;
  padding: 14px 10px;
  text-align: right;
  color: var(--ink3);
  border-right: 1px solid var(--line2);
  user-select: none;
  font-size: .85em;
  line-height: calc(1.65 / .85);
}
[data-linenos="0"] .md-code-gutter { display: none }
.md-pre { margin: 0; padding: 14px 15px; flex: 1; white-space: pre }
.md-pre code { font: inherit }
.md-code-raw { display: none }

.tok-kw { color: var(--teal) }
.tok-str { color: var(--accent) }
.tok-com { color: var(--ink3); font-style: italic }
.tok-num { color: var(--ink2) }
.tok-fn { color: color-mix(in oklab, var(--teal) 70%, var(--ink)) }
.tok-add { color: oklch(0.52 0.13 145) }
.tok-del { color: oklch(0.55 0.16 25) }
.tok-meta { color: var(--ink3) }
[data-theme="dark"] .tok-add { color: oklch(0.74 0.13 145) }
[data-theme="dark"] .tok-del { color: oklch(0.72 0.15 25) }

/* images */

.md-figure { margin: 1.4em 0 }
.md-figure img, .md-img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--line2);
  display: block;
}
.md-img { display: inline-block; vertical-align: middle; max-height: 1.6em; border: none; border-radius: 4px }
.md-figure figcaption { font-size: .78em; color: var(--ink3); margin-top: .6em; text-align: center }

.md-img-missing {
  aspect-ratio: 16 / 9;
  border-radius: var(--r-md);
  border: 1px solid var(--line2);
  background: repeating-linear-gradient(135deg, var(--sunk), var(--sunk) 9px, var(--line2) 9px, var(--line2) 10px);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: .72em;
  color: var(--ink2);
}
.md-img-missing span {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 11px;
}

/* footnotes */

.md-fnref a { color: var(--accent); font-weight: 700; text-decoration: none; font-size: .78em }
.md-notes {
  margin-top: 2.4em;
  padding-top: 1.2em;
  border-top: 1px solid var(--line2);
  font-size: .86em;
  color: var(--ink2);
  display: flex;
  flex-direction: column;
  gap: .5em;
}
.md-notes-title { font-size: 1em; font-weight: 700; color: var(--ink3); margin: 0 0 .2em; letter-spacing: .04em }
.md-note { display: flex; gap: .6em; scroll-margin-top: 20px }
.md-note-id { color: var(--accent); font-weight: 700; flex: none }

/* math */

.md-math-inline, .md-math-block { font-family: Georgia, "Times New Roman", serif }
.md-math-block {
  margin: 1.3em 0;
  padding: 20px 16px;
  background: var(--sunk);
  border: 1px solid var(--line2);
  border-radius: var(--r-md);
  text-align: center;
  font-size: 1.06em;
  overflow-x: auto;
}
.m-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: -0.55em;
  margin: 0 .22em;
}
.m-num { padding: 0 .3em .12em }
.m-den { border-top: 1px solid currentColor; padding: .12em .3em 0 }
.m-big {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1;
  margin: 0 .18em;
}
.m-big .m-op { font-size: 1.5em }
.m-big .m-lim { font-size: .58em }
.m-fn { font-style: normal }
.m-sp { padding: 0 .28em }
.m-sqrt::before { content: "√" }
.m-sqrt { border-top: 1px solid currentColor; padding: 0 .1em }

/* mermaid */

.md-mermaid {
  margin: 1.4em 0;
  padding: 22px 16px;
  background: var(--sunk);
  border: 1px solid var(--line2);
  border-radius: var(--r-md);
  overflow-x: auto;
}
.mm-graph { display: flex; flex-direction: column; align-items: center; min-width: max-content; margin: 0 auto }
.mm-row { display: flex; gap: 22px; align-items: center }
.mm-arrows { padding: 6px 0 }
.mm-node {
  padding: 9px 16px;
  background: var(--raised);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink);
}
.mm-diamond { border-color: var(--accent); border-radius: 999px; padding: 9px 20px }
.mm-round, .mm-circle { border-radius: 999px }
.mm-arrow { display: flex; flex-direction: column; align-items: center; gap: 2px }
.mm-stem { width: 1.5px; height: 14px; background: var(--ink3) }
.mm-label { font-size: 10.5px; color: var(--ink2); background: var(--sunk); padding: 0 4px; font-weight: 600 }
.mm-head {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid var(--ink3);
}

/* ==========================================================================
   responsive
   ========================================================================== */

/* medium — the table of contents becomes an overlay */
@media (max-width: 1180px) {
  .app { grid-template-columns: 234px minmax(0, 1fr) }
  .panel-toc {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 250px;
    z-index: 30;
    box-shadow: -16px 0 40px -20px var(--shadow);
    transform: translateX(100%);
    transition: transform .22s cubic-bezier(.2, .9, .3, 1);
    background: var(--raised);
  }
  .panel-toc.is-open { transform: none }
}

/* narrow — one screen at a time, phone shape */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr }

  .sidebar { grid-column: 1; grid-row: 1; border-right: none }
  .main { grid-column: 1; grid-row: 1 }

  .app[data-screen="list"] .main { display: none }
  .app[data-screen="doc"] .sidebar { display: none }

  .sidebar-head { padding: 18px 14px 12px }
  .brand-text b { font-size: 21px; letter-spacing: -.03em }
  .brand-mark { width: 27px; height: 27px }

  .doc-list { padding: 0 10px 14px }
  .doc-row { padding: 12px 12px; border-radius: var(--r-lg); margin-bottom: 3px }
  .doc-row .name { font-family: var(--sans); font-size: 15.5px; font-weight: 650; letter-spacing: -.015em }
  .doc-row .snippet { display: -webkit-box }
  .doc-row .meta { font-family: var(--mono); font-size: 11.5px; margin-top: 6px }

  .sidebar-foot { padding: 10px 12px max(10px, env(safe-area-inset-bottom)) }
  .ghost-btn { padding: 9px 14px; font-size: 13.5px }

  .topbar { height: 50px; padding: 0 6px 0 4px }
  .doc-title { text-align: center; font-size: 14px }
  .segmented .wide-only { display: none }

  .statusbar { display: none }
  .fab-row { display: flex }

  .md { padding: 22px 20px 130px }
  #editor, .editor-mirror { padding: 18px 18px 40vh; font-size: 14px }
  .toolbar { height: 42px; padding: 0 6px }
  .tool { height: 30px; min-width: 32px; font-size: 13px; border-radius: 8px }

  /* panels become bottom sheets */
  .panel-toc, .panel-search {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    width: auto;
    max-height: 74vh;
    height: auto;
    transform: translateY(100%);
    transition: transform .26s cubic-bezier(.2, .9, .3, 1);
    background: var(--raised);
    border: none;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: 0 -12px 40px -16px var(--shadow);
    z-index: 30;
    padding-bottom: env(safe-area-inset-bottom);
    animation: none;
  }
  .panel-search { display: flex; height: 74vh }
  .panel-toc.is-open, .panel-search.is-open { transform: none }

  .sheet-grip {
    display: block;
    flex: none;
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    margin: 12px auto 4px;
  }
  .panel-head { padding: 6px 20px 8px; font-size: 12.5px }
  .toc { padding: 0 12px 24px }
  .toc-item { padding: 11px 12px; font-size: 15px; border-radius: 11px }
  .toc-item.lv1 { padding-left: 12px }
  .toc-item.lv2 { padding-left: 26px }
  .toc-item.lv3 { padding-left: 40px }
  .toc-item.lv4 { padding-left: 54px }
  .toc-item.lv5, .toc-item.lv6 { padding-left: 66px }

  .panel-search-head { padding: 8px 12px 10px }
  .hits { padding: 4px 8px 24px }
  .hit { padding: 12px }
  .hit .text { font-size: 14px }

  .modal { padding: 0; place-items: end stretch }
  .modal-card {
    width: 100%;
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: nibUp .24s cubic-bezier(.2, .9, .3, 1) both;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-narrow { width: 100% }

  .pane-split { display: none }
}

@media (min-width: 861px) {
  .only-narrow { display: none }
  .panel-toc.is-open { display: flex }
}

@media (max-width: 480px) {
  .md { padding: 20px 16px 130px }
  .md-code-gutter { padding: 14px 7px }
  .md-pre { padding: 14px 11px }
}

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

@media print {
  .sidebar, .topbar, .toolbar, .statusbar, .panel, .fab-row, .pane-edit, .pane-split { display: none !important }
  .app { display: block; height: auto }
  html, body { overflow: visible; height: auto; background: #fff }
  .main { height: auto }
  .md { overflow: visible; padding: 0 }
}
