:root {
  --bg: #0e1117;
  --bg2: #151a23;
  --bg3: #1c2330;
  --line: #2a3342;
  --text: #e6ebf2;
  --muted: #8a96a8;
  --accent: #4f8cff;
  --accent2: #2f6fe6;
  --danger: #e5484d;
  --attract: #3b8cff;
  --repel: #f07c3a;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #3d4a60; background: #232c3b; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent2); border-color: var(--accent); }
button.primary:hover { background: var(--accent); }
button.danger:hover { background: #3a1d20; border-color: var(--danger); }
button.active { background: #25324a; border-color: var(--accent); }
input[type=number], input[type=text], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
input[type=color] { width: 44px; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); cursor: pointer; }
input[type=range] { accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }
a { color: var(--accent); }
h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }
h2 { margin: 0 0 14px; font-size: 18px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- шапка ---------- */
.topbar {
  height: 48px; display: flex; align-items: center; gap: 18px; padding: 0 14px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; }
.logo { color: var(--accent); font-size: 18px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 1px solid transparent; }
.tabs button.active { background: var(--bg3); border-color: var(--line); }
.top-actions { display: flex; gap: 6px; }

main { height: calc(100% - 48px); position: relative; }
.tab-page { display: none; height: 100%; }
.tab-page.active { display: flex; }

/* ---------- панели ---------- */
.panel { width: 270px; flex: none; background: var(--bg2); overflow-y: auto; display: flex; flex-direction: column; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); width: 300px; }
.group { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.grow-group { flex: 1; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
.field-row input[type=number] { width: 90px; }
.check { display: flex; align-items: center; gap: 8px; margin: 5px 0; cursor: pointer; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
#tool-options:empty { display: none; }
#tool-options { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
#tool-options .field-row input[type=number] { width: 80px; }

.palette { display: flex; flex-direction: column; gap: 4px; }
.pal-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.pal-item:hover { background: var(--bg3); }
.pal-item.active { border-color: var(--accent); background: #1d283a; }
.pal-item .meta { font-size: 11px; color: var(--muted); }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; display: inline-block; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; display: inline-block; }

.toggles { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.toggle-row { display: flex; align-items: center; gap: 6px; }
.toggle-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toggle-row .count { color: var(--muted); font-size: 12px; }
.icon-btn { padding: 2px 6px; font-size: 13px; line-height: 1.2; min-width: 28px; }
.icon-btn.off { opacity: .35; }

/* ---------- холст ---------- */
.viewport { flex: 1; position: relative; overflow: hidden; background: #0a0d12; min-width: 0; touch-action: none; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cv-ov { cursor: grab; }
.viewport.tool-place #cv-ov, .viewport.tool-fill #cv-ov { cursor: crosshair; }
.viewport.tool-erase #cv-ov { cursor: cell; }
.viewport.panning #cv-ov { cursor: grabbing; }
.hud-top { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; pointer-events: none; }
.stats {
  font: 12px ui-monospace, Consolas, monospace; background: rgba(14,17,23,.82); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 9px; color: var(--muted); white-space: pre; line-height: 1.45;
}
.stats b { color: var(--text); font-weight: 600; }
.controls {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 7px 9px;
  background: rgba(21,26,35,.94); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); width: max-content; max-width: calc(100% - 16px); flex-wrap: wrap; justify-content: center;
}
.controls .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }
.controls #btn-run { min-width: 92px; }
.tick-ctl { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.tick-ctl input[type=range] { width: 120px; }
.tick-ctl input[type=number] { width: 72px; }
.hint {
  position: absolute; right: 8px; top: 8px; font-size: 12px; color: var(--muted);
  background: rgba(14,17,23,.82); border: 1px solid var(--line); padding: 6px 9px; border-radius: 6px; pointer-events: none; max-width: min(360px, 45%);
}
.hint:empty { display: none; }

/* ---------- инспектор ---------- */
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }
.insp-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 4px 6px; align-items: center; }
.insp-grid input { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 3px 5px; }
.insp-grid .lbl { color: var(--muted); font-size: 12px; }
.insp-val { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
table.insp-fields { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
table.insp-fields th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--line); }
table.insp-fields td { padding: 3px 4px; font-family: ui-monospace, Consolas, monospace; }
table.insp-fields td:first-child { font-family: inherit; }
.insp-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- списки и редакторы ---------- */
.list-panel { width: 280px; }
.item-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.item:hover { background: var(--bg3); }
.item.active { border-color: var(--accent); background: #1d283a; }
.item .sub { font-size: 11px; color: var(--muted); }
.item .txt { flex: 1; min-width: 0; }
.item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor { flex: 1; overflow-y: auto; padding: 22px 28px; min-width: 0; }
.editor .empty { color: var(--muted); margin-top: 40px; text-align: center; }
.form-grid { display: grid; grid-template-columns: 160px minmax(0, 420px); gap: 10px 14px; align-items: center; margin-bottom: 20px; }
.form-grid > label { color: var(--muted); }
.cols { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-start; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; }
.card h4 { margin: 0 0 10px; font-size: 13px; font-weight: 600; }

table.ftable { border-collapse: collapse; }
table.ftable th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 8px 6px 0; }
table.ftable td { padding: 2px 8px 2px 0; }
table.ftable td.dist { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); white-space: nowrap; }
table.ftable input { width: 110px; font-family: ui-monospace, Consolas, monospace; }
.table-scroll { max-height: 380px; overflow-y: auto; padding-right: 6px; margin-bottom: 10px; }

.chart-wrap { position: relative; }
.chart-wrap canvas { width: 100%; height: 220px; display: block; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; display: none; color: var(--text);
}
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

.field-checks { display: flex; flex-direction: column; gap: 4px; }
.field-checks label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.field-checks label:hover { background: var(--bg3); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.toast {
  position: fixed; left: 50%; top: 60px; transform: translateX(-50%); background: var(--bg3);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 10; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; }

/* ---------- узкие экраны ---------- */
@media (max-width: 1100px) {
  .panel.right { width: 250px; }
  .panel.left { width: 220px; }
}
@media (max-width: 800px) {
  html, body { overflow: auto; }
  main { height: auto; }
  .tab-page.active { flex-direction: column; }
  .panel, .panel.left, .panel.right, .list-panel { width: 100%; border: none; border-bottom: 1px solid var(--line); }
  .viewport { height: 70vh; flex: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .brand { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .editor { padding: 16px; }
  .tick-ctl input[type=range] { width: 80px; }
}

/* ================= аккаунты, главная, редактор ================= */
[hidden] { display: none !important; }
a.btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text);
  background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; white-space: nowrap;
}
a.btn:hover { border-color: #3d4a60; background: #232c3b; }
a.btn.primary { background: var(--accent2); border-color: var(--accent); }
a.btn.primary:hover { background: var(--accent); }
.brand { color: var(--text); text-decoration: none; }
.tabs a { color: var(--text); text-decoration: none; padding: 5px 10px; border-radius: 6px; border: 1px solid transparent; white-space: nowrap; }
.tabs a:hover { background: var(--bg3); }
.tabs a.active { background: var(--bg3); border-color: var(--line); }
.account { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.account .who { color: var(--muted); font-size: 13px; }
.account .who b { color: var(--text); font-weight: 600; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #25324a; color: #a9c4ff; border: 1px solid #34507e; vertical-align: middle; }
.badge.pub { background: #1d3a2c; color: #8fe3b4; border-color: #2c6547; }

/* главная */
#page-home.active { display: block; overflow-y: auto; }
.home { max-width: 1280px; margin: 0 auto; padding: 24px 28px 40px; }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.home-head h1 { margin: 0; font-size: 24px; }
.home-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.home h2 { font-size: 15px; font-weight: 600; margin: 26px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--bg2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; }
.banner .txt { flex: 1; min-width: 220px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tile { position: relative; display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s; }
.tile:hover { border-color: #3d5378; transform: translateY(-2px); }
.tile .thumb { aspect-ratio: 16 / 10; background: #0a0d12; display: flex; align-items: center; justify-content: center; color: #2a3342; font-size: 44px; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.tile-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-desc { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; }
.tile-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tile-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; }
.tile-actions button { background: rgba(14,17,23,.85); padding: 3px 8px; font-size: 12px; }
.tile-new { align-items: center; justify-content: center; min-height: 200px; border-style: dashed; color: var(--muted); font-size: 15px; gap: 8px; }
.tile-new .plus { font-size: 36px; color: var(--accent); }
.empty-note { color: var(--muted); padding: 8px 0; }
.home-footer { margin-top: 34px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }

/* редактор сцены */
.stack { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.stack > span { color: var(--muted); font-size: 12px; }
.stack input, .stack textarea { width: 100%; }
#scene-desc { font-family: inherit; font-size: 13px; }
.save-buttons { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; }
.icon-btn { text-transform: none; letter-spacing: 0; }
.scene-title { background: rgba(14,17,23,.82); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font-size: 13px; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: flex-start; }
.scene-title:empty { display: none; }
.scene-title .muted { font-size: 12px; }
.hint { top: auto; bottom: 70px; right: 8px; }

/* списки полей и частиц */
.list-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 2px 4px; }
.readonly-note { background: var(--bg2); border: 1px solid var(--line); border-left: 3px solid #d7a53a; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.readonly-note .txt { flex: 1; min-width: 200px; }

/* окно входа */
.modal-back { position: fixed; inset: 0; background: rgba(5,7,10,.65); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal { width: 100%; max-width: 360px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.modal-tabs button { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.auth-error { color: #ff8b8f; font-size: 13px; min-height: 1.2em; margin-top: 6px; }

@media (max-width: 800px) {
  .home { padding: 16px; }
  .account .who { display: none; }
  .scene-title { max-width: 55%; }
}
a.item { color: var(--text); text-decoration: none; }

/* ================= версия 3: адреса, свойства сцены, чужие работы ================= */
.back-link { color: var(--text); text-decoration: none; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg3); white-space: nowrap; }
.back-link:hover { border-color: #3d4a60; }
.topbar .back-link { margin-right: auto; }
.hud-top { align-items: flex-start; gap: 8px; }
.scene-bar { display: flex; gap: 6px; align-items: center; pointer-events: auto; flex-wrap: wrap; justify-content: flex-end; max-width: 70%; }
.scene-bar .scene-title { max-width: 320px; }
.scene-bar button { background: rgba(28,35,48,.92); }
.scene-bar button.primary { background: var(--accent2); }
.viewport.tool-pin #cv-ov { cursor: pointer; }
.hint { bottom: 70px; top: auto; right: 8px; }

.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal-wide { max-width: 720px; }
.props-grid { display: grid; grid-template-columns: 1fr 260px; gap: 18px; }
.icon-preview { margin-top: 4px; aspect-ratio: 16 / 10; border: 1px solid var(--line); border-radius: 8px; background: #0a0d12; display: flex; align-items: center; justify-content: center; overflow: hidden; color: #2a3342; font-size: 44px; }
.icon-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.leave-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.leave-actions button { padding: 8px 12px; }

.explore-cta { margin-top: 18px; }
.seg { display: inline-flex; gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin-bottom: 18px; flex-wrap: wrap; }
.seg a { color: var(--text); text-decoration: none; padding: 5px 12px; border-radius: 6px; }
.seg a.active { background: var(--bg3); box-shadow: inset 0 0 0 1px var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.item-card { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.item-card-head { display: flex; align-items: center; gap: 8px; }
.item-card-body { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.item-card button { margin-top: auto; }
.dot.big { width: 40px; height: 40px; }
.spark { width: 100%; height: 40px; display: block; }

.formula-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.formula-row .stack { margin: 0; }
.formula-row input[type=number] { width: 80px; }
.formula-row .grow input { min-width: 200px; font-family: ui-monospace, Consolas, monospace; }

.pal-item input[type=checkbox] { margin: 0; }
.pal-item .weight { width: 56px; padding: 3px 5px; }
.pal-item .grow { min-width: 0; }

.vel-box { display: flex; gap: 10px; align-items: center; margin: 8px 0 6px; }
.vel-box canvas { width: 96px; height: 96px; flex: none; background: var(--bg); border: 1px solid var(--line); border-radius: 50%; touch-action: none; }
.vel-fields { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.vel-fields input { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 3px 5px; }

@media (max-width: 800px) {
  .props-grid { grid-template-columns: 1fr; }
  .scene-bar { max-width: 100%; }
}
