/* Edytor figur: formularz z krokami po lewej, podgląd na żywo po prawej (na telefonie podgląd na górze). */
/* strona przewija się zwykłym oknem (płynne przewijanie do kroku działa tylko wtedy) */
html.editor-html { height: auto; }
body.editor-page {
  display: block; overflow: visible; height: auto; min-height: 100vh;
}
.ed-top, .ed-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 10px var(--gutter-r) 10px var(--gutter-l);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.ed-top { justify-content: space-between; }
.ed-auth { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ed-auth-status { color: var(--muted); font-size: 14px; }
.ed-inline { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-inline input { min-width: 0; width: 200px; max-width: 100%; }
.ed-bar { position: sticky; top: 0; z-index: 5; align-items: flex-end; }
.ed-pick { min-width: 160px; }
.ed-pick-wide { flex: 1 1 260px; }
.ed-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-state { color: var(--muted); font-size: 13.5px; min-height: 1em; flex-basis: 100%; }

.ed-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ed-field > span { font-size: 12px; font-weight: 700; color: var(--muted); }
.ed-field select, .ed-field input, .ed-field textarea { width: 100%; }

input[type="text"], input[type="password"], textarea {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px;
}
textarea { resize: vertical; font: inherit; }

.ed-main {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 14px;
  padding: 14px var(--gutter-r) 24px var(--gutter-l); align-items: start;
}
.ed-form { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ed-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 0; min-width: 0;
}
.ed-card legend { font-weight: 800; padding: 0 4px; }
.ed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; }
.ed-span2 { grid-column: span 2; }
.ed-span-all { grid-column: 1 / -1; }

.ed-steps-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ed-steps-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-step-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ed-step {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 8px; align-items: start;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--surface-2);
}
.ed-step {
  cursor: pointer;
  /* przewijanie do kroku: zostaje widoczny pod przyklejonym paskiem u góry */
  scroll-margin-top: calc(var(--ed-bar-h, 0px) + 12px); scroll-margin-bottom: 16px;
  transition: background-color .2s, border-color .2s;
}
.ed-step.is-current { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
/* zaznaczony krok: cały panel wyróżniony kolorem */
.ed-step.is-selected {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
  border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent);
}
.ed-step.is-selected .ed-step-grid input, .ed-step.is-selected .ed-step-grid select {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.ed-seek {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  font-weight: 800; cursor: pointer;
}
.ed-step.is-selected .ed-seek, .ed-step.is-current .ed-seek { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ed-step-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px 8px; min-width: 0; }
.ed-step-grid label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ed-step-grid label > span { font-size: 11px; font-weight: 700; color: var(--muted); }
.ed-step-grid input, .ed-step-grid select { width: 100%; min-height: 34px; padding: 4px 6px; font-size: 14px; }
.ed-step-grid input[type="text"], .ed-step-grid input:not([type]) {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
}
.ed-step-grid input[type="number"], .ed-step-grid select { background: var(--surface); }
.ed-dir { grid-column: span 2; }
.ed-dir input { margin-top: 4px; }
.ed-desc { grid-column: 1 / -1; }
.ed-chk { flex-direction: row !important; align-items: center; gap: 6px !important; align-self: end; min-height: 34px; }
.ed-chk input { width: 18px !important; min-height: 0 !important; accent-color: var(--accent); }
.ed-chk span { font-size: 12.5px !important; font-weight: 600 !important; color: var(--ink) !important; }
.ed-step-tools { display: flex; flex-direction: column; gap: 4px; }
.ed-step-tools .btn.icon { width: 32px; min-height: 30px; font-size: 12px; }
.ed-step-tools .danger:hover { border-color: var(--danger); color: var(--danger); }
.ed-empty { color: var(--muted); margin: 6px 0 0; }

.ed-json summary { cursor: pointer; font-weight: 700; }
.ed-json textarea { width: 100%; margin-top: 10px; font: 13px/1.4 var(--font-mono); }
.ed-json-tools { margin-top: 8px; }

.ed-preview {
  position: sticky; top: 76px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.ed-preview-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.ed-preview iframe {
  width: 100%; height: min(72vh, 680px); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--scene-bg);
}
.ed-msgs { display: flex; flex-direction: column; gap: 6px; }
.ed-msgs .msg { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); font-size: 14px; }
.ed-msgs .msg.error { border-color: var(--danger); }
.ed-msgs .msg.error strong { color: var(--danger); }
.ed-msgs .msg.ok { border-color: var(--ok); }
.ed-msgs ul { margin: 4px 0 0; padding-left: 18px; }

@media (max-width: 900px) {
  .ed-main { grid-template-columns: minmax(0, 1fr); }
  .ed-preview { position: static; order: -1; }
  .ed-preview iframe { height: min(62vh, 520px); }
  .ed-bar { position: static; }
  .ed-span2 { grid-column: 1 / -1; }
}

/* ---------- Tabela kroków ---------- */
.ed-rhythm { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px; margin-bottom: 10px; }
.ed-rhythm-field { flex: 1 1 260px; }
.ed-auto { min-height: 40px; }
.ed-pick-hint {
  margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; font-size: 13.5px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); border: 1px solid var(--accent);
}
#pickBtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ed-table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.ed-table { width: 100%; border-collapse: separate; border-spacing: 0 3px; font-size: 14px; }
.ed-table th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--muted); padding: 0 4px 2px; white-space: nowrap;
}
.ed-table td { padding: 3px 3px; vertical-align: middle; background: var(--surface-2); }
.ed-table tr.ed-row td:first-child { border-radius: 8px 0 0 8px; }
.ed-table tr.ed-row td:last-child { border-radius: 0 8px 8px 0; }
.ed-table tr.ed-row { cursor: pointer; }
.ed-table tr.is-current td { background: color-mix(in srgb, var(--accent) 9%, var(--surface-2)); }
.ed-table tr.is-selected td { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); }
.ed-table tr.ed-detail td { padding-top: 0; padding-bottom: 8px; }
.ed-table tr.ed-detail td:first-child { border-radius: 0 0 0 8px; }
.ed-table tr.ed-detail td:last-child { border-radius: 0 0 8px 0; }
.ed-table tr.ed-row.is-selected td:first-child { border-radius: 8px 0 0 0; }
.ed-table tr.ed-row.is-selected td:last-child { border-radius: 0 8px 0 0; }
.ed-table input, .ed-table select {
  min-height: 32px; padding: 3px 5px; font-size: 14px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--line); width: 100%;
}
.ed-table input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--accent); }
.ed-table .w-count { width: 4.2em; }
.ed-table .w-num { width: 4.6em; }
.ed-table .w-foot { width: 3.6em; font-weight: 700; }
.ed-table .w-foot.is-l { color: var(--left); }
.ed-table .w-foot.is-r { color: var(--right); }
.ed-table .c-dir { min-width: 8.5em; }
.ed-table .c-dir { display: table-cell; }
.ed-table .c-dir input { margin-top: 3px; }
.ed-table .c-chk { text-align: center; }
.ed-table .c-no { width: 34px; }
.ed-table .c-tools { white-space: nowrap; text-align: right; }
.ed-mini {
  width: 26px; height: 28px; padding: 0; border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 12px;
}
.ed-mini:hover, .ed-mini:focus-visible { border-color: var(--line); background: var(--surface); color: var(--ink); }
.ed-mini.danger:hover { color: var(--danger); border-color: var(--danger); }
.ed-table tr.ed-row:not(.is-selected):not(:hover) .ed-mini { opacity: .45; }
.ed-seek {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  font-weight: 800; cursor: pointer; font-size: 13px;
}
.ed-table tr.is-selected .ed-seek, .ed-table tr.is-current .ed-seek { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ed-detail-grid { display: grid; grid-template-columns: minmax(180px, 1fr) repeat(3, auto) auto; gap: 6px 10px; align-items: end; }
.ed-detail-grid label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); }
.ed-detail-grid .ed-chk { flex-direction: row; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink); min-height: 32px; }
.ed-detail-grid .ed-desc input { width: 100%; }
.ed-keys { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
@media (max-width: 700px) {
  .ed-detail-grid { grid-template-columns: 1fr 1fr; }
  .ed-detail-grid .ed-desc { grid-column: 1 / -1; }
}
/* węższe kolumny: pola liczbowe bez strzałek, mniejsze odstępy */
.ed-table input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.ed-table input[type="number"]::-webkit-inner-spin-button,
.ed-table input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.ed-table td { padding: 3px 2px; }
.ed-table .w-count { width: 3.4em; }
.ed-table .w-num { width: 3.4em; }
.ed-table .w-foot { width: 3.2em; }
.ed-table .c-dir { min-width: 7em; }
.ed-table select[data-k="rise"] { width: 5.2em; }
.ed-table .c-tools { width: 1%; }

/* ---------- Edytor układów: lista elementów ---------- */
.ed-h2 { margin: 0; font-size: 16px; font-weight: 800; align-self: center; }
.ed-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ed-item {
  display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 8px; align-items: start;
  padding: 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line);
}
.ed-item.is-board { background: color-mix(in srgb, var(--accent) 9%, var(--surface-2)); border-style: dashed; }
.ed-item-no { font-weight: 800; color: var(--muted); padding-top: 22px; text-align: center; }
.ed-item-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ed-item-row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: flex-end; }
.ed-item .ed-grow { flex: 1 1 200px; }
.ed-item .ed-sec { width: 5.5em; }
.ed-item input, .ed-item select, .ed-item textarea { min-height: 34px; font-size: 14px; }
.ed-item .ed-chk { display: flex; align-items: center; gap: 6px; min-height: 34px; font-size: 13px; }
.ed-item .ed-chk input { width: 18px; min-height: 18px; accent-color: var(--accent); }
.ed-beats { font-size: 12px; color: var(--muted); min-height: 34px; display: flex; align-items: center; }
.ed-item-tools { display: flex; gap: 2px; padding-top: 18px; }

.ed-item { cursor: pointer; transition: background-color .2s, border-color .2s; }
.ed-item.is-current { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.ed-item.is-selected { background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }
.ed-item.is-selected .ed-item-no, .ed-item.is-current .ed-item-no { color: var(--accent); }
.ed-item:not(.is-selected):not(:hover) .ed-mini { opacity: .5; }

/* powrót do strony głównej (lewy górny róg edytorów) */
.ed-home { display: flex; align-items: center; gap: 12px; }
.ed-back { min-height: 36px; padding: 0 12px; font-size: 14px; }

/* szybkie przyciski w zaznaczonym kroku: czas 1/2, obrót L / P o 90° */
.ed-table .c-quick { white-space: nowrap; }
.ed-table .c-quick input { vertical-align: middle; }
.ed-table .ed-quick {
  width: auto; min-width: 22px; height: 26px; margin-left: 2px; padding: 0 4px; vertical-align: middle;
  border-color: var(--line); background: var(--surface); color: var(--ink); font-weight: 700; font-size: 11.5px;
}
.ed-table .ed-quick:hover { border-color: var(--accent); }
.ed-table .ed-quick[data-act="turnL"] { color: var(--left); }
.ed-table .ed-quick[data-act="turnR"] { color: var(--right); }
