/* =====================================================================
   Editor — a dense, dark-first creative workspace
   ===================================================================== */
html, body { height: 100%; overflow: hidden; }
body.editor-body { background: var(--bg); }

.editor { display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: 64px 288px 1fr 280px; grid-template-rows: 54px 1fr;
  grid-template-areas: "top top top top" "rail panel stage right"; }
.editor.panel-closed { grid-template-columns: 64px 0 1fr 280px; }
.editor.panel-closed .ed-panel { display: none; }

/* top bar */
.ed-top { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 8px; background: var(--bg-elev); border-bottom: 1px solid var(--border); min-width: 0; }
.ed-top .logo-mark { width: 30px; height: 30px; }
.ed-home { display: grid; place-items: center; width: 44px; height: 40px; border-radius: var(--r-md); }
.ed-home:hover { background: var(--surface-2); }
.ed-name { height: 34px; min-width: 120px; width: 260px; max-width: 32vw; padding: 0 10px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; font-weight: 600; font-size: .95rem; color: var(--text); }
.ed-name:hover { border-color: var(--border); } .ed-name:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: var(--surface); }
.ed-status { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--text-3); white-space: nowrap; }
.ed-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.ed-status[data-state="dirty"] .dot { background: var(--warning); }
.ed-status[data-state="saving"] .dot { background: var(--info); animation: pulse 1s infinite; }
.ed-status[data-state="error"] .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.ed-top .sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.ed-top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.ed-top .btn-icon { flex: none; } /* undo/redo keep a full tap target on narrow phones */
/* Small phones: Download/Save become icon buttons; the label stays for screen readers. */
@media (max-width: 420px) {
  .ed-top [data-cmd="download"], .ed-top [data-cmd="save"] { width: 40px; padding: 0; flex: none; }
  .ed-top [data-cmd="download"] > span, .ed-top [data-cmd="save"] > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
.ed-zoom-label { min-width: 54px; font-variant-numeric: tabular-nums; font-size: .82rem; }

/* tool rail */
.ed-rail { grid-area: rail; display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; background: var(--bg-elev); border-right: 1px solid var(--border); overflow-y: auto; }
.rail-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 58px; border-radius: var(--r-md);
  border: 0; background: transparent; color: var(--text-2); font-size: .66rem; font-weight: 600; cursor: pointer; }
.rail-btn:hover { background: var(--surface-2); color: var(--text); }
.rail-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* left panel */
.ed-panel { grid-area: panel; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; min-width: 0; }
.panel-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; background: var(--surface); }
.panel-head h2 { font-size: 1rem; margin: 0; font-family: var(--font-ui); letter-spacing: 0; }
.panel-body { padding: 0 16px 20px; display: grid; gap: 14px; align-content: start; }
.panel-note { font-size: .82rem; color: var(--text-3); padding: 10px 12px; background: var(--surface-2); border-radius: var(--r-md); }
.group-label { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-top: 6px; }

.thumb-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.thumb-btn { position: relative; aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); padding: 0; cursor: pointer; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; }
.thumb-btn:hover { border-color: var(--accent); }
.thumb-btn.tpl { aspect-ratio: 1; display: grid; place-items: center; padding: 8px; }
.thumb-btn.tpl img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.thumb-btn .lock { position: absolute; top: 6px; right: 6px; }

.text-presets { display: grid; gap: 8px; }
.text-preset { text-align: left; padding: 14px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; color: var(--text); }
.text-preset:hover { border-color: var(--accent); }

.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shape-btn { aspect-ratio: 1; display: grid; place-items: center; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; }
.shape-btn:hover { border-color: var(--accent); color: var(--accent); }
.shape-btn svg { width: 34px; height: 34px; }

.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.filter-btn { display: flex; flex-direction: column; gap: 6px; padding: 0 0 6px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: .72rem; font-weight: 600; color: var(--text-2); overflow: hidden; position: relative; }
.filter-btn .sw { aspect-ratio: 1; background: linear-gradient(135deg, #ffb36b, #ff5a5f 55%, #6b3fa0); }
.filter-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); box-shadow: var(--ring); }
.filter-btn .lock { position: absolute; top: 4px; right: 4px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

.color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.color-chip { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--border-strong); cursor: pointer; padding: 0; }
.color-chip[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.color-chip.transparent { background: conic-gradient(#ccc 25%, #fff 0 50%, #ccc 0 75%, #fff 0) 0 0 / 10px 10px; }

.slider-row { display: grid; gap: 4px; }
.slider-row .row-between { font-size: .82rem; color: var(--text-2); }
.slider-row output { font-variant-numeric: tabular-nums; font-size: .78rem; color: var(--text-3); }

/* stage */
.ed-stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden;
  background: color-mix(in srgb, var(--bg) 70%, #000 6%); }
:root[data-theme="dark"] .ed-stage { background: #0a0a0d; }
.ed-canvas-host { position: absolute; inset: 0; }
.ed-canvas-host.panning, .ed-canvas-host.panning .upper-canvas { cursor: grab !important; }
.ed-canvas-host.panning.dragging .upper-canvas { cursor: grabbing !important; }
.ed-floating { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 4px;
  border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); z-index: 5; }
.ed-floating .btn { height: 32px; }
.ed-context { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: center; padding: 4px;
  border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); z-index: 6; }
.ed-drop-hint { position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: var(--r-xl); display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent-soft) 70%, transparent); color: var(--accent); font-weight: 700; z-index: 10; pointer-events: none; }
.ed-loading { position: absolute; inset: 0; display: grid; place-items: center; z-index: 20; background: var(--bg); }

/* right sidebar */
.ed-right { grid-area: right; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--border); }
.ed-right .tabs { margin: 10px 12px 0; width: auto; }
.ed-right .tab { flex: 1; }
.ed-right-body { flex: 1; overflow-y: auto; padding: 12px; display: grid; gap: 14px; align-content: start; }

.prop-section { display: grid; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.prop-section:last-child { border-bottom: 0; }
.prop-section h3 { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 0; font-family: var(--font-ui); }
.prop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prop { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); }
.prop:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.prop span { font-size: .72rem; color: var(--text-3); font-weight: 600; width: 14px; }
.prop input { width: 100%; border: 0; background: transparent; font-size: .84rem; font-variant-numeric: tabular-nums; outline: none; min-width: 0; }
.btn-row { display: flex; gap: 4px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 0; }
.seg { display: flex; gap: 2px; padding: 2px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--border); }
.seg .btn { flex: 1; height: 28px; border: 0; }
.seg .btn[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow-sm); color: var(--accent); }
.color-field { display: flex; align-items: center; gap: 8px; }
.color-field .input { height: 32px; font-family: var(--font-mono); font-size: .8rem; }

.layer-list { display: grid; gap: 2px; }
.layer { display: grid; grid-template-columns: 18px 26px 1fr auto; align-items: center; gap: 6px; height: 40px; padding: 0 6px; border-radius: var(--r-sm);
  cursor: pointer; border: 1px solid transparent; font-size: .85rem; }
.layer:hover { background: var(--surface-2); }
.layer[aria-selected="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.layer.hidden-layer .layer-name { opacity: .45; }
.layer.drag-over { box-shadow: inset 0 2px 0 var(--accent); }
.layer .grip { color: var(--text-3); cursor: grab; }
.layer-thumb { width: 26px; height: 26px; border-radius: 5px; background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); overflow: hidden; }
.layer-thumb img { width: 100%; height: 100%; object-fit: cover; }
.layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-name input { width: 100%; height: 26px; border: 1px solid var(--accent); border-radius: 4px; background: var(--surface); padding: 0 6px; font-size: .85rem; }
.layer-actions { display: flex; gap: 0; opacity: .0; }
.layer:hover .layer-actions, .layer[aria-selected="true"] .layer-actions, .layer-actions .on { opacity: 1; }
.layer-actions .btn { width: 26px; height: 26px; }
.layer-actions .btn.on { color: var(--accent); }

.kbd-list { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: .88rem; }

/* export dialog */
.export-formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.export-format { position: relative; padding: 12px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; text-align: left; }
.export-format[aria-pressed="true"] { border-color: var(--accent); box-shadow: var(--ring); }
.export-format[disabled] { opacity: .55; cursor: not-allowed; }
.export-format strong { display: block; } .export-format span { font-size: .75rem; color: var(--text-3); }
.scale-row { display: flex; gap: 6px; flex-wrap: wrap; }
.scale-row .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* tablet & mobile */
@media (max-width: 1180px) {
  .editor { grid-template-columns: 64px 260px 1fr 250px; }
}
@media (max-width: 900px) {
  .editor, .editor.panel-closed { grid-template-columns: 1fr; grid-template-rows: 52px 1fr auto 64px;
    grid-template-areas: "top" "stage" "panel" "rail"; }
  .ed-rail { flex-direction: row; overflow-x: auto; border-right: 0; border-top: 1px solid var(--border); padding: 4px; }
  .rail-btn { min-width: 64px; height: 54px; }
  .ed-panel { max-height: 42vh; border-right: 0; border-top: 1px solid var(--border); }
  .ed-right { position: fixed; top: 52px; right: 0; bottom: 64px; width: min(320px, 90vw); z-index: 40; transform: translateX(100%); transition: transform var(--t-med) var(--ease); box-shadow: var(--shadow-lg); }
  .ed-right.open { transform: none; }
  .ed-name { width: 110px; min-width: 0; }
  .ed-status [data-status-text], .ed-top [data-action] > span { display: none; }
  .ed-top .sep, [data-avatar] { display: none; }
  .ed-top { gap: 4px; }
  .hide-md { display: none !important; }
}
@media (min-width: 901px) { .show-md { display: none !important; } }
