/* Оболочка: тонкий «браузер». Нейтральная, системная, без собственного стиля. */
:root {
  --sh-bg: #f1f1f3;
  --sh-line: #d4d4d8;
  --sh-ink: #1f1f22;
  --sh-mute: #6b6b72;
  --sh-field: #ffffff;
  --sh-focus: #2a62d9;
  --sh-h: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --sh-bg: #2b2b2e; --sh-line: #3d3d42; --sh-ink: #ececee; --sh-mute: #a0a0a8; --sh-field: #1d1d20; --sh-focus: #7aa2ff; }
}
:root[data-theme="dark"] { --sh-bg: #2b2b2e; --sh-line: #3d3d42; --sh-ink: #ececee; --sh-mute: #a0a0a8; --sh-field: #1d1d20; --sh-focus: #7aa2ff; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: #fff; color: #000; overflow-x: hidden; }
body.ov-open { overflow: hidden; }
#app { min-height: 100vh; }
:focus-visible { outline: 2px solid var(--sh-focus); outline-offset: 2px; }
button { font: inherit; }
.ic { display: inline-block; vertical-align: middle; flex: none; }

.shell {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 2px;
  height: var(--sh-h); padding: 0 4px; padding-top: env(safe-area-inset-top);
  background: var(--sh-bg); border-bottom: 1px solid var(--sh-line);
  font: 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--sh-ink);
}
.sh-btn {
  display: inline-grid; place-items: center; flex: none;
  min-width: 44px; height: 44px; padding: 0 6px;
  border: 0; border-radius: 8px; background: transparent; color: var(--sh-ink); cursor: pointer;
}
.sh-btn:hover { background: rgba(127, 127, 127, .14); }
.sh-btn:disabled { color: var(--sh-mute); opacity: .45; cursor: default; background: transparent; }
.sh-btn .flip { display: inline-block; transform: scaleX(-1); }
.sh-form { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; margin: 0 4px; border-radius: 18px; background: var(--sh-field); border: 1px solid var(--sh-line); }
.sh-lock { color: var(--sh-mute); display: inline-flex; }
.sh-addr { flex: 1; min-width: 0; height: 34px; border: 0; background: transparent; color: var(--sh-ink); font: 15px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; outline: none; text-overflow: ellipsis; }
.sh-form:focus-within { border-color: var(--sh-focus); }
.sh-tabs .tabcount { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 3px; border: 1.8px solid currentColor; border-radius: 5px; font-size: 11px; font-weight: 700; }
.sh-nb { position: relative; }
.nb-ic { display: block; width: 18px; height: 20px; border: 1.8px solid currentColor; border-radius: 2px 4px 4px 2px; box-shadow: inset 4px 0 0 -2px currentColor; }
.nb-count { position: absolute; top: 6px; right: 4px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; font: 700 10px/15px system-ui, sans-serif; background: var(--sh-ink); color: var(--sh-bg); }
.nb-count:empty { display: none; }
@media (max-width: 719px) {
  .sh-fwd, .sh-reload { display: none; }
  .sh-btn { min-width: 40px; padding: 0 4px; }
  .sh-form { margin: 0 2px; padding: 0 8px; }
  .sh-addr { font-size: 14px; }
}
.page { min-height: calc(100vh - var(--sh-h)); }

.sh-toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 90;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  padding: 8px 14px; border-radius: 6px; background: rgba(30, 30, 33, .92); color: #fff;
  font: 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  transition: opacity .2s, transform .2s;
}
.sh-toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Оверлеи: вкладки, меню, блокнот */
.ov { position: fixed; inset: 0; z-index: 80; }
.ov[hidden] { display: none; }
.ov-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.ov-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(420px, 100%); overflow: auto;
  background: var(--sh-bg); color: var(--sh-ink); border-left: 1px solid var(--sh-line);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  padding: 8px 16px 24px; padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.ov-menu .ov-panel { top: var(--sh-h); bottom: auto; width: min(280px, 100%); border: 1px solid var(--sh-line); border-radius: 0 0 0 8px; padding: 4px 0; }
.ov-nb .ov-panel { width: min(760px, 100%); }
.ov-close { float: right; }
.ov-panel h2 { font-size: 17px; margin: 10px 0 12px; }
.menu { display: flex; flex-direction: column; padding-top: 44px; }
.ov-menu .ov-close { position: absolute; right: 0; top: 0; }
.menu-item { display: block; text-align: left; min-height: 44px; padding: 12px 16px; border: 0; background: none; color: inherit; text-decoration: none; cursor: pointer; font: inherit; }
.menu-item:hover { background: rgba(127, 127, 127, .14); }
.tabs-list { list-style: none; margin: 0; padding: 0; }
.tabs-list li { display: flex; align-items: stretch; border-bottom: 1px solid var(--sh-line); }
.tab-item { flex: 1; min-width: 0; text-align: left; padding: 10px 6px; min-height: 52px; border: 0; background: none; color: inherit; cursor: pointer; }
.tab-item b, .tab-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-item span { color: var(--sh-mute); font-size: 13px; }
.tab-item.on b::before { content: "● "; color: var(--sh-focus); }
.tab-new { margin-top: 12px; min-height: 44px; width: 100%; border: 1px dashed var(--sh-line); background: none; color: inherit; border-radius: 8px; cursor: pointer; }

/* Блокнот — простой, как заметки на телефоне */
.nb-h { margin-top: 12px; }
.nb-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--sh-line); }
.nb-tab { min-height: 44px; padding: 0 14px; border: 0; background: none; color: var(--sh-mute); border-bottom: 2px solid transparent; cursor: pointer; }
.nb-tab[aria-selected="true"] { color: var(--sh-ink); border-bottom-color: var(--sh-ink); }
.nb-notes { width: 100%; min-height: 140px; resize: vertical; padding: 10px; border: 1px solid var(--sh-line); border-radius: 6px; background: var(--sh-field); color: var(--sh-ink); font: 15px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.clips { list-style: none; margin: 14px 0 0; padding: 0; }
.clip { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--sh-line); }
.clip-thumb { width: 72px; height: auto; border-radius: 3px; flex: none; }
.clip-main { flex: 1; min-width: 0; }
.clip-main b { display: block; }
.clip-main p { margin: 2px 0; color: var(--sh-mute); font-size: 14px; overflow-wrap: anywhere; }
.clip-src { color: var(--sh-focus); font-size: 13px; overflow-wrap: anywhere; display: inline-block; min-height: 32px; padding-top: 6px; }

/* Схема (доска) */
.board-view { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: 100%; }
.ov-nb .ov-panel { overflow-x: hidden; }
.board-viewport { max-width: 100%; }
.board-empty { padding: 24px 0; color: var(--sh-mute); }
.board-empty h2 { color: var(--sh-ink); }
.board-empty .be-ic { display: none; }
.board-viewport { overflow: auto; height: min(60vh, 560px); border: 1px solid var(--sh-line); border-radius: 6px; background: #f6f3ea; background-image: radial-gradient(rgba(0,0,0,.08) 1px, transparent 1px); background-size: 18px 18px; touch-action: pan-x pan-y; overscroll-behavior: contain; }
.board-sizer { position: relative; }
.board-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.board-lines { position: absolute; inset: 0; overflow: visible; }
.board-lines .thread { fill: none; stroke: #b3261e; stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.board-lines .hit { fill: none; stroke: transparent; stroke-width: 22; cursor: pointer; pointer-events: stroke; }
.board-lines .link.sel .thread { stroke: #1d4ed8; stroke-width: 3; }
.card {
  position: absolute; width: 190px; min-height: 92px; padding: 14px 10px 8px;
  background: #fffef8; color: #222; border: 1px solid #d9d4c3; box-shadow: 0 1px 3px rgba(0,0,0,.18);
  font: 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  transform: rotate(var(--tilt, 0deg)); touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
}
.card.dragging { cursor: grabbing; box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 5; }
.card.sel { outline: 2px solid #1d4ed8; }
.card.from { outline: 2px dashed #b3261e; }
.card-pin { position: absolute; top: 4px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: #b3261e; box-shadow: 0 1px 1px rgba(0,0,0,.4); }
.card-label { display: block; margin-bottom: 3px; }
.card-detail { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: #555; font-size: 12px; }
.card-src { display: block; margin-top: 4px; color: #888; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.bar-title { flex: 1 1 100%; font-weight: 600; font-size: 14px; }
.bar-hint { flex: 1; font-size: 13px; }
.board-banner:empty { display: none; }
.board-banner { font-size: 14px; padding: 6px 8px; background: #fff3cd; color: #5c4400; border-radius: 4px; }
.tool { min-height: 44px; min-width: 44px; padding: 0 12px; border: 1px solid var(--sh-line); border-radius: 6px; background: var(--sh-field); color: var(--sh-ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tool.small { min-height: 36px; min-width: 36px; padding: 0 6px; }
.zoom { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.zoom-lbl { min-width: 3.2em; text-align: center; font-size: 13px; color: var(--sh-mute); }
.board-links summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.board-links ul { list-style: none; padding: 0; margin: 0; }
.board-links li { display: flex; align-items: center; gap: 6px; padding: 4px 0; font-size: 14px; flex-wrap: wrap; }

/* Едва заметная возможность сохранить фрагмент */
.clue { position: relative; }
.pin {
  position: absolute; top: 0; right: 0; z-index: 2;
  width: 28px; height: 28px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 4px; background: rgba(255, 255, 255, .85); color: #555; cursor: pointer;
  opacity: 0; transition: opacity .12s;
}
.pin::after { content: ""; position: absolute; inset: -8px; }
.clue-inline > .pin { position: relative; display: inline-grid; vertical-align: middle; width: 22px; height: 22px; margin-left: 2px; }
@media (hover: hover) {
  .clue:hover > .pin { opacity: .75; }
  .pin:hover { opacity: 1 !important; }
}
.pin:focus-visible { opacity: 1; }
.clue.is-pinned > .pin { opacity: .9; color: #b3261e; }
@media (hover: none) {
  .pin { width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .pin:focus-visible { width: 28px; height: 28px; clip-path: none; }
  .clue.is-pinned::before { content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: #b3261e; opacity: .8; pointer-events: none; }
}
.lp-pop { position: fixed; z-index: 95; display: flex; flex-direction: column; min-width: 190px; background: #fff; color: #111; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); overflow: hidden; font: 15px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
.lp-pop button { min-height: 44px; padding: 0 14px; text-align: left; border: 0; background: none; border-bottom: 1px solid #eee; cursor: pointer; }

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