/* ═══════════════════════════════════════════════════════════════════
   EDIT MODE CSS
   All rules gated under body.em-active or .em-* prefix.
   Zero visual impact when edit mode is off.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Grid overlay ───────────────────────────────────────────────── */
body.em-active::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 109, 0, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 109, 0, 0.04) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ── Suppress conflicting normal-mode interactions ──────────────── */
body.em-active #spotlight               { opacity: 0 !important; }
body.em-active #card-backdrop           { display: none !important; }
body.em-active .card-glow               { animation: none !important; box-shadow: none !important; }
body.em-active .card-item:hover         { transform: none !important; }
body.em-active .glitch:hover            { animation: none !important; }
body.em-active #chaos-btn               { pointer-events: none; opacity: 0.35; }
body.em-active .profile-glitch-wrap     { pointer-events: none; }

/* ── Override custom cursors in edit mode ───────────────────────── */
body.em-active *                                    { cursor: default !important; }
body.em-active [data-em-id]:not([data-em-locked])  { cursor: grab !important; }
body.em-active [data-em-dragging]                   { cursor: grabbing !important; }
body.em-active .em-handle[data-em-handle="nw"],
body.em-active .em-handle[data-em-handle="se"]      { cursor: nw-resize !important; }
body.em-active .em-handle[data-em-handle="ne"],
body.em-active .em-handle[data-em-handle="sw"]      { cursor: ne-resize !important; }
body.em-active .em-handle[data-em-handle="n"],
body.em-active .em-handle[data-em-handle="s"]       { cursor: n-resize !important; }
body.em-active .em-handle[data-em-handle="e"],
body.em-active .em-handle[data-em-handle="w"]       { cursor: e-resize !important; }
body.em-active #em-inspector *                      { cursor: default !important; }
body.em-active #em-inspector input,
body.em-active #em-inspector textarea,
body.em-active #em-inspector select                 { cursor: text !important; }
body.em-active #em-inspector button                 { cursor: pointer !important; }
body.em-active #em-toggle-btn                       { cursor: pointer !important; }

/* ── Editable element hover hint ────────────────────────────────── */
body.em-active [data-em-id]:not([data-em-locked]):hover {
  outline: 1px dashed rgba(255, 109, 0, 0.4) !important;
  outline-offset: 3px;
}
body.em-active [data-em-id][data-em-locked] {
  opacity: 0.6;
}

/* ── Selection overlay ──────────────────────────────────────────── */
#em-selection-overlay {
  position: fixed;
  pointer-events: none;
  border: 2px solid var(--orange, #FF6D00);
  box-shadow: 0 0 0 1px rgba(255, 109, 0, 0.15), 0 0 16px rgba(255, 109, 0, 0.12);
  z-index: 10100;
  display: none;
  border-radius: 2px;
}

/* ── Resize handles ─────────────────────────────────────────────── */
.em-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--orange, #FF6D00);
  border: 1.5px solid var(--bg, #0D0902);
  border-radius: 2px;
  pointer-events: all;
  z-index: 10101;
  box-shadow: 0 0 4px rgba(255, 109, 0, 0.5);
}
.em-handle[data-em-handle="nw"] { top: -5px; left: -5px; }
.em-handle[data-em-handle="n"]  { top: -5px; left: calc(50% - 4px); }
.em-handle[data-em-handle="ne"] { top: -5px; right: -5px; }
.em-handle[data-em-handle="e"]  { top: calc(50% - 4px); right: -5px; }
.em-handle[data-em-handle="se"] { bottom: -5px; right: -5px; }
.em-handle[data-em-handle="s"]  { bottom: -5px; left: calc(50% - 4px); }
.em-handle[data-em-handle="sw"] { bottom: -5px; left: -5px; }
.em-handle[data-em-handle="w"]  { top: calc(50% - 4px); left: -5px; }

/* ── Alignment guides ───────────────────────────────────────────── */
.em-guide {
  position: fixed;
  background: rgba(255, 109, 0, 0.5);
  z-index: 10099;
  pointer-events: none;
}
.em-guide-h { height: 1px; left: 0; right: 0; }
.em-guide-v { width: 1px;  top: 0; bottom: 0; }

/* ── Hide terminal button in edit mode ──────────────────────────── */
body.em-active #terminal-toggle-btn { display: none !important; }

/* ── Toggle button ──────────────────────────────────────────────── */
#em-toggle-btn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 10400;
  background: transparent;
  border: 1px solid rgba(255, 109, 0, 0.35);
  color: var(--muted, #5C4A38);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
  letter-spacing: 0.05em;
}
#em-toggle-btn:hover {
  color: var(--orange, #FF6D00);
  border-color: var(--orange, #FF6D00);
  box-shadow: 0 0 10px rgba(255, 109, 0, 0.2);
}
body.em-active #em-toggle-btn {
  color: var(--orange, #FF6D00);
  border-color: var(--orange, #FF6D00);
  box-shadow: 0 0 12px rgba(255, 109, 0, 0.25);
}

/* ── Floating reset button (visible only in edit mode) ──────────── */
#em-reset-float-btn {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 108px;
  z-index: 10400;
  background: transparent;
  border: 1px solid rgba(255, 68, 68, 0.35);
  color: var(--muted, #5C4A38);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
  letter-spacing: 0.05em;
}
#em-reset-float-btn:hover {
  color: #ff4444;
  border-color: rgba(255, 68, 68, 0.7);
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.15);
}

/* ── Inspector panel ─────────────────────────────────────────────── */
#em-inspector {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  height: 100vh;
  background: rgba(13, 9, 2, 0.97);
  border-left: 1px solid rgba(255, 109, 0, 0.2);
  z-index: 10200;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  color: var(--text, #9B9088);
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  user-select: none;
}
#em-inspector.em-open { transform: translateX(0); }

/* Inspector scrollbar */
#em-inspector::-webkit-scrollbar { width: 4px; }
#em-inspector::-webkit-scrollbar-track { background: transparent; }
#em-inspector::-webkit-scrollbar-thumb { background: rgba(255,109,0,0.3); border-radius: 2px; }

/* Inspector header */
.em-panel-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255, 109, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.em-panel-title {
  color: var(--orange, #FF6D00);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 500;
}

/* Section headers */
.em-section {
  border-bottom: 1px solid rgba(45, 30, 10, 0.8);
}
.em-section-header {
  padding: 10px 16px;
  color: var(--heading, #E8E0D8);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.em-section-header:hover { color: var(--orange, #FF6D00); }
.em-section-arrow { font-size: 0.55rem; opacity: 0.6; transition: transform 0.15s; }
.em-section.collapsed .em-section-arrow { transform: rotate(-90deg); }
.em-section-body { padding: 8px 16px 12px; }
.em-section.collapsed .em-section-body { display: none; }

/* Inspector fields */
.em-field {
  margin-bottom: 10px;
}
.em-field label {
  display: block;
  color: var(--muted, #5C4A38);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.em-field input[type="text"],
.em-field input[type="number"],
.em-field textarea,
.em-field select {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(45, 30, 10, 1);
  color: var(--heading, #E8E0D8);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  padding: 5px 8px;
  border-radius: 3px;
  outline: none;
  transition: border-color 0.15s;
  user-select: text;
}
.em-field input:focus,
.em-field textarea:focus,
.em-field select:focus {
  border-color: rgba(255, 109, 0, 0.5);
}
.em-field textarea { resize: vertical; min-height: 52px; }

/* 2-column grid for small inputs */
.em-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.em-field-row .em-field { margin-bottom: 0; }

/* Color picker */
.em-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.em-color-row input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(45,30,10,1);
  border-radius: 3px;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.em-color-row input[type="text"] {
  flex: 1;
}

/* Toggle switch */
.em-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.em-toggle-row label { margin-bottom: 0; }
.em-switch {
  position: relative;
  width: 32px;
  height: 16px;
  flex-shrink: 0;
}
.em-switch input { opacity: 0; width: 0; height: 0; }
.em-switch-slider {
  position: absolute;
  inset: 0;
  background: rgba(45,30,10,1);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s;
}
.em-switch-slider::before {
  content: '';
  position: absolute;
  height: 10px;
  width: 10px;
  left: 3px;
  bottom: 3px;
  background: var(--muted, #5C4A38);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.em-switch input:checked + .em-switch-slider { background: rgba(255, 109, 0, 0.3); }
.em-switch input:checked + .em-switch-slider::before {
  transform: translateX(16px);
  background: var(--orange, #FF6D00);
}

/* Buttons */
.em-btn {
  background: transparent;
  border: 1px solid rgba(45,30,10,1);
  color: var(--muted, #5C4A38);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  padding: 5px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.04em;
}
.em-btn:hover {
  color: var(--heading, #E8E0D8);
  border-color: rgba(255,109,0,0.4);
}
.em-btn-primary {
  border-color: rgba(255,109,0,0.4);
  color: var(--orange, #FF6D00);
}
.em-btn-primary:hover {
  border-color: var(--orange, #FF6D00);
  box-shadow: 0 0 8px rgba(255,109,0,0.15);
}
.em-btn-danger:hover {
  color: #ff4444;
  border-color: rgba(255,68,68,0.4);
}
.em-btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Element info badge */
.em-info-badge {
  display: inline-block;
  background: rgba(255,109,0,0.1);
  color: var(--orange, #FF6D00);
  border: 1px solid rgba(255,109,0,0.25);
  border-radius: 2px;
  padding: 1px 6px;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.em-no-selection {
  padding: 24px 16px;
  color: var(--muted, #5C4A38);
  font-size: 0.65rem;
  text-align: center;
  line-height: 1.8;
}
.em-muted { color: var(--muted, #5C4A38); font-size: 0.6rem; }

/* Theme swatches */
.em-theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.em-theme-swatch {
  display: flex;
  align-items: center;
  gap: 6px;
}
.em-theme-swatch label {
  flex: 1;
  margin-bottom: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.em-theme-swatch input[type="color"] {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(45,30,10,1);
  border-radius: 3px;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

/* Add element dropdown */
.em-add-select {
  width: 100%;
  margin-bottom: 8px;
}

/* Inline editing state */
[data-em-inline-editing] {
  outline: 2px solid var(--orange, #FF6D00) !important;
  outline-offset: 2px !important;
  cursor: text !important;
  caret-color: var(--orange, #FF6D00);
}

/* Created elements (user-added) */
.em-created-element {
  position: absolute;
  min-width: 80px;
  min-height: 24px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--heading, #E8E0D8);
  background: transparent;
  border: none;
  outline: none;
}

/* Divider */
.em-divider {
  height: 1px;
  background: rgba(45,30,10,0.8);
  margin: 4px 0;
}

/* ── Popup dialog ────────────────────────────────────────────────── */
.em-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 10500;
  background: rgba(13, 9, 2, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.em-popup-overlay.em-popup-visible {
  opacity: 1;
  pointer-events: all;
}
.em-popup {
  background: var(--card, #1A1208);
  border: 1px solid rgba(255, 109, 0, 0.3);
  border-radius: 6px;
  padding: 28px 28px 20px;
  max-width: 320px;
  width: calc(100% - 48px);
  box-shadow: 0 0 32px rgba(255, 109, 0, 0.12), 0 8px 32px rgba(0,0,0,0.6);
  font-family: 'JetBrains Mono', monospace;
}
.em-popup-message {
  color: var(--heading, #E8E0D8);
  font-size: 0.8rem;
  line-height: 1.6;
  margin: 0 0 20px;
}
.em-popup-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.em-popup-btn {
  background: transparent;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  padding: 7px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
  letter-spacing: 0.04em;
}
.em-popup-btn-ok {
  border: 1px solid rgba(255, 109, 0, 0.4);
  color: var(--muted, #5C4A38);
}
.em-popup-btn-ok:hover {
  color: var(--orange, #FF6D00);
  border-color: var(--orange, #FF6D00);
  box-shadow: 0 0 10px rgba(255, 109, 0, 0.2);
}
.em-popup-btn-yes {
  border: 1px solid rgba(255, 68, 68, 0.4);
  color: var(--muted, #5C4A38);
}
.em-popup-btn-yes:hover {
  color: #ff4444;
  border-color: rgba(255, 68, 68, 0.7);
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.15);
}
.em-popup-btn-no {
  border: 1px solid rgba(255, 109, 0, 0.25);
  color: var(--muted, #5C4A38);
}
.em-popup-btn-no:hover {
  color: var(--orange, #FF6D00);
  border-color: rgba(255, 109, 0, 0.5);
}
