:root {
  --bg: #f6f6f4; --card: #fff; --text: #1d1d1b; --muted: #6b6b66; --line: #e2e1dc;
  --accent: #1f5fbf; --accent-soft: #e3ecfa; --hl: #e8442e; --hl-soft: #fdeae6; --star: #e0a100;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --card: #20201e; --text: #ecebe6; --muted: #9a9993; --line: #34332f;
    --accent: #6ea3f2; --accent-soft: #22324a; --hl: #ff6a52; --hl-soft: #43231d; --star: #f0b928; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }

.top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 10px 16px; border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.brand { font-weight: 800; color: var(--text); margin-right: auto; letter-spacing: .01em; }
.brand span { color: var(--muted); font-weight: 500; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang button { border: 0; background: var(--card); padding: 4px 10px; font-size: 14px; cursor: pointer; }
.lang button.on { background: var(--accent); color: #fff; }
.installbtn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 2px 8px; font-size: 18px; cursor: pointer; line-height: 1.3; }
.favlink { color: var(--star); font-weight: 600; white-space: nowrap; }
#q { width: 100%; padding: 10px 12px; font-size: 17px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 12px 16px 60px; }
h1 { font-size: 20px; margin: 4px 0; }
h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 18px 0 6px; text-transform: uppercase; letter-spacing: .03em; }
.sub { color: var(--muted); font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list a, .list .row { display: flex; gap: 10px; align-items: baseline; padding: 11px 14px; color: var(--text); }
.list .num { color: var(--muted); min-width: 2.2em; font-variant-numeric: tabular-nums; }
.list .grow { flex: 1; min-width: 0; }
.list .off { color: var(--muted); }
.badge { font-size: 12px; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.gray { background: var(--line); color: var(--muted); }
.pn { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; white-space: nowrap; }
.names .ru { font-weight: 500; }
.names .alt { color: var(--muted); font-size: 13px; }
.star { color: var(--star); }

/* Схема */
.fig { display: grid; gap: 16px; }
/* Схема «прилипает» под шапкой: на телефоне сверху, на широком экране слева от таблицы. */
.diagram-wrap { position: sticky; top: var(--top, 104px); z-index: 5; }
.parts li { scroll-margin-top: calc(var(--top, 104px) + 42vh + 56px); }
@media (min-width: 900px) { .fig { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .parts li { scroll-margin-top: calc(var(--top, 104px) + 16px); } }
.diagram-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.diagram-scroll { overflow: auto; max-height: var(--boxh); touch-action: pan-x pan-y pinch-zoom; }
:root { --boxh: 42vh; }
@media (min-width: 900px) { :root { --boxh: calc(100vh - var(--top, 104px) - 170px); } }
/* Схема целиком вписана в окно (по ширине и высоте), --z — увеличение кнопками. */
.diagram { position: relative; margin: 0 auto; width: calc(min(100%, var(--boxh) * var(--ar, 1)) * var(--z, 1)); }
.diagram img { display: block; width: 100%; height: auto; }
.co { position: absolute; width: 4.2%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; min-width: 22px; }
.co:hover { border-color: rgba(232, 68, 46, .4); }
.co.on { border: 3px solid var(--hl); background: rgba(232, 68, 46, .12); animation: pulse 1.2s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(232, 68, 46, .6); } 100% { box-shadow: 0 0 0 14px rgba(232, 68, 46, 0); } }
.dtools { display: flex; gap: 6px; padding: 6px; border-top: 1px solid var(--line); background: var(--card); }
.dtools { padding: 4px; }
.dtools button, .btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 12px; cursor: pointer; }
.dtools > * { white-space: nowrap; }
.dtools button, .dtools .btn { padding: 3px 12px; font-size: 15px; }
.dtools .sp { flex: 1; }

.parts .row { cursor: pointer; }
.parts li.on { background: var(--hl-soft); }
.card { padding: 0 14px 10px calc(14px + 2.2em + 10px); display: grid; gap: 6px; }
.card > .alt { color: var(--muted); font-size: 13px; }
/* ссылки внутри карточки — обычные, не строки списка */
.list .card a { display: inline; padding: 0; color: var(--accent); }
.acts { display: flex; flex-wrap: wrap; gap: 6px; }
.acts .btn { font-size: 14px; padding: 4px 9px; white-space: nowrap; }
.noteedit { display: grid; gap: 6px; justify-items: start; }
.noteedit[hidden] { display: none; }
.card textarea { width: 100%; min-height: 48px; font: inherit; padding: 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.links { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.note-line { font-size: 13px; color: var(--muted); }
.mynote { font-size: 14px; color: var(--star); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 10px; font-size: 14px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.userlink { font-size: 14px; white-space: nowrap; max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.userlink img { width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 12px; }

/* Телефон: кнопки под палец */
@media (pointer: coarse) {
  .lang button { padding: 7px 11px; }
  .favlink { padding: 6px 2px; }
}

/* Серверная версия страниц (для поисковиков и до загрузки app.js) */
.crumbs a { color: var(--accent); }
.seo-parts { width: 100%; border-collapse: collapse; background: var(--card); font-size: 14px; }
.seo-parts th, .seo-parts td { border-top: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.blk { display: block; }

/* Узкая шапка (iPhone SE): переключатель языка не сжимается, название сайта уступает место */
.lang, .installbtn, .favlink { flex: none; }
.brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 400px) { .bar { gap: 6px; } .lang button { padding: 6px 8px; } }

/* Миниатюры схем в списках разделов и схем */
.thumb { background: #fff; border: 1px solid var(--line); border-radius: 6px; object-fit: contain; flex: none; height: auto; }
.thumbs { display: flex; gap: 6px; margin-top: 6px; overflow: hidden; }
.thumbs .thumb { width: 72px; height: 72px; }
.list a > .thumb { width: 64px; height: 64px; align-self: center; }
