/* Тёмная тема как у Sky Guide: чёрный фон, карточки #141414, зелёный акцент у кнопок, золото — для выделения */
:root {
  --bg: #0a0a0a; --bg2: #0e0e0e; --card: #141414; --card2: #1a1a1a; --card-b: #262626; --line2: #363636;
  --text: #ededed; --text2: #c8c8c8; --muted: #8f8f8f;
  --accent: #62d14b; --accent-d: #3fa437; --on-accent: #0a1a07;
  --gold: #ffd25a; --red: #ff7d6b; --blue: #7cc8ff; --purple: #c39bff; --gray: #a0a0a0;
  --ui: 'Onest', 'Inter Variable', Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Unbounded', 'Onest', system-ui, sans-serif;
  --mono: ui-monospace, 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  --r: 12px; --r-lg: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--ui); }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { font-family: var(--mono); font-size: .9em; background: var(--card2); border: 1px solid var(--card-b); border-radius: 6px; padding: 1px 5px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.boot img { animation: float 2.4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }

.brand { display: flex; align-items: center; gap: 10px; font: 600 16px/1 var(--display); letter-spacing: .01em; }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line2); background: var(--card2);
  border-radius: 10px; padding: 10px 16px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; white-space: nowrap; }
.btn:hover { background: #222; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid rgba(214,214,214,.35); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: #74de5e; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text2); }
.btn.ghost:hover { background: rgba(255,255,255,.06); }
.btn.sm { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn.icon { padding: 6px 9px; }
.btn.danger { color: var(--red); }
.btn.discord { background: #5865f2; border-color: #5865f2; color: #fff; }
.btn.discord:hover { background: #6d78f5; }

/* --- вход --- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, rgba(98,209,75,.10), transparent 60%), var(--bg); }
.auth-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--card-b); border-radius: var(--r-lg); padding: 28px 24px; }
.auth-card p { text-align: center; margin: 0 0 18px; }
.auth-card form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--text2); }
input, textarea { background: var(--bg2); border: 1px solid var(--card-b); border-radius: 10px; padding: 10px 12px; }
input::placeholder, textarea::placeholder { color: #666; }
.auth-card .btn { width: 100%; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 16px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--card-b); }
.msg { min-height: 1.4em; margin: 12px 0 0 !important; color: var(--red); text-align: center; font-size: 14px; }
.msg.ok { color: var(--accent); }

/* --- холст --- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--card-b); background: rgba(10,10,10,.92); backdrop-filter: blur(8px); z-index: 20; }
.spacer { flex: 1; }
.search { position: relative; width: min(280px, 34vw); }
.search input { width: 100%; padding: 7px 12px; font-size: 14px; }
.search-list { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #181818; border: 1px solid var(--line2); border-radius: 10px; overflow: hidden; z-index: 40; }
.search-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; cursor: pointer; }
.search-list button:hover, .search-list button.on { background: rgba(255,255,255,.06); }

.board { position: relative; flex: 1; overflow: hidden; cursor: grab; touch-action: none; outline: none;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1.2px);
  background-size: 24px 24px; }
.board.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.edges line { stroke: #4a4a4a; stroke-width: 2; stroke-linecap: round; }
.edges line.hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.edges line.hit:hover + line, .edges line.sel { stroke: var(--gold); }
.edges line.on { stroke: #7a7a7a; }
.edges line.draft { stroke: var(--gold); stroke-dasharray: 6 6; }

.node { position: absolute; transform: translate(-50%, -50%); min-width: 120px; max-width: 240px; padding: 12px 22px;
  border-radius: 999px; background: var(--card); border: 1.5px solid var(--c, var(--accent)); color: var(--text);
  text-align: center; font-weight: 500; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.02); transition: box-shadow .15s, background .15s; }
.node:hover { background: var(--card2); box-shadow: 0 6px 24px rgba(0,0,0,.5), 0 0 0 4px color-mix(in srgb, var(--c) 18%, transparent); }
.node.sel { background: color-mix(in srgb, var(--c) 14%, var(--card)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 30%, transparent), 0 8px 26px rgba(0,0,0,.55); }
.node.dim { opacity: .35; }
.node .t { display: block; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.node .has { position: absolute; top: 6px; right: 12px; width: 5px; height: 5px; border-radius: 50%; background: var(--c); opacity: .8; }
.node .h { position: absolute; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--bg);
  border: 2px solid var(--c); opacity: 0; cursor: crosshair; transition: opacity .12s; }
.node .h.l { left: -8px; } .node .h.r { right: -8px; }
.node:hover .h, .node.sel .h, .linking .node .h { opacity: 1; }
.node.target { box-shadow: 0 0 0 4px rgba(255,210,90,.45); }
[data-c="green"] { --c: var(--accent); } [data-c="gold"] { --c: var(--gold); } [data-c="blue"] { --c: var(--blue); }
[data-c="red"] { --c: var(--red); } [data-c="purple"] { --c: var(--purple); } [data-c="gray"] { --c: var(--gray); }

.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; padding: 20px; }
.empty p { margin: 4px 0; }
.hint { position: absolute; left: 14px; bottom: 10px; font-size: 12px; pointer-events: none; padding-bottom: env(safe-area-inset-bottom); }

/* --- панели --- */
.panel { position: absolute; top: 58px; right: 14px; bottom: 14px; background: var(--card); border: 1px solid var(--card-b);
  border-radius: var(--r-lg); box-shadow: 0 20px 60px rgba(0,0,0,.6); display: flex; flex-direction: column; z-index: 30; overflow: hidden; }
.panel.view { width: min(440px, calc(100vw - 28px)); }
.panel.editor { width: min(1040px, calc(100vw - 28px)); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--card-b); }
.panel-head h2 { flex: 1; margin: 0; font: 600 17px/1.3 var(--display); overflow-wrap: anywhere; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }
.panel-foot { padding: 10px 16px; border-top: 1px solid var(--card-b); font-size: 12px; }
.view .md { padding: 4px 18px 16px; overflow: auto; flex: 1; }
.title-input { flex: 1; min-width: 0; font: 600 16px/1.3 var(--display); background: transparent; border-color: transparent; padding: 6px 8px; }
.title-input:hover, .title-input:focus { border-color: var(--card-b); background: var(--bg2); }
.colors { display: flex; gap: 6px; }
.colors button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; padding: 0; }
.colors button.on { border-color: var(--text); }
.cols-head { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--card-b); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.cols-head span { padding: 8px 16px; text-align: center; }
.cols-head span + span { border-left: 1px solid var(--card-b); }
.cols { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.cols textarea { resize: none; border: 0; border-radius: 0; background: var(--bg2); padding: 16px; font: 14px/1.6 var(--mono); outline: none; tab-size: 2; }
.cols .md { border-left: 1px solid var(--card-b); padding: 4px 20px 16px; overflow: auto; }
.tabs-mobile { display: none; }

/* --- превью Markdown --- */
.md { overflow-wrap: anywhere; color: var(--text2); }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { color: var(--text); font-family: var(--display); line-height: 1.3; margin: 18px 0 8px; font-weight: 600; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; } .md h4, .md h5, .md h6 { font-size: 15px; }
.md p { margin: 10px 0; }
.md ul, .md ol { padding-left: 22px; margin: 10px 0; }
.md li.sub { margin-left: 18px; }
.md .task { color: var(--muted); } .md .task.done { color: var(--accent); }
.md blockquote { margin: 10px 0; padding: 2px 14px; border-left: 3px solid var(--gold); background: rgba(255,210,90,.05); border-radius: 0 8px 8px 0; }
.md pre { background: var(--bg2); border: 1px solid var(--card-b); border-radius: 10px; padding: 12px; overflow: auto; }
.md pre code { border: 0; padding: 0; background: none; }
.md hr { border: 0; border-top: 1px solid var(--card-b); margin: 16px 0; }
.md img { max-width: 100%; border-radius: 8px; }
.md strong { color: var(--text); }
.md a.wikilink { color: var(--gold); text-decoration: none; border-bottom: 1px dashed rgba(255,210,90,.5); }
.md .table { overflow-x: auto; margin: 10px 0; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 50%; }
.md th, .md td { border: 1px solid var(--card-b); padding: 6px 10px; text-align: left; }
.md th { background: var(--card2); color: var(--text); font-weight: 600; }
.md .al-center { text-align: center; } .md .al-right { text-align: right; }
.md a.wikilink.missing { color: var(--muted); border-bottom-color: rgba(143,143,143,.5); }
.rel { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-top: 1px solid var(--card-b); }
.rel:empty { display: none; }
.rel .lbl { font-size: 12px; color: var(--muted); width: 100%; }
.rel button { border: 1px solid var(--c, var(--line2)); background: var(--bg2); border-radius: 999px; padding: 3px 10px; font-size: 13px; cursor: pointer; color: var(--text2); }
.rel button:hover { background: var(--card2); color: var(--text); }
.toast button { margin-left: 12px; background: none; border: 0; color: var(--gold); font-weight: 600; cursor: pointer; padding: 0; }
.md .empty-body { color: var(--muted); font-style: italic; }

/* --- окна --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { width: min(640px, 100%); max-height: calc(100vh - 32px); background: var(--card); border: 1px solid var(--card-b); border-radius: var(--r-lg); display: flex; flex-direction: column; overflow: hidden; }
.modal-body { padding: 6px 18px 18px; overflow: auto; }
.modal h3 { font: 600 15px/1.3 var(--display); margin: 18px 0 6px; }
.modal h4 { font-size: 14px; margin: 16px 0 4px; }
.row-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.row-form input { flex: 1 1 140px; min-width: 0; padding: 7px 10px; font-size: 14px; }
.list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.list li { display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 1px solid var(--card-b); border-radius: 10px; padding: 8px 12px; }
.list li > span:first-child { flex: 1; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(255,210,90,.12); color: var(--gold); }

.ctx { position: fixed; z-index: 60; max-width: min(460px, calc(100vw - 16px)); max-height: 60vh; overflow: auto; background: #181818; border: 1px solid var(--line2); border-radius: 10px; padding: 4px; min-width: 180px; box-shadow: 0 12px 30px rgba(0,0,0,.5); }
.ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.ctx button:hover { background: rgba(255,255,255,.06); }
.ctx button.danger { color: var(--red); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d1d1d; border: 1px solid var(--line2); border-radius: 10px; padding: 10px 16px; z-index: 70; font-size: 14px; }

@media (max-width: 760px) {
  .hint, #fit-btn { display: none; }
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand span { display: none; }
  .search { flex: 1; width: auto; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: 100% !important; height: 72vh; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .panel.editor { height: calc(100% - 52px); }
  .cols-head { display: none; }
  .cols { grid-template-columns: 1fr; }
  .cols .md { border-left: 0; }
  .editor[data-tab="code"] .cols .md, .editor[data-tab="preview"] .cols textarea { display: none; }
  .tabs-mobile { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--card-b); }
  .tabs-mobile button { border: 0; background: none; padding: 12px; color: var(--muted); }
  .tabs-mobile button.on { color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
  .colors { display: none; }
}
