.editor-root { position: fixed; inset: 0; z-index: 500; background: var(--bg); overflow: hidden; }

.ed-loading { display: flex; align-items: center; justify-content: center; height: 100vh; }
.ed-shell { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }

.ed-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; height: 60px; padding: 0 1rem; border-bottom: 1px solid var(--border); background: var(--bg-2); flex-shrink: 0; }
.ed-bar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.ed-title-wrap { display: flex; flex-direction: column; min-width: 0; }
.ed-kicker { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); font-weight: 700; }
.ed-link { font-size: 0.82rem; display: flex; align-items: center; gap: 0.35rem; color: var(--text-muted); min-width: 0; }
.ed-link svg { width: 14px; height: 14px; flex-shrink: 0; }
.ed-link a { color: var(--accent); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-link.live { color: var(--success); }
.ed-temp { color: var(--text-dim); font-style: italic; }
.ed-bar-right { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.ed-save-state { font-size: 0.8rem; color: var(--text-dim); }
.ed-bar-right .btn.active { background: var(--accent); color: #fff; }

.ed-body { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.ed-side { border-right: 1px solid var(--border); overflow-y: auto; padding: 1.25rem; background: var(--bg-2); }
.ed-group { margin-bottom: 1.75rem; }
.ed-group h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin-bottom: 0.85rem; font-weight: 700; }

.ed-canvas-wrap { display: flex; flex-direction: column; min-height: 0; }
.ed-toolbar-host { flex-shrink: 0; padding: 1rem 1rem 0; display: flex; justify-content: center; }
.ed-canvas, .ed-preview { flex: 1; overflow-y: auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 5rem; }
.ed-canvas { display: flex; flex-direction: column; gap: 1rem; max-width: 940px; width: 100%; margin: 0 auto; }
.ed-canvas > * { flex-shrink: 0; }
.ed-preview { background: var(--bg); }
.ed-preview-inner { max-width: 900px; margin: 0 auto; }

.rt-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.25rem; padding: 0.5rem 0.6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); margin: 0; }
.rt-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 0 0.4rem; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--text-muted); cursor: pointer; font-size: 0.9rem; }
.rt-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.rt-btn svg { width: 16px; height: 16px; }
.rt-ico { font-weight: 800; }
.rt-bar { position: absolute; bottom: 3px; left: 6px; right: 6px; height: 3px; border-radius: 2px; }
.rt-select { height: 30px; min-width: 110px; background-color: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.82rem; padding: 0 1.6rem 0 0.6rem; cursor: pointer; }
.rt-sep { width: 1px; height: 20px; background: var(--border); margin: 0 0.3rem; }
.rt-pop { position: absolute; top: 110%; left: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 6px; background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); }
.rt-swatch { width: 22px; height: 22px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.2); cursor: pointer; }

.rt-field { background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.65rem 0.8rem; outline: none; line-height: 1.6; transition: border-color 0.18s, box-shadow 0.18s; }
.rt-field.focused { border-color: var(--accent); box-shadow: var(--ring); }
.rt-field:empty::before { content: attr(data-placeholder); color: var(--text-dim); }
.rt-field a { color: var(--accent); }
.rt-field ul, .rt-field ol { margin-left: 1.3rem; }

.ed-palette { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; padding: 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px); }
.ed-palette-label { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; margin-right: 0.2rem; }
.ed-palette-btn { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.6rem; background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: all 0.16s; }
.ed-palette-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: translateY(-1px); }
.ed-palette-btn svg { width: 15px; height: 15px; }

.ed-empty { text-align: center; padding: 3.5rem 1rem; color: var(--text-muted); border: 2px dashed var(--border); border-radius: var(--radius); }
.ed-empty svg { width: 40px; height: 40px; color: var(--text-dim); margin-bottom: 0.75rem; }
.ed-empty h3 { color: var(--text); margin-bottom: 0.3rem; }

.ed-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: border-color 0.18s, box-shadow 0.18s; }
.ed-block:hover { border-color: var(--border-strong); }
.ed-block.dragging { opacity: 0.5; }
.ed-block.drop-over { border-color: var(--accent); box-shadow: 0 -3px 0 var(--accent) inset; }
.ed-block.just-added { animation: block-pop 0.5s var(--ease); }
@keyframes block-pop { from { box-shadow: 0 0 0 2px var(--accent); } to { box-shadow: 0 0 0 0 transparent; } }
.ed-block-head { display: flex; align-items: center; gap: 0.55rem; padding: 0.55rem 0.75rem; background: rgba(255,255,255,0.03); border-bottom: 1px solid var(--border); }
.ed-drag { cursor: grab; color: var(--text-dim); display: inline-flex; }
.ed-drag svg { width: 16px; height: 16px; }
.ed-block-ico { width: 16px; height: 16px; color: var(--accent); }
.ed-block-label { font-weight: 600; font-size: 0.9rem; flex: 1; }
.ed-block-actions { display: flex; gap: 0.15rem; }
.ed-block-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.85rem; }

.eb-mini { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--text-muted); cursor: pointer; }
.eb-mini:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.eb-mini.danger:hover { background: rgba(239,68,68,0.15); color: var(--danger); }
.eb-mini svg { width: 15px; height: 15px; }

.eb-field { display: flex; flex-direction: column; }
.eb-inline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.eb-inline { display: flex; align-items: center; gap: 0.6rem; }
.eb-heading-input { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
.eb-divider-note { text-align: center; color: var(--text-dim); font-size: 0.85rem; padding: 0.5rem; border: 1px dashed var(--border); border-radius: 8px; }
.eb-color { width: 46px; height: 34px; padding: 2px; background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }

.eb-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.eb-chip { display: flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.3rem 0.25rem 0.35rem; background: rgba(255,255,255,0.06); border: 1px solid var(--border); border-radius: 8px; font-size: 0.82rem; font-weight: 600; }
.eb-chip img { width: 26px; height: 26px; border-radius: 5px; object-fit: cover; background: rgba(0,0,0,0.3); }
.eb-chip-ph { width: 26px; height: 26px; border-radius: 5px; background: var(--accent-2); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 0.6rem; font-weight: 700; }
.eb-chip-ctrl { display: flex; margin-left: 0.15rem; }
.eb-add-tower { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.4rem 0.7rem; background: transparent; border: 1px dashed var(--border-strong); border-radius: 8px; color: var(--text-muted); font-size: 0.82rem; font-weight: 600; cursor: pointer; }
.eb-add-tower:hover { border-color: var(--accent); color: var(--accent); }
.eb-add-tower svg { width: 14px; height: 14px; }

.eb-steps { display: flex; flex-direction: column; gap: 0.6rem; }
.eb-step-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 0.6rem; align-items: start; }
.eb-step-waves { text-align: center; font-weight: 600; }

.eb-players { display: flex; flex-direction: column; gap: 1rem; }
.eb-player { border: 1px solid var(--border); border-top: 3px solid var(--player-color); border-radius: var(--radius-sm); padding: 1rem; display: flex; flex-direction: column; gap: 0.7rem; background: rgba(255,255,255,0.02); }
.eb-player-head { display: flex; align-items: center; gap: 0.5rem; }
.eb-player-name { flex: 1; font-weight: 600; }
.eb-player-ctrl { display: flex; gap: 0.1rem; }

.eb-table-grid { display: grid; gap: 4px; }
.eb-cell { font-size: 0.85rem; padding: 0.5rem; }
.eb-cell.head { font-weight: 700; background: rgba(255,255,255,0.06); }
.eb-table-ctrl { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; align-items: center; }
.eb-inline-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; color: var(--text-muted); margin-left: auto; }

.eb-image-preview { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: rgba(0,0,0,0.25); display: flex; align-items: center; justify-content: center; min-height: 120px; padding: 0.5rem; }
.eb-image-preview img { border-radius: 6px; }
.eb-image-empty { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; color: var(--text-dim); font-size: 0.85rem; padding: 1.5rem; }
.eb-image-empty svg { width: 32px; height: 32px; }

.ed-thumb-preview { height: 110px; border-radius: var(--radius-sm); background-size: cover; background-position: center; border: 1px solid var(--border); margin-bottom: 0.75rem; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 0.82rem; }
.ed-thumb-preview.empty { background: rgba(255,255,255,0.03); }

.ed-mod-picker { position: relative; }
.ed-mod-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.ed-mod-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.3rem 0.2rem 0.55rem; background: rgba(46,138,246,0.14); border: 1px solid rgba(46,138,246,0.3); border-radius: 999px; font-size: 0.78rem; color: #bcd8ff; }
.ed-mod-chip button { background: none; border: none; color: inherit; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.15rem; }
.ed-mod-panel { margin-top: 0.5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-solid); padding: 0.6rem; display: flex; flex-direction: column; }
.ed-mod-list { margin-top: 0.5rem; max-height: 280px; overflow-y: auto; padding-right: 0.2rem; }
.ed-mod-group { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); font-weight: 700; margin: 0.6rem 0 0.3rem; }
label.ed-mod-opt { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.5rem; border-radius: 8px; font-size: 0.86rem; color: var(--text-muted); cursor: pointer; transition: background 0.14s, color 0.14s; margin-bottom: 0; }
label.ed-mod-opt:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
label.ed-mod-opt input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.ed-mod-box { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border-strong); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background 0.14s, border-color 0.14s; }
.ed-mod-box svg { width: 12px; height: 12px; opacity: 0; color: #fff; transition: opacity 0.14s; }
label.ed-mod-opt input:checked ~ .ed-mod-box { background: var(--accent); border-color: var(--accent); }
label.ed-mod-opt input:checked ~ .ed-mod-box svg { opacity: 1; }
label.ed-mod-opt input:checked ~ span:last-child { color: var(--text); font-weight: 600; }
label.ed-mod-opt input:focus-visible ~ .ed-mod-box { box-shadow: var(--ring); }
.ed-mod-count { font-size: 0.72rem; color: var(--text-dim); }

.blockpick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 0.6rem; }
.blockpick-btn { display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 0.8rem; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-weight: 600; font-size: 0.86rem; text-align: left; cursor: pointer; transition: border-color 0.15s, background 0.15s, transform 0.15s; }
.blockpick-btn:hover { border-color: var(--accent); background: rgba(46, 138, 246, 0.1); transform: translateY(-1px); }
.blockpick-btn svg { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }

.ed-invalid .input, .input.ed-invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.22) !important; }

.ed-add-end { display: flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.9rem; width: 100%; background: transparent; border: 2px dashed var(--border); border-radius: var(--radius); color: var(--text-muted); font-weight: 600; cursor: pointer; transition: all 0.16s; }
.ed-add-end:hover { border-color: var(--accent); color: var(--accent); }
.ed-add-end svg { width: 18px; height: 18px; }

.tower-picker { max-width: 640px; }
.tower-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 0.6rem; max-height: 46vh; overflow-y: auto; padding: 0.25rem; }
.tower-tile { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; padding: 0.6rem 0.4rem; background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-family: inherit; cursor: pointer; transition: border-color 0.15s, background 0.15s, transform 0.15s; }
.tower-tile:hover { border-color: var(--accent); background: rgba(46,138,246,0.1); transform: translateY(-2px); }
.tower-tile.flash { border-color: var(--success); background: rgba(34,197,94,0.15); }
.tower-tile img { width: 46px; height: 46px; object-fit: contain; }
.tower-tile span { font-size: 0.72rem; text-align: center; line-height: 1.1; color: var(--text); }
.picker-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; }

@media (max-width: 820px) {
    .ed-body { grid-template-columns: 1fr; }
    .ed-side { border-right: none; border-bottom: 1px solid var(--border); max-height: 42vh; }
    .ed-bar-right .btn span { display: none; }
    .eb-step-row { grid-template-columns: 84px 1fr auto; }
}