/* Картотека: тёплая бумага и чернила. Мобильная вёрстка по умолчанию. */
:root {
  --bg: #131210; --paper: #1c1a16; --paper-2: #232019; --line: #34302a;
  --text: #efe8d8; --muted: #aaa190; --accent: #f2b84b; --accent-ink: #1a1200;
  --margin: #e0705a; --rule: rgba(242, 184, 75, .09); --mark: rgba(242, 184, 75, .32);
  --add: #7fd48b; --add-bg: rgba(127, 212, 139, .12); --del: #f08a7a; --del-bg: rgba(240, 138, 122, .13);
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .35);
  --serif: "Literata", "PT Serif", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --g0: #f2b84b; --g1: #7fb8f0; --g2: #8fd49a; --g3: #e0846f; --g4: #c39be6; --g5: #6fd0c8;
}
:root[data-theme="light"] {
  --bg: #e8e0cf; --paper: #fbf7ec; --paper-2: #f3ecdb; --line: #d3c9b1;
  --text: #231f17; --muted: #5d5444; --accent: #8a5200; --accent-ink: #fffaf0;
  --margin: #b3402a; --rule: rgba(138, 82, 0, .10); --mark: #f6d57a;
  --add: #1f6b2c; --add-bg: #dff1df; --del: #9b2a1a; --del-bg: #f8dfd9;
  --shadow: 0 1px 0 #fff inset, 0 6px 18px rgba(80, 60, 20, .12);
  --g0: #8a5200; --g1: #1f5f9e; --g2: #2b7a3a; --g3: #a63c24; --g4: #7a4aa8; --g5: #14756d;
}

* { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
html[data-theme="light"] { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.55 var(--sans); min-height: 100dvh; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.kit-nav { position: static; margin-bottom: 4px; --kit-nav-bg: color-mix(in srgb, var(--paper) 90%, transparent); --kit-nav-fg: var(--text); --kit-nav-fg-muted: var(--muted);
  --kit-nav-border: var(--line); --kit-nav-current-bg: var(--accent); --kit-nav-current-fg: var(--accent-ink); --kit-nav-focus: var(--accent);
  --kit-nav-panel-bg: var(--paper); --kit-nav-font: var(--sans); --kit-nav-blur: none; --kit-nav-shadow: var(--shadow); }
.cards-wrap { min-height: 260px; }
.cards-wrap .kit-sk-layer { display: grid; gap: 10px; align-content: start; }
.sk-card { height: 76px; border-radius: 4px 12px 12px 12px; }
.side-foot { display: grid; gap: 10px; justify-items: start; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.foot-link { color: var(--accent); font-size: 14px; }
.side-foot [data-kit-contacts] { --kit-contacts-border: var(--line); --kit-contacts-fg: var(--text); --kit-contacts-focus: var(--accent); }
a { color: var(--accent); }
kbd { font: 500 .78em var(--mono); background: var(--paper-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; color: var(--muted); }
code { font-family: var(--mono); font-size: .9em; }

/* шапка */
.top { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; font: 600 15px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--text); text-decoration: none; }
.brand .tab { width: 22px; height: 16px; border-radius: 3px 8px 3px 3px; background: var(--accent); position: relative; }
.brand .tab::after { content: ""; position: absolute; left: 0; top: -4px; width: 10px; height: 5px; border-radius: 3px 3px 0 0; background: var(--margin); }
.tools { display: flex; gap: 4px; }
.search { grid-column: 1 / -1; grid-row: 2; position: relative; }
.search input { width: 100%; padding-right: 64px; }
.search kbd { display: none; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }

/* элементы форм */
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--rule); }
select { width: auto; max-width: 100%; }
.fld { display: block; margin: 16px 0 6px; font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.title-in { font: 600 22px/1.3 var(--serif); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--text); font: 500 14px var(--sans); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .15s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--del); }
.btn.icon { width: 44px; padding: 0; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.err { color: var(--del); min-height: 1.4em; margin: 6px 0 0; }

/* каркас: на телефоне либо список, либо заметка */
.app { display: block; }
.side { padding: 14px 16px 90px; }
.main { padding: 0 16px 60px; outline: none; }
.app[data-view="list"] .main { display: none; }
.app:not([data-view="list"]) .side { display: none; }
.back { margin-left: -10px; }

.side-head { display: grid; gap: 12px; }
.count { margin: 14px 0 8px; font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { position: relative; display: block; padding: 12px 14px 12px 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; color: var(--text); text-decoration: none; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); opacity: .0; border-radius: 4px 0 0 12px; }
.card:hover { border-color: var(--accent); }
.card[aria-current="page"]::before { opacity: 1; }
.card[aria-current="page"] { border-color: var(--accent); }
.card h3 { margin: 0; font: 600 17px/1.3 var(--serif); overflow-wrap: anywhere; }
.card .snip { margin: 6px 0 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.card .cmeta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; font: 400 12px var(--mono); color: var(--muted); }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; min-height: 32px; padding: 2px 11px; border: 1px solid var(--line); border-radius: 9999px; background: transparent; color: var(--muted); font: 500 12px var(--mono); cursor: pointer; }
.tag::before { content: "#"; opacity: .6; margin-right: 1px; }
.tag:hover { border-color: var(--accent); color: var(--text); }
.tag[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tag small { margin-left: 6px; opacity: .75; font-size: 11px; }

/* заметка */
.bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 0; position: sticky; top: 110px; z-index: 10; background: var(--bg); }
.tabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--paper); border: 1px solid var(--line); border-radius: 9999px; }
.tabs button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 9999px; background: transparent; color: var(--muted); font: 500 14px var(--sans); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.status { margin-left: auto; font: 400 12px var(--mono); color: var(--muted); }
.status.bad { color: var(--del); }
.note-title { margin: 12px 0 6px; font: 600 clamp(26px, 6vw, 38px)/1.2 var(--serif); letter-spacing: -.01em; overflow-wrap: anywhere; }
.meta { font: 400 12px var(--mono); color: var(--muted); margin-bottom: 12px; }
.conflict { margin: 8px 0; padding: 12px 14px; border: 1px solid var(--del); border-radius: 12px; background: var(--del-bg); }
.conflict p { margin: 0 0 8px; }
.conflict .btn { margin-right: 6px; }

.md { font: 400 17px/1.7 var(--serif); margin: 18px 0 8px; max-width: 70ch; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); line-height: 1.25; margin: 1.5em 0 .5em; }
.md h1 { font-size: 1.6em; } .md h2 { font-size: 1.35em; } .md h3 { font-size: 1.15em; }
.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li > ul, .md li > ol { margin: .2em 0 0; }
.md li.task { list-style: none; margin-left: -1.2em; }
.md li.done { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.md blockquote { padding: 4px 16px; border-left: 3px solid var(--margin); background: var(--paper); border-radius: 0 10px 10px 0; color: var(--muted); }
.md blockquote p { margin: .4em 0; }
.md code { background: var(--paper-2); padding: 1px 6px; border-radius: 5px; }
.md pre { padding: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px dashed var(--line); margin: 1.6em 0; }
.md a.wl { text-decoration: none; border-bottom: 1.5px solid var(--accent); }
.md a.wl.missing { border-bottom-style: dashed; color: var(--muted); }

.rel { margin-top: 28px; padding-top: 14px; border-top: 1px dashed var(--line); }
.rel h2 { margin: 0 0 10px; font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips a { display: inline-flex; align-items: center; min-height: 40px; padding: 4px 14px; border: 1px solid var(--line); border-radius: 9999px; background: var(--paper); color: var(--text); text-decoration: none; font-size: 14px; }
.chips a:hover { border-color: var(--accent); }
.chips a.missing { border-style: dashed; color: var(--muted); }
.chips .none { color: var(--muted); font-size: 14px; }

/* редактор: линованная бумага с красным полем */
textarea.paper { font: 400 16px/28px var(--serif); padding: 8px 14px 8px 22px; min-height: 340px; resize: vertical; background-color: var(--paper); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 27px, var(--rule) 27px, var(--rule) 28px), linear-gradient(to right, transparent 14px, var(--margin) 14px, var(--margin) 15px, transparent 15px); background-attachment: local; border-radius: 4px 12px 12px 12px; }

/* история */
.hist-grid { display: grid; gap: 16px; margin-top: 8px; }
.versions { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; align-content: start; max-height: 280px; overflow: auto; }
.versions button { width: 100%; text-align: left; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--text); cursor: pointer; font: 400 14px var(--sans); }
.versions button[aria-current="true"] { border-color: var(--accent); background: var(--paper-2); }
.versions b { font-family: var(--mono); font-weight: 500; color: var(--accent); margin-right: 8px; }
.versions small { display: block; color: var(--muted); font: 400 12px var(--mono); }
.diff-ctl { margin: 0 0 8px; }
.diff-sum { font: 400 12px var(--mono); color: var(--muted); margin: 6px 0; }
.diff { margin: 0; padding: 0; max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); font: 400 13px/1.55 var(--mono); }
.diff div { display: grid; grid-template-columns: 22px 1fr; padding: 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff i { font-style: normal; color: var(--muted); user-select: none; }
.diff .add { background: var(--add-bg); color: var(--add); }
.diff .del { background: var(--del-bg); color: var(--del); }

/* пустое состояние */
.empty { padding: 40px 0; max-width: 56ch; }
.empty h1 { font: 600 clamp(32px, 8vw, 54px)/1.1 var(--serif); margin: 0 0 14px; }
.empty p { color: var(--muted); font-size: 17px; }
.demo-note { padding: 10px 14px; border: 1px dashed var(--accent); border-radius: 10px; color: var(--text) !important; }

/* граф */
.graph .gh { margin: 0; font: 600 20px var(--serif); }
.gwrap { margin-top: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); background-image: radial-gradient(var(--rule) 1px, transparent 1px); background-size: 22px 22px; height: min(70dvh, 640px); touch-action: none; overflow: hidden; }
#gsvg { display: block; width: 100%; height: 100%; }
#gsvg .edge { stroke: var(--muted); stroke-opacity: .45; stroke-width: 1.3; }
#gsvg .edge.hot { stroke: var(--accent); stroke-opacity: 1; stroke-width: 2; }
#gsvg .node circle { stroke: var(--bg); stroke-width: 2; cursor: pointer; }
#gsvg .node text { fill: var(--text); font: 500 11px var(--sans); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; pointer-events: none; }
#gsvg .node:focus-visible circle, #gsvg .node:hover circle { stroke: var(--accent); stroke-width: 3; }
#gsvg .node.cur circle { stroke: var(--text); stroke-width: 3; }
#gsvg .c0 circle { fill: var(--g0); } #gsvg .c1 circle { fill: var(--g1); } #gsvg .c2 circle { fill: var(--g2); }
#gsvg .c3 circle { fill: var(--g3); } #gsvg .c4 circle { fill: var(--g4); } #gsvg .c5 circle { fill: var(--g5); } #gsvg .cn circle { fill: var(--muted); }

/* диалоги и тост */
dialog { width: min(92vw, 560px); padding: 22px; color: var(--text); background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 10px; font: 600 22px var(--serif); }
dialog h3 { margin: 0 0 6px; font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
dialog form { margin: 0; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 16px; }
.keys dt { white-space: nowrap; } .keys dd { margin: 0; color: var(--muted); }
.data-grid { display: grid; gap: 20px; margin-bottom: 8px; }
.data-grid p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
label.file { cursor: pointer; }
label.file:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(92vw, 460px); padding: 12px 16px; background: var(--text); color: var(--bg); border-radius: 12px; font-size: 14px; z-index: 60; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.fab-gap { height: 20px; }

@media (min-width: 560px) {
  .top { grid-template-columns: auto 1fr auto; }
  .search { grid-column: auto; grid-row: auto; max-width: 520px; width: 100%; justify-self: center; }
  .search kbd { display: inline-block; }
  .bar { top: 66px; }
  .data-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 880px) {
  .app { display: grid; grid-template-columns: 340px 1fr; height: calc(100dvh - 130px); }
  .app[data-view] .side, .app[data-view="list"] .main { display: block; }
  .side { overflow: auto; border-right: 1px solid var(--line); padding-bottom: 40px; }
  .main { overflow: auto; padding: 0 clamp(20px, 4vw, 56px) 60px; }
  .bar { top: 0; }
  .back { display: none; }
  .hist-grid { grid-template-columns: 220px 1fr; }
  .versions { max-height: 60vh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (max-width: 879px) {
  .side-head .tags { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .side-head .tag { flex: none; }
}
