/* Layout: рабочее место планировщика — панель инструментов сверху, библиотека слева, сцена, свойства справа. */
:root {
  --bg: #edf0f2;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #5b6672;
  --line: #d5dbe0;
  --accent: #9a6110;
  --accent-soft: #f4e6cc;
  --danger: #b3261e;
  --stage: #dfe3e6;
  --display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --body: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1217; --surface: #141b22; --ink: #e4e9ed; --muted: #93a0ac; --line: #26313b;
    --accent: #e3a64b; --accent-soft: #3a2c17; --danger: #f2867d; --stage: #0b1118; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1217; --surface: #141b22; --ink: #e4e9ed; --muted: #93a0ac; --line: #26313b;
  --accent: #e3a64b; --accent-soft: #3a2c17; --danger: #f2867d; --stage: #0b1118; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/1.45 var(--body); }
[hidden] { display: none !important; }
body:not(.is-editor) .edit-only { display: none !important; }
body.is-editor #login-btn { display: none; }
.mono { font-family: var(--mono); }
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px;
  cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
:root[data-theme="dark"] button.primary { color: #17120a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) button.primary { color: #17120a; } }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="number"], input[type="text"], input[type="password"], input[type="search"], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0;
}

/* --- Список планировок --- */
.list { max-width: 1000px; margin: 0 auto; padding-block: 32px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 22px; }
.list-head { display: grid; gap: 8px; }
.list-head h1 { font: 600 clamp(24px, 4vw, 36px)/1.1 var(--display); margin: 0; }
.lead { margin: 0; color: var(--muted); max-width: 60ch; }
.back { text-decoration: none; font-weight: 500; }
.list-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 14px; }
.lcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; display: grid; gap: 6px; text-decoration: none; color: inherit; }
.lcard:hover { border-color: var(--accent); }
.lcard h2 { margin: 0; font: 600 16px/1.3 var(--body); }
.lcard p { margin: 0; color: var(--muted); font: 400 12.5px var(--mono); }

/* --- Редактор --- */
.app {
  height: 100%; display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "bar bar bar" "lib stage props";
}
body:not(.is-editor) .app { grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "bar bar" "stage props"; }
.bar {
  grid-area: bar; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar .back { font-size: 18px; padding: 2px 6px; }
.title-block { min-width: 0; flex: 1 1 220px; }
.title-block h1 { margin: 0; font: 600 16px/1.2 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { margin: 2px 0 0; font: 400 12px var(--mono); color: var(--muted); }
.status.dirty { color: var(--accent); }
.tools, .tools-edit { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.step { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

.lib, .props { background: var(--surface); overflow-y: auto; padding: 14px 16px 20px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.lib { grid-area: lib; border-right: 1px solid var(--line); }
.props { grid-area: props; border-left: 1px solid var(--line); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pane-head h2 { margin: 0; font: 600 15px/1.3 var(--body); }
.pane-close { display: none; border: 0; font-size: 20px; padding: 0 6px; }
.lib-list { display: grid; gap: 8px; }
.lib-cat { margin: 8px 0 0; font: 500 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.lib-item {
  display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 10px; align-items: center; text-align: left;
  padding: 6px; border-radius: 8px; white-space: normal;
}
.lib-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--stage); }
.lib-item b { display: block; font-weight: 500; font-size: 13px; line-height: 1.3; }
.lib-item span { font: 400 11.5px var(--mono); color: var(--muted); }

.stage { grid-area: stage; position: relative; background: var(--stage); min-width: 0; min-height: 0; overflow: hidden; touch-action: none; }
#canvas { display: block; width: 100%; height: 100%; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.tag {
  position: absolute; transform: translate(-50%, -50%); font: 500 11.5px/1 var(--mono); padding: 5px 6px; border-radius: 999px;
  background: #e6c18a; color: #1b1408; box-shadow: 0 1px 2px rgba(0,0,0,.25); white-space: nowrap;
}
.tag.sel { background: var(--accent); color: #fff; outline: 2px solid #fff; }
.tag.bad { background: #e06a5f; color: #fff; }
.gap-tag { position: absolute; transform: translate(-50%, -50%); font: 500 11px/1 var(--mono); padding: 3px 5px; border-radius: 4px; background: rgba(13, 18, 23, .78); color: #fff; white-space: nowrap; }
.warn {
  position: absolute; left: 12px; top: 12px; max-width: min(420px, calc(100% - 24px)); padding: 8px 10px; border-radius: 8px;
  background: #fbe3e0; color: #5c1510; font-size: 13px; border: 1px solid #e8a39b;
}
.hint { position: absolute; left: 12px; bottom: 10px; right: 12px; margin: 0; font-size: 12px; color: var(--muted); pointer-events: none; text-shadow: 0 1px 0 var(--stage); }
.mobile-tabs { display: none; }

.sel { display: grid; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.sel-asset, .sel-dims { margin: 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fields label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.fields input { width: 100%; font-family: var(--mono); font-size: 13px; color: var(--ink); }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.gaps { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; }
.gaps dt { color: var(--muted); }
.gaps dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sel-link { font-size: 13px; }
.sub { margin: 4px 0 0; font: 600 13px var(--body); color: var(--muted); }
.items { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.items li button {
  width: 100%; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 8px; text-align: left; border: 0;
  background: transparent; padding: 6px 4px; white-space: normal; border-radius: 6px;
}
.items li button:hover { background: var(--bg); }
.items li button.on { background: var(--accent-soft); }
.items .n { font: 500 12px var(--mono); color: var(--accent); }
.items .t { font-size: 13px; }
.items li.bad .n { color: var(--danger); }
.notes { font-size: 12.5px; color: var(--muted); display: grid; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.notes ul { margin: 0; padding-left: 16px; }

.dlg { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 20px 22px; width: min(380px, calc(100% - 32px)); }
.dlg::backdrop { background: rgba(10, 14, 18, .5); }
.dlg form { display: grid; gap: 12px; }
.dlg h2 { margin: 0; font: 600 17px var(--body); }
.dlg label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.dlg input { color: var(--ink); }
.dlg .row { justify-content: flex-end; }
.muted { margin: 0; color: var(--muted); font-size: 13px; }
.err { margin: 0; color: var(--danger); font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; max-width: calc(100% - 32px);
  display: flex; gap: 10px; align-items: center;
}
.toast button { background: transparent; color: inherit; border-color: currentColor; }

/* Телефон и узкое окно: сцена во весь экран, панели выезжают снизу. */
@media (max-width: 900px) {
  .app, body:not(.is-editor) .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "stage"; }
  .lib, .props {
    position: fixed; left: 0; right: 0; bottom: 0; max-height: 62%; z-index: 10; border: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2); transform: translateY(105%); transition: transform .2s ease;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .lib.open, .props.open { transform: none; }
  .pane-close { display: block; }
  .mobile-tabs { display: flex; gap: 6px; position: absolute; right: 12px; bottom: 12px; }
  .hint { display: none; }
  .tools-edit .step, #save-as { display: none; }
}
@media (prefers-reduced-motion: reduce) { .lib, .props { transition: none; } }
